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._market_id) 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)
def __init__(self, parentNodeID): """ @param parentNodeID: The 160-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 160-bit ID space self._buckets = [kbucket.KBucket(rangeMin=0, rangeMax=2**160)] self._parentNodeID = parentNodeID
def __init__(self, parentNodeID, market_id): """ @param parentNodeID: The 160-bit node ID of the node to which this routing table belongs @type parentNodeID: str """ super(TreeRoutingTable, self).__init__(parentNodeID) self._log = logging.getLogger('[%s] %s' % (market_id, self.__class__.__name__)) self._buckets = [ kbucket.KBucket(rangeMin=0, rangeMax=2**200, market_id=market_id) ] self._parentNodeID = parentNodeID
def __init__(self, parent_node_id, market_id): """ Initialize a new TreeRoutingTable. For details, see RoutingTable documentation. """ super(TreeRoutingTable, self).__init__(parent_node_id, market_id) self.buckets = [ kbucket.KBucket(rangeMin=0, rangeMax=2**constants.BIT_NODE_ID_LEN, market_id=market_id) ]
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._buckets = [ kbucket.KBucket(rangeMin=0, rangeMax=2**constants.key_bits) ] self._parentNodeID = parentNodeID if not getTime: from time import time as getTime self._getTime = getTime
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
def __init__(self): self.buckets = {'':kbucket.KBucket('')}