]> git.mxchange.org Git - quix0rs-apt-p2p.git/blobdiff - ktable.py
fix bug in pong handler
[quix0rs-apt-p2p.git] / ktable.py
index 9cd373246ab1ea23cf556e9e939d1128bef272cf..b47416ccf0243656b8d685def7ae1e5fbeda1dac 100644 (file)
--- a/ktable.py
+++ b/ktable.py
@@ -8,7 +8,7 @@ from types import *
 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
@@ -111,6 +111,7 @@ class KTable:
        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
@@ -218,11 +219,11 @@ import unittest
 
 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)