fix updating/setting contact triple
This commit is contained in:
parent
154702e6dd
commit
e260de59f1
1 changed files with 10 additions and 7 deletions
|
@ -413,11 +413,12 @@ class KademliaProtocol(DatagramProtocol):
|
||||||
sender_contact, ResponseDatagram(RESPONSE_TYPE, message.rpc_id, self.node_id, result),
|
sender_contact, ResponseDatagram(RESPONSE_TYPE, message.rpc_id, self.node_id, result),
|
||||||
)
|
)
|
||||||
|
|
||||||
async def handle_request_datagram(self, address, request_datagram: RequestDatagram):
|
async def handle_request_datagram(self, address: typing.Tuple[str, int], request_datagram: RequestDatagram):
|
||||||
# This is an RPC method request
|
# This is an RPC method request
|
||||||
self.peer_manager.report_last_requested(address[0], address[1])
|
self.peer_manager.report_last_requested(address[0], address[1])
|
||||||
self.peer_manager.update_contact_triple(request_datagram.node_id, address[0], address[1])
|
try:
|
||||||
# only add a requesting contact to the routing table if it has replied to one of our requests
|
peer = self.routing_table.get_peer(request_datagram.node_id)
|
||||||
|
except IndexError:
|
||||||
peer = self.peer_manager.get_kademlia_peer(request_datagram.node_id, address[0], address[1])
|
peer = self.peer_manager.get_kademlia_peer(request_datagram.node_id, address[0], address[1])
|
||||||
try:
|
try:
|
||||||
await self._handle_rpc(peer, request_datagram)
|
await self._handle_rpc(peer, request_datagram)
|
||||||
|
@ -426,6 +427,7 @@ class KademliaProtocol(DatagramProtocol):
|
||||||
is_good = self.peer_manager.peer_is_good(peer)
|
is_good = self.peer_manager.peer_is_good(peer)
|
||||||
if is_good is None:
|
if is_good is None:
|
||||||
self.ping_queue.enqueue_maybe_ping(peer)
|
self.ping_queue.enqueue_maybe_ping(peer)
|
||||||
|
# only add a requesting contact to the routing table if it has replied to one of our requests
|
||||||
elif is_good is True:
|
elif is_good is True:
|
||||||
await self.add_peer(peer)
|
await self.add_peer(peer)
|
||||||
except ValueError as err:
|
except ValueError as err:
|
||||||
|
@ -453,11 +455,10 @@ class KademliaProtocol(DatagramProtocol):
|
||||||
peer, df, request = self.sent_messages[response_datagram.rpc_id]
|
peer, df, request = self.sent_messages[response_datagram.rpc_id]
|
||||||
if peer.address != address[0]:
|
if peer.address != address[0]:
|
||||||
df.set_exception(RemoteException(
|
df.set_exception(RemoteException(
|
||||||
f"response from {address[0]}:{address[1]}, "
|
f"response from {address[0]}, expected {peer.address}")
|
||||||
f"expected {peer.address}:{peer.udp_port}")
|
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
peer.set_id(response_datagram.node_id)
|
|
||||||
# We got a result from the RPC
|
# We got a result from the RPC
|
||||||
if peer.node_id == self.node_id:
|
if peer.node_id == self.node_id:
|
||||||
df.set_exception(RemoteException("node has our node id"))
|
df.set_exception(RemoteException("node has our node id"))
|
||||||
|
@ -465,6 +466,8 @@ class KademliaProtocol(DatagramProtocol):
|
||||||
elif response_datagram.node_id == self.node_id:
|
elif response_datagram.node_id == self.node_id:
|
||||||
df.set_exception(RemoteException("incoming message is from our node id"))
|
df.set_exception(RemoteException("incoming message is from our node id"))
|
||||||
return
|
return
|
||||||
|
peer.set_id(response_datagram.node_id)
|
||||||
|
peer.update_udp_port(address[1])
|
||||||
self.peer_manager.report_last_replied(address[0], address[1])
|
self.peer_manager.report_last_replied(address[0], address[1])
|
||||||
self.peer_manager.update_contact_triple(peer.node_id, address[0], address[1])
|
self.peer_manager.update_contact_triple(peer.node_id, address[0], address[1])
|
||||||
if not df.cancelled():
|
if not df.cancelled():
|
||||||
|
|
Loading…
Add table
Reference in a new issue