コード例 #1
0
ファイル: rpcudp.py プロジェクト: mlegore/OpenBazaar-Server
 def func(address, *args):
     msgID = sha1(str(random.getrandbits(255))).digest()
     m = Message()
     m.messageID = msgID
     m.sender.MergeFrom(self.sourceNode.getProto())
     m.command = Command.Value(name.upper())
     m.protoVer = PROTOCOL_VERSION
     for arg in args:
         m.arguments.append(str(arg))
     m.testnet = self.multiplexer.testnet
     data = m.SerializeToString()
     d = defer.Deferred()
     if name != "hole_punch":
         seed = SEED_NODE_TESTNET if self.multiplexer.testnet else SEED_NODE
         hole_punch = reactor.callLater(3, self.hole_punch, seed,
                                        address[0], address[1], "True")
         if address in self.multiplexer:
             hole_punch.cancel()
         self._outstanding[msgID] = [d, address, hole_punch]
         self.log.debug("calling remote function %s on %s (msgid %s)" %
                        (name, address, b64encode(msgID)))
     else:
         self.log.debug("sending hole punch message to %s" % args[0] +
                        ":" + str(args[1]))
     self.multiplexer.send_message(data, address)
     return d
コード例 #2
0
        def func(node, *args):
            msgID = sha1(str(random.getrandbits(255))).digest()

            m = Message()
            m.messageID = msgID
            m.sender.MergeFrom(self.sourceNode.getProto())
            m.command = Command.Value(name.upper())
            m.protoVer = PROTOCOL_VERSION
            for arg in args:
                m.arguments.append(str(arg))
            m.testnet = self.multiplexer.testnet
            data = m.SerializeToString()

            address = (node.ip, node.port)
            relay_addr = None
            if node.nat_type == SYMMETRIC or \
                    (node.nat_type == RESTRICTED and self.sourceNode.nat_type == SYMMETRIC):
                relay_addr = node.relay_node

            d = defer.Deferred()
            if m.command != HOLE_PUNCH:
                timeout = reactor.callLater(self._waitTimeout, self.timeout, node)
                self._outstanding[msgID] = [d, address, timeout]
                self.log.debug("calling remote function %s on %s (msgid %s)" % (name, address, b64encode(msgID)))

            self.multiplexer.send_message(data, address, relay_addr)

            if self.multiplexer[address].state != State.CONNECTED and \
                            node.nat_type == RESTRICTED and \
                            self.sourceNode.nat_type != SYMMETRIC:
                self.hole_punch(Node(digest("null"), node.relay_node[0], node.relay_node[1], nat_type=FULL_CONE),
                                address[0], address[1], "True")
                self.log.debug("sending hole punch message to %s" % address[0] + ":" + str(address[1]))

            return d
コード例 #3
0
 def _sendResponse(self, response, funcname, msgID, sender, connection):
     if self.noisy:
         self.log.debug("Sending response for msg id %s to %s" % (b64encode(msgID), sender))
     m = Message()
     m.messageID = msgID
     m.sender.MergeFrom(self.proto)
     m.command = Command.Value(funcname.upper())
     for arg in response:
         m.arguments.append(str(arg))
     data = m.SerializeToString()
     connection.send_message(data)
コード例 #4
0
ファイル: rpcudp.py プロジェクト: mlegore/OpenBazaar-Server
 def _sendResponse(self, response, funcname, msgID, sender, connection):
     self.log.debug("sending response for msg id %s to %s" %
                    (b64encode(msgID), sender))
     m = Message()
     m.messageID = msgID
     m.sender.MergeFrom(self.sourceNode.getProto())
     m.protoVer = PROTOCOL_VERSION
     m.testnet = self.multiplexer.testnet
     if response is None:
         m.command = NOT_FOUND
     else:
         m.command = Command.Value(funcname.upper())
         for arg in response:
             m.arguments.append(str(arg))
     data = m.SerializeToString()
     connection.send_message(data)
コード例 #5
0
 def func(address, *args):
     msgID = sha1(str(random.getrandbits(255))).digest()
     m = Message()
     m.messageID = msgID
     m.sender.MergeFrom(self.proto)
     m.command = Command.Value(name.upper())
     for arg in args:
         m.arguments.append(str(arg))
     data = m.SerializeToString()
     if self.noisy:
         self.log.debug("calling remote function %s on %s (msgid %s)" % (name, address, b64encode(msgID)))
     self.multiplexer.send_message(data, address)
     if name is not "hole_punch":
         d = defer.Deferred()
         timeout = reactor.callLater(self._waitTimeout, self._timeout, msgID, address)
         self._outstanding[msgID] = [d, timeout]
         return d