本文整理汇总了Python中dht.protocol.KademliaProtocol.callFindNode方法的典型用法代码示例。如果您正苦于以下问题:Python KademliaProtocol.callFindNode方法的具体用法?Python KademliaProtocol.callFindNode怎么用?Python KademliaProtocol.callFindNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dht.protocol.KademliaProtocol
的用法示例。
在下文中一共展示了KademliaProtocol.callFindNode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: KademliaProtocolTest
# 需要导入模块: from dht.protocol import KademliaProtocol [as 别名]
# 或者: from dht.protocol.KademliaProtocol import callFindNode [as 别名]
#.........这里部分代码省略.........
m = message.Message()
m.ParseFromString(sent_message)
self.assertTrue(len(m.messageID) == 20)
self.assertEqual(self.protocol.sourceNode.getProto().guid, m.sender.guid)
self.assertEqual(self.protocol.sourceNode.getProto().signedPublicKey, m.sender.signedPublicKey)
self.assertTrue(m.command == message.STORE)
self.assertEqual(self.proto_mock.send_datagram.call_args_list[0][0][1], self.addr1)
self.assertEqual(m.arguments[0], digest("Keyword"))
self.assertEqual(m.arguments[1], digest("Key"))
self.assertEqual(m.arguments[2], self.protocol.sourceNode.getProto().SerializeToString())
def test_callFindValue(self):
self._connecting_to_connected()
n = Node(digest("S"), self.addr1[0], self.addr1[1])
self.wire_protocol[self.addr1] = self.con
keyword = Node(digest("Keyword"))
self.protocol.callFindValue(n, keyword)
self.clock.advance(100 * constants.PACKET_TIMEOUT)
connection.REACTOR.runUntilCurrent()
sent_packet = packet.Packet.from_bytes(self.proto_mock.send_datagram.call_args_list[0][0][0])
sent_message = sent_packet.payload
m = message.Message()
m.ParseFromString(sent_message)
self.assertTrue(len(m.messageID) == 20)
self.assertEqual(self.protocol.sourceNode.getProto().guid, m.sender.guid)
self.assertEqual(self.protocol.sourceNode.getProto().signedPublicKey, m.sender.signedPublicKey)
self.assertTrue(m.command == message.FIND_VALUE)
self.assertEqual(self.proto_mock.send_datagram.call_args_list[0][0][1], self.addr1)
self.assertEqual(m.arguments[0], keyword.id)
def test_callFindNode(self):
self._connecting_to_connected()
n = Node(digest("S"), self.addr1[0], self.addr1[1])
self.wire_protocol[self.addr1] = self.con
keyword = Node(digest("nodetofind"))
self.protocol.callFindNode(n, keyword)
self.clock.advance(100 * constants.PACKET_TIMEOUT)
connection.REACTOR.runUntilCurrent()
sent_packet = packet.Packet.from_bytes(self.proto_mock.send_datagram.call_args_list[0][0][0])
sent_message = sent_packet.payload
m = message.Message()
m.ParseFromString(sent_message)
self.assertTrue(len(m.messageID) == 20)
self.assertEqual(self.protocol.sourceNode.getProto().guid, m.sender.guid)
self.assertEqual(self.protocol.sourceNode.getProto().signedPublicKey, m.sender.signedPublicKey)
self.assertTrue(m.command == message.FIND_NODE)
self.assertEqual(self.proto_mock.send_datagram.call_args_list[0][0][1], self.addr1)
self.assertEqual(m.arguments[0], keyword.id)
def test_callDelete(self):
self._connecting_to_connected()
n = Node(digest("S"), self.addr1[0], self.addr1[1])
self.wire_protocol[self.addr1] = self.con
self.protocol.callDelete(n, digest("Keyword"), digest("Key"), digest("Signature"))
self.clock.advance(100 * constants.PACKET_TIMEOUT)
connection.REACTOR.runUntilCurrent()
sent_packet = packet.Packet.from_bytes(self.proto_mock.send_datagram.call_args_list[0][0][0])
sent_message = sent_packet.payload
示例2: KademliaProtocolTest
# 需要导入模块: from dht.protocol import KademliaProtocol [as 别名]
# 或者: from dht.protocol.KademliaProtocol import callFindNode [as 别名]
#.........这里部分代码省略.........
m = message.Message()
m.ParseFromString(sent_message)
self.assertTrue(len(m.messageID) == 20)
self.assertEqual(self.protocol.sourceNode.getProto().guid, m.sender.guid)
self.assertEqual(self.protocol.sourceNode.getProto().signedPublicKey, m.sender.signedPublicKey)
self.assertTrue(m.command == message.STORE)
self.assertEqual(self.proto_mock.send_datagram.call_args_list[0][0][1], self.addr1)
self.assertEqual(m.arguments[0], digest("Keyword"))
self.assertEqual(m.arguments[1], digest("Key"))
self.assertEqual(m.arguments[2], self.protocol.sourceNode.getProto().SerializeToString())
def test_callFindValue(self):
self._connecting_to_connected()
n = Node(digest("S"), self.addr1[0], self.addr1[1])
self.protocol[self.addr1] = self.con
keyword = Node(digest("Keyword"))
self.protocol.callFindValue(n, keyword)
self.clock.advance(100 * constants.PACKET_TIMEOUT)
connection.REACTOR.runUntilCurrent()
sent_packet = packet.Packet.from_bytes(self.proto_mock.send_datagram.call_args_list[0][0][0])
sent_message = sent_packet.payload
m = message.Message()
m.ParseFromString(sent_message)
self.assertTrue(len(m.messageID) == 20)
self.assertEqual(self.protocol.sourceNode.getProto().guid, m.sender.guid)
self.assertEqual(self.protocol.sourceNode.getProto().signedPublicKey, m.sender.signedPublicKey)
self.assertTrue(m.command == message.FIND_VALUE)
self.assertEqual(self.proto_mock.send_datagram.call_args_list[0][0][1], self.addr1)
self.assertEqual(m.arguments[0], keyword.id)
def test_callFindNode(self):
self._connecting_to_connected()
n = Node(digest("S"), self.addr1[0], self.addr1[1])
self.protocol[self.addr1] = self.con
keyword = Node(digest("nodetofind"))
self.protocol.callFindNode(n, keyword)
self.clock.advance(100 * constants.PACKET_TIMEOUT)
connection.REACTOR.runUntilCurrent()
sent_packet = packet.Packet.from_bytes(self.proto_mock.send_datagram.call_args_list[0][0][0])
sent_message = sent_packet.payload
m = message.Message()
m.ParseFromString(sent_message)
self.assertTrue(len(m.messageID) == 20)
self.assertEqual(self.protocol.sourceNode.getProto().guid, m.sender.guid)
self.assertEqual(self.protocol.sourceNode.getProto().signedPublicKey, m.sender.signedPublicKey)
self.assertTrue(m.command == message.FIND_NODE)
self.assertEqual(self.proto_mock.send_datagram.call_args_list[0][0][1], self.addr1)
self.assertEqual(m.arguments[0], keyword.id)
def test_callDelete(self):
self._connecting_to_connected()
n = Node(digest("S"), self.addr1[0], self.addr1[1])
self.protocol[self.addr1] = self.con
self.protocol.callDelete(n, digest("Keyword"), digest("Key"), digest("Signature"))
self.clock.advance(100 * constants.PACKET_TIMEOUT)
connection.REACTOR.runUntilCurrent()
sent_packet = packet.Packet.from_bytes(self.proto_mock.send_datagram.call_args_list[0][0][0])
sent_message = sent_packet.payload