now splitting buckets completely per section 4.2 of paper
This commit is contained in:
parent
c370c8b95b
commit
670958f946
@ -59,6 +59,10 @@ class KBucket(object):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def depth(self):
|
||||||
|
sp = sharedPrefix([n.id for n in self.nodes.values()])
|
||||||
|
return len(sp)
|
||||||
|
|
||||||
def head(self):
|
def head(self):
|
||||||
return self.nodes.values()[0]
|
return self.nodes.values()[0]
|
||||||
|
|
||||||
@ -120,7 +124,6 @@ class RoutingTable(object):
|
|||||||
one, two = self.buckets[index].split()
|
one, two = self.buckets[index].split()
|
||||||
self.buckets[index] = one
|
self.buckets[index] = one
|
||||||
self.buckets.insert(index + 1, two)
|
self.buckets.insert(index + 1, two)
|
||||||
# todo split one/two if needed based on section 4.2
|
|
||||||
|
|
||||||
def getLonelyBuckets(self):
|
def getLonelyBuckets(self):
|
||||||
"""
|
"""
|
||||||
@ -141,7 +144,9 @@ class RoutingTable(object):
|
|||||||
if bucket.addNode(node):
|
if bucket.addNode(node):
|
||||||
return
|
return
|
||||||
|
|
||||||
if bucket.hasInRange(self.node):
|
# Per section 4.2 of paper, split if the bucket has the node in it's range
|
||||||
|
# or if the depth is not congruent to 0 mod 5
|
||||||
|
if bucket.hasInRange(self.node) or bucket.depth() % 5 != 0:
|
||||||
self.splitBucket(index)
|
self.splitBucket(index)
|
||||||
self.addContact(node)
|
self.addContact(node)
|
||||||
else:
|
else:
|
||||||
|
@ -21,7 +21,7 @@ def mknode(id=None, ip=None, port=None, intid=None):
|
|||||||
|
|
||||||
class FakeProtocol(object):
|
class FakeProtocol(object):
|
||||||
def __init__(self, sourceID, ksize=20):
|
def __init__(self, sourceID, ksize=20):
|
||||||
self.router = RoutingTable(self, ksize)
|
self.router = RoutingTable(self, ksize, Node(sourceID))
|
||||||
self.storage = {}
|
self.storage = {}
|
||||||
self.sourceID = sourceID
|
self.sourceID = sourceID
|
||||||
|
|
||||||
|
@ -39,3 +39,19 @@ class OrderedSet(list):
|
|||||||
if thing in self:
|
if thing in self:
|
||||||
self.remove(thing)
|
self.remove(thing)
|
||||||
self.append(thing)
|
self.append(thing)
|
||||||
|
|
||||||
|
|
||||||
|
def sharedPrefix(args):
|
||||||
|
"""
|
||||||
|
Find the shared prefix between the strings.
|
||||||
|
|
||||||
|
For instance, sharedPrefix(['blahblah', 'blahwhat']) is
|
||||||
|
'blah'.
|
||||||
|
"""
|
||||||
|
i = 0
|
||||||
|
while i < min(map(len, args)):
|
||||||
|
if len(set(map(operator.itemgetter(i), args))) != 1:
|
||||||
|
break
|
||||||
|
i += 1
|
||||||
|
return args[0][:i]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user