예제 #1
0
파일: routing.py 프로젝트: Beskhue/otdht
 def _findBucket(self, node):
     """
     Find the appropriate bucket for the given node
     """
     for bucket in buckets:
         if bucket.inRange(node):
             return bucket
         #if bucket.low <= node and node <= bucket.high:
         #    return bucket
     return None
예제 #2
0
파일: routing.py 프로젝트: Beskhue/otdht
 def findNode(self, target: hash.hash.Hash):
     """
     Find a node with the given ID in the routing table.
     """
     for bucket in self.buckets:
         if bucket.inRange(nodeID):
             for node in bucket:
                 if node.hash == target:
                     return node
                     
             return None
     return None
예제 #3
0
    def addNode(self, node: dht.node.Node):
        """
        Attempt to add the given node to the routing table.
        """

        bucket = self._findBucket(node)
        if bucket == None:
            raise Exception("Found no bucket for given id")

        if not node in bucket:
            # We do not have this node on our routing table yet;
            # attempt to add it.
            if len(bucket) < MAX_NODES_PER_BUCKET:
                bucket.append(node)
            else:
                if bucket.inRange(myID):
                    # Our own node's ID is in the appropriate bucket's range,
                    # split the bucket and recursively attempt to add the node.
                    self._splitBucket(bucket)
                    self.addNode(node)
                else:
                    # TODO: handle this
                    pass
예제 #4
0
파일: routing.py 프로젝트: Beskhue/otdht
 def addNode(self, node: dht.node.Node):
     """
     Attempt to add the given node to the routing table.
     """
     
     bucket = self._findBucket(node)
     if bucket == None:
         raise Exception("Found no bucket for given id")
     
     if not node in bucket:
         # We do not have this node on our routing table yet;
         # attempt to add it.
         if len(bucket) < MAX_NODES_PER_BUCKET:
             bucket.append(node)
         else:
             if bucket.inRange(myID):
                 # Our own node's ID is in the appropriate bucket's range,
                 # split the bucket and recursively attempt to add the node.
                 self._splitBucket(bucket)
                 self.addNode(node)
             else:
                 # TODO: handle this
                 pass