本文整理汇总了Python中dht.protocol.KademliaProtocol.addToRouter方法的典型用法代码示例。如果您正苦于以下问题:Python KademliaProtocol.addToRouter方法的具体用法?Python KademliaProtocol.addToRouter怎么用?Python KademliaProtocol.addToRouter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dht.protocol.KademliaProtocol
的用法示例。
在下文中一共展示了KademliaProtocol.addToRouter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: KademliaProtocolTest
# 需要导入模块: from dht.protocol import KademliaProtocol [as 别名]
# 或者: from dht.protocol.KademliaProtocol import addToRouter [as 别名]
#.........这里部分代码省略.........
message_id = digest("msgid")
n = Node(digest("S"), self.addr1[0], self.addr1[1])
d = defer.Deferred()
timeout = reactor.callLater(5, self.protocol._timeout, message_id)
self.protocol._outstanding[message_id] = (d, timeout)
self.protocol._acceptResponse(message_id, ["test"], n)
return d.addCallback(handle_response)
def test_unknownRPC(self):
self.assertFalse(self.handler.receive_message(str(random.getrandbits(1400))))
def test_timeout(self):
self._connecting_to_connected()
self.wire_protocol[self.addr1] = self.con
def test_remove_outstanding():
self.assertTrue(len(self.protocol._outstanding) == 0)
def test_deffered(d):
self.assertFalse(d[0])
test_remove_outstanding()
n = Node(digest("S"), self.addr1[0], self.addr1[1])
d = self.protocol.callPing(n)
self.clock.advance(6)
connection.REACTOR.runUntilCurrent()
self.clock.advance(6)
return d.addCallback(test_deffered)
def test_transferKeyValues(self):
self._connecting_to_connected()
self.wire_protocol[self.addr1] = self.con
self.protocol.addToRouter(mknode())
self.protocol.storage[digest("keyword")] = (
digest("key"), self.protocol.sourceNode.getProto().SerializeToString())
self.protocol.transferKeyValues(Node(digest("id"), self.addr1[0], self.addr1[1]))
self.clock.advance(1)
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
x = message.Message()
x.ParseFromString(sent_message)
m = message.Message()
m.sender.MergeFrom(self.protocol.sourceNode.getProto())
m.command = message.Command.Value("STORE")
m.arguments.append(digest("keyword"))
m.arguments.append(digest("key"))
m.arguments.append(self.protocol.sourceNode.getProto().SerializeToString())
self.assertEqual(x.sender, m.sender)
self.assertEqual(x.command, m.command)
self.assertEqual(x.arguments[0], m.arguments[0])
self.assertEqual(x.arguments[1], m.arguments[1])
self.assertEqual(x.arguments[2], m.arguments[2])
def test_refreshIDs(self):
node1 = Node(digest("id1"), "127.0.0.1", 12345, signed_pubkey=digest("key1"))
node2 = Node(digest("id2"), "127.0.0.1", 22222, signed_pubkey=digest("key2"))
node3 = Node(digest("id3"), "127.0.0.1", 77777, signed_pubkey=digest("key3"))
self.protocol.router.addContact(node1)
self.protocol.router.addContact(node2)
self.protocol.router.addContact(node3)
for b in self.protocol.router.buckets:
b.lastUpdated = (time.time() - 5000)
ids = self.protocol.getRefreshIDs()
self.assertTrue(len(ids) == 1)
def _connecting_to_connected(self):
remote_synack_packet = packet.Packet.from_data(
42,
self.con.own_addr,
self.con.dest_addr,
ack=0,
syn=True
)
self.con.receive_packet(remote_synack_packet)
self.clock.advance(0)
connection.REACTOR.runUntilCurrent()
self.next_remote_seqnum = 43
m_calls = self.proto_mock.send_datagram.call_args_list
sent_syn_packet = packet.Packet.from_bytes(m_calls[0][0][0])
seqnum = sent_syn_packet.sequence_number
self.handler_mock.reset_mock()
self.proto_mock.reset_mock()
self.next_seqnum = seqnum + 1
def test_badRPCDelete(self):
n = mknode()
val = self.protocol.rpc_delete(n, 'testkeyword', 'key', 'testsig')
self.assertEqual(val, ["False"])
val = self.protocol.rpc_delete(n, '', '', '')