コード例 #1
0
    def _splitBucket(self, oldBucketIndex):
        """ Splits the specified k-bucket into two new buckets which together
        cover the same range in the key/ID space

        @param oldBucketIndex: The index of k-bucket to split (in this table's
                               list of k-buckets)
        @type oldBucketIndex: int
        """
        # Resize the range of the current (old) k-bucket
        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,
                                    self._parentNodeID)
        oldBucket.rangeMax = splitPoint
        # Now, add the new bucket into the routing table tree
        self._buckets.insert(oldBucketIndex + 1, newBucket)
        # Finally, copy all nodes that belong to the new k-bucket into it...
        for contact in oldBucket._contacts:
            if newBucket.keyInRange(contact.id):
                newBucket.addContact(contact)
        # ...and remove them from the old bucket
        for contact in newBucket._contacts:
            oldBucket.removeContact(contact)
コード例 #2
0
 def __init__(self, parentNodeID, getTime=None):
     """
     @param parentNodeID: The n-bit node ID of the node to which this
                          routing table belongs
     @type parentNodeID: str
     """
     # Create the initial (single) k-bucket covering the range of the entire n-bit ID space
     self._parentNodeID = parentNodeID
     self._buckets = [
         kbucket.KBucket(rangeMin=0,
                         rangeMax=2**constants.key_bits,
                         node_id=self._parentNodeID)
     ]
     if not getTime:
         from twisted.internet import reactor
         getTime = reactor.seconds
     self._getTime = getTime
     self._ongoing_replacements = set()
コード例 #3
0
 def setUp(self):
     self.kbucket = kbucket.KBucket(0, 2**160)
コード例 #4
0
 def setUp(self):
     self.address_generator = address_generator()
     self.contact_manager = ContactManager()
     self.kbucket = kbucket.KBucket(0, 2**constants.key_bits, generate_id())