Skip to content

Commit

Permalink
exclude self and querying node from closest contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
jackrobison committed Jul 2, 2018
1 parent b6289d1 commit 929a0cc
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lbrynet/dht/routingtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,15 @@ def findCloseNodes(self, key, count=None, sender_node_id=None):
node is returning all of the contacts that it knows of.
@rtype: list
"""

exclude = [self._parentNodeID]
if sender_node_id:
exclude.append(sender_node_id)
if key in exclude:
exclude.remove(key)
count = count or constants.k
sender_node_id = sender_node_id or self._parentNodeID
distance = Distance(key)
contacts = self.get_contacts()
contacts = [c for c in contacts if c.id != sender_node_id]
contacts = [c for c in contacts if c.id not in exclude]
contacts.sort(key=lambda c: distance(c.id))
return contacts[:min(count, len(contacts))]

Expand Down

0 comments on commit 929a0cc

Please sign in to comment.