exclude self and querying node from closest contacts

This commit is contained in:
Jack Robison 2018-07-02 14:44:56 -04:00
parent b6289d101d
commit 929a0cc5af
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2

View file

@ -161,12 +161,15 @@ class TreeRoutingTable(object):
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))]