コード例 #1
0
    def process(self, incoming_demand):
        rospy.loginfo('Incoming ask %s...', str(incoming_demand))
        if (incoming_demand.model == rospy.get_param('~model')
                and incoming_demand.token == rospy.get_param('~token')
                and incoming_demand.cost == 0):

            rospy.loginfo('Starting process...')

            with NamedTemporaryFile(delete=False) as tmpfile:
                recorder = rosbag.Bag(tmpfile.name, 'w')

                output = 'St.Petersburg: {{"DUST": {}, "CO": {}, "LPG": {}, "METHANE": {}, "SMOKE": {}, "HYDROGEN": {}}}'.format(
                    *self.measurements)
                recorder.write('/worker/data', String(data=output))
                recorder.close()

                # recover account of sender
                msg_hash = defunct_hash_message(
                    self.demandhash(incoming_demand))
                sender_account = Account.recoverHash(
                    msg_hash, signature=incoming_demand.signature)

                ipfs_response = self.ipfs.add(tmpfile.name)

                res = Result()
                res.liability = sender_account
                res.result = ipfs_response
                res.success = True

                self.pub.publish(res)

            rospy.loginfo('Process complete.')
コード例 #2
0
def dict2res(m):
    msg = Result()

    msg.liability.address = m['liability']
    msg.result.multihash = m['result']
    msg.success = m['success']
    if m['signature']:
        msg.signature = unhexlify(m['signature'].encode('utf-8'))
    return msg
コード例 #3
0
def sign_result(res):
    pub = rospy.Publisher("/liability/infochan/eth/signing/result",
                          Result,
                          queue_size=128)

    r = Result()
    r.result = res.result
    r.liability = res.liability
    r.success = res.success

    rospy.sleep(2)
    rospy.loginfo(r)

    pub.publish(r)
コード例 #4
0
    def finish(self, success):
        self.__recorder.stop()

        ipfs_response = self.ipfs_client.add(self.__liability_result_file)
        try:
            self.liability.result = ipfs_response['Hash']
        except TypeError:
            rospy.logwarn('IPFS add proceeding error: %s',
                          ipfs_response[1]['Message'])
            self.liability.result = ipfs_response[0]['Hash']

        result_msg = Result()
        result_msg.liability = self.liability.address
        result_msg.result = self.liability.result
        result_msg.success = success
        return result_msg
コード例 #5
0
    def finish(self, success):
        self.__recorder.stop()
        self.__player.stop()

        ipfs_add_file_request = IpfsUploadFileRequest()
        ipfs_add_file_request.file.filepath = self.__liability_result_file
        ipfs_add_file_response = ipfs_fileutils.ipfs_upload_file(
            self.ipfs_client, ipfs_add_file_request)

        self.liability.result = ipfs_add_file_response.ipfs_address

        result_msg = Result()
        result_msg.liability = self.liability.address
        result_msg.result = self.liability.result
        result_msg.success = success
        return result_msg
コード例 #6
0
        def finish_liability(msg):
            liability_thread = self.liability_execution_threads.pop(msg.address.address)

            liability_msg = liability_thread.getLiabilityMsg()

            result_ipfs_address = liability_thread.finish(msg.success)
            result = Result()
            result.liability = liability_msg.address
            result.result = result_ipfs_address
            result.success = msg.success

            self.persistence_del.publish(liability_msg)

            self.complete.publish(liability_msg)
            self.result_topic.publish(result)
            rospy.loginfo('Liability %s finished with %s', liability_msg.address.address, result.result)
            return FinishLiabilityResponse()
コード例 #7
0
ファイル: testMessages.py プロジェクト: RinatGumarov/korum
def getValidRes():
    r = Result()
    r.liability = validResDict['liability']
    r.result = validResDict['result']
    r.success = validResDict['success']
    r.signature = unhexlify(validResDict['signature'].encode('utf-8'))
    return r
コード例 #8
0
def dict2res(m):
    msg = Result()

    result_mh = Multihash()
    result_mh.multihash = m['result']

    msg.liability = m['liability']
    msg.result = result_mh
    msg.success = m['success']
    msg.signature = unhexlify(m['signature'].encode('utf-8'))
    return msg