Exemplo n.º 1
0
 def __init__(self, my_id, target):
     GetPeersLookup.__init__(self, my_id, None, target, None, 0)
     self.bootstrap_alpha = 4
     self.normal_alpha = 4
     self.normal_m = 1
     self.slowdown_alpha = 4
     self.slowdown_m = 1
     self._get_peers_msg = message.OutgoingFindNodeQuery(my_id, target)
Exemplo n.º 2
0
    def _get_maintenance_query(self, node_):
        if not node_.id:
            # Bootstrap nodes don't have id
            return message.OutgoingFindNodeQuery(node_, self.my_node.id,
                                                 self.my_node.id, None)
        if random.choice((False, True)):
            # 50% chance to send find_node with my id as target
            return message.OutgoingFindNodeQuery(node_, self.my_node.id,
                                                 self.my_node.id, None)

        # 50% chance to send a find_node to fill up a non-full bucket
        target_log_distance = self.table.find_next_bucket_with_room_index(
            node_=node_)
        if target_log_distance:
            target = self.my_node.id.generate_close_id(target_log_distance)
            return message.OutgoingFindNodeQuery(node_, self.my_node.id,
                                                 target, None)
        else:
            # Every bucket is full. We send a ping instead.
            return message.OutgoingPingQuery(node_, self.my_node.id)
Exemplo n.º 3
0
 def _get_maintenance_query(self, node_):
     if not node_.id:
         return Query(self.find_closest_msg, node_)
     elif random.choice((False, True)):
         return Query(self.find_closest_msg, node_)
     target_log_distance = self.table.find_next_bucket_with_room_index(
         node_=node_)
     if target_log_distance:
         target = self.my_node.id.generate_close_id(target_log_distance)
         return Query(
             message.OutgoingFindNodeQuery(self.my_node.id, target), node_)
     else:
         return Query(self.ping_msg, node_)
Exemplo n.º 4
0
 def __init__(self, my_node, bootstrap_nodes):
     self.my_node = my_node
     self.bootstrap_nodes = iter(bootstrap_nodes)
     self.table = RoutingTable(my_node, NODES_PER_BUCKET)
     self.ping_msg = message.OutgoingPingQuery(my_node.id)
     self.find_closest_msg = message.OutgoingFindNodeQuery(
         my_node.id, my_node.id)
     self._next_stale_maintenance_index = 0
     self._maintenance_mode = BOOTSTRAP_MODE
     self._replacement_queue = _ReplacementQueue(self.table)
     self._query_received_queue = _QueryReceivedQueue(self.table)
     self._found_nodes_queue = _FoundNodesQueue(self.table)
     self._maintenance_tasks = [
         self._ping_a_staled_rnode, self._ping_a_query_received_node,
         self._ping_a_found_node, self._ping_a_replacement_node
     ]
Exemplo n.º 5
0
    def __init__(self, my_node, bootstrap_nodes):
        self.my_node = my_node
        #Copy the bootstrap list
        self.bootstrap_nodes = iter(bootstrap_nodes)

        self.table = RoutingTable(my_node, NODES_PER_BUCKET)
        self.ping_msg = message.OutgoingPingQuery(my_node.id)
        self.find_closest_msg = message.OutgoingFindNodeQuery(
            my_node.id, my_node.id)

        # maintenance variables
        self._maintenance_mode = BOOTSTRAP_MODE
        self._pinged_q_rnodes = {}  # questionable nodes which have been
        # recently pinged
        self._maintenance_tasks = [
            self._refresh_stale_bucket,
            #self._ping_a_staled_rnode,
            # self._ping_a_query_received_node,
            # self._ping_a_found_node,
        ]