Skip to content

Commit

Permalink
Merge pull request #1280 from hoffmabc/seed0-fix
Browse files Browse the repository at this point in the history
Peers should only relay reachable close nodes
  • Loading branch information
gubatron committed May 12, 2015
2 parents 7e0a6d7 + 0ce1193 commit 5e1d795
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
2 changes: 2 additions & 0 deletions node/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,5 @@
MSG_HEARTBEAT_ID = 'heartbeat'
MSG_RELAYTO_ID = 'relayto'
MSG_RELAY_ID = 'relay ' # Trailing space is intentional.

CLOSE_NODE_TIMELIMIT_IN_SECONDS = 5*60
34 changes: 20 additions & 14 deletions node/dht.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,20 +242,26 @@ def close_nodes(self, key, guid=None):
contacts = self.routing_table.find_close_nodes(key, constants.K, guid)
contact_list = []
for contact in contacts:
self.log.debug('Contact: %s', contact)
contact.avatar_url = contact.avatar_url if contact.avatar_url else None

contact_list.append((
contact.guid,
contact.hostname,
contact.port,
contact.pub,
contact.nickname,
contact.nat_type,
contact.avatar_url
))

return self.dedupe(contact_list)

stale_contact_time = time.time() - constants.CLOSE_NODE_TIMELIMIT_IN_SECONDS

if contact.last_reached > stale_contact_time:

contact.avatar_url = contact.avatar_url if contact.avatar_url else None

contact_list.append((
contact.guid,
contact.hostname,
contact.port,
contact.pub,
contact.nickname,
contact.nat_type,
contact.avatar_url
))

close_nodes = self.dedupe(contact_list)

return close_nodes

@_synchronized
def on_find_node_response(self, msg):
Expand Down

0 comments on commit 5e1d795

Please sign in to comment.