from node import Node
# The all-powerful, magical Kademlia "k" constant, bucket depth
-K = 20
+K = 8
# how many bits wide is our hash?
HASH_LENGTH = 160
this insert the node, returning None if successful, returns the oldest node in the bucket if it's full
the caller responsible for pinging the returned node and calling replaceStaleNode if it is found to be stale!!
"""
+ assert(node.id != " "*20)
# get the bucket for this node
i = self. _bucketIndexForInt(node.int)
## check to see if node is in the bucket already
class TestKTable(unittest.TestCase):
def setUp(self):
- self.a = Node(hash.newID(), 'localhost', 2002)
+ self.a = Node().init(hash.newID(), 'localhost', 2002)
self.t = KTable(self.a)
def test_replace_stale_node(self):
- self.b = Node(hash.newID(), 'localhost', 2003)
+ self.b = Node().init(hash.newID(), 'localhost', 2003)
self.t.replaceStaleNode(self.a, self.b)
assert(len(self.t.buckets[0].l) == 1)
assert(self.t.buckets[0].l[0].id == self.b.id)