class TestMultiDHT(unittest.TestCase):
"""More complicated 20-node tests for the DHT."""
- timeout = 100
+ timeout = 200
num = 20
DHT_DEFAULTS = {'PORT': 9977,
'CHECKPOINT_INTERVAL': 300, 'CONCURRENT_REQS': 8,
def __init__(self):
self.nodes = []
bl1 = bl()
- bl1.l.append(dummy())
+ bl1.nodes.append(dummy())
bl2 = bl()
- bl2.l.append(dummy2)
+ bl2.nodes.append(dummy2)
buckets = [bl1, bl2]
self.store.dumpRoutingTable(buckets)
rt = self.store.getRoutingTable()
@param callback: the method to call with the results, it must take 1
parameter, the list of K closest nodes
"""
+ # Mark the bucket as having been accessed
+ self.table.touch(id)
+
# Start with our node
nodes = [copy(self.node)]
@param callback: the method to call with the results, it must take 1
parameter, the list of nodes with values
"""
+ # Mark the bucket as having been accessed
+ self.table.touch(key)
+
# Start with ourself
nodes = [copy(self.node)]
nodes.sort(lambda a, b, num=num: cmp(num ^ a.num, num ^ b.num))
return nodes[:K]
+ def touch(self, id):
+ """Mark a bucket as having been looked up.
+
+ @type id: C{string} or C{int} or L{node.Node}
+ @param id: the ID in the bucket that was accessed
+ """
+ # Get the bucket number from the input
+ num = self._nodeNum(id)
+ i = self._bucketIndexForInt(num)
+
+ self.buckets[i].touch()
+
def _mergeBucket(self, i):
"""Merge unneeded buckets after removing a node.
# note that we removed the original and replaced it with the new one
# utilizing this nodes new contact info
self.buckets[i].add(node)
- self.buckets[i].touch()
return True
# We don't have this node, check to see if the bucket is full
if contacted:
node.updateLastSeen()
self.buckets[i].add(node)
- self.buckets[i].touch()
log.msg('Added node to routing table: %s/%s' % (node.host, node.port))
return True
return False
except ValueError:
return None
else:
- self.buckets[i].touch()
return tstamp
def invalidateNode(self, n):