From ad2dcf0893e48467a3113a4d9742030ef3f8c0e3 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Wed, 23 May 2018 17:06:45 -0400 Subject: [PATCH] add the parent node id to KBucket --- lbrynet/dht/kbucket.py | 3 ++- lbrynet/dht/routingtable.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lbrynet/dht/kbucket.py b/lbrynet/dht/kbucket.py index ead763895..de5484bb0 100644 --- a/lbrynet/dht/kbucket.py +++ b/lbrynet/dht/kbucket.py @@ -6,7 +6,7 @@ class KBucket(object): """ Description - later """ - def __init__(self, rangeMin, rangeMax): + def __init__(self, rangeMin, rangeMax, node_id): """ @param rangeMin: The lower boundary for the range in the n-bit ID space covered by this k-bucket @@ -17,6 +17,7 @@ class KBucket(object): self.rangeMin = rangeMin self.rangeMax = rangeMax self._contacts = list() + self._node_id = node_id def addContact(self, contact): """ Add contact to _contact list in the right order. This will move the diff --git a/lbrynet/dht/routingtable.py b/lbrynet/dht/routingtable.py index 05acb56f6..16e3ef1cb 100644 --- a/lbrynet/dht/routingtable.py +++ b/lbrynet/dht/routingtable.py @@ -40,8 +40,8 @@ class TreeRoutingTable(object): @type parentNodeID: str """ # Create the initial (single) k-bucket covering the range of the entire n-bit ID space - self._buckets = [kbucket.KBucket(rangeMin=0, rangeMax=2 ** constants.key_bits)] self._parentNodeID = parentNodeID + self._buckets = [kbucket.KBucket(rangeMin=0, rangeMax=2 ** constants.key_bits, node_id=self._parentNodeID)] if not getTime: from time import time as getTime self._getTime = getTime @@ -272,7 +272,7 @@ class TreeRoutingTable(object): oldBucket = self._buckets[oldBucketIndex] splitPoint = oldBucket.rangeMax - (oldBucket.rangeMax - oldBucket.rangeMin) / 2 # Create a new k-bucket to cover the range split off from the old bucket - newBucket = kbucket.KBucket(splitPoint, oldBucket.rangeMax) + newBucket = kbucket.KBucket(splitPoint, oldBucket.rangeMax, self._parentNodeID) oldBucket.rangeMax = splitPoint # Now, add the new bucket into the routing table tree self._buckets.insert(oldBucketIndex + 1, newBucket)