From 929a0cc5afcbc434cd87dcf84c06e7056bd8332a Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Mon, 2 Jul 2018 14:44:56 -0400 Subject: [PATCH] exclude self and querying node from closest contacts --- lbrynet/dht/routingtable.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lbrynet/dht/routingtable.py b/lbrynet/dht/routingtable.py index db6160db6..89d1a5e13 100644 --- a/lbrynet/dht/routingtable.py +++ b/lbrynet/dht/routingtable.py @@ -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))]