示例#1
0
    def __init__(self, dht_addr, state_path, routing_m_mod, lookup_m_mod):
        self.state_filename = os.path.join(state_path, STATE_FILENAME)
        self.load_state()
        if not self._my_id:
            self._my_id = identifier.RandomId()
        self._my_node = Node(dht_addr, self._my_id)
        self._tracker = tracker.Tracker()
        self._token_m = token_manager.TokenManager()

        self._reactor = ThreadedReactor()
        self._reactor.listen_udp(self._my_node.addr[1],
                                 self._on_datagram_received)
        #self._rpc_m = RPCManager(self._reactor)
        self._querier = Querier(self._my_id)
        bootstrap_nodes = self.loaded_nodes or BOOTSTRAP_NODES
        del self.loaded_nodes
        self._routing_m = routing_m_mod.RoutingManager(self._my_node, 
                                                       bootstrap_nodes)
#        self._responder = Responder(self._my_id, self._routing_m,
#                                    self._tracker, self._token_m)

        self._lookup_m = lookup_m_mod.LookupManager(self._my_id)
        current_time = time.time()
        self._next_maintenance_ts = current_time
        self._next_save_state_ts = current_time + SAVE_STATE_DELAY
        
        self._running = False
 def __init__(self, my_id, routing_m, msg_f, bootstrap_mode=False):
     self._my_id = my_id
     self._routing_m = routing_m
     self.msg_f = msg_f
     self.bootstrap_mode = bootstrap_mode
     self._tracker = tracker.Tracker()
     self._token_m = token_manager.TokenManager()
示例#3
0
    def __init__(self, dht_addr):
        self.my_addr = dht_addr
        self.my_id = identifier.RandomId()
        self.my_node = Node(self.my_addr, self.my_id)
        self.tracker = tracker.Tracker()
        self.token_m = token_manager.TokenManager()

        self.reactor = ThreadedReactor()
        self.rpc_m = RPCManager(self.reactor, self.my_addr[1])
        self.querier = Querier(self.rpc_m, self.my_id)
        self.routing_m = RoutingManager(self.my_node, self.querier,
                                        bootstrap_nodes)
        self.responder = Responder(self.my_id, self.routing_m,
                                   self.tracker, self.token_m)

        self.responder.set_on_query_received_callback(
            self.routing_m.on_query_received)
        self.querier.set_on_response_received_callback(
            self.routing_m.on_response_received)
        self.querier.set_on_error_received_callback(
            self.routing_m.on_error_received)
        self.querier.set_on_timeout_callback(self.routing_m.on_timeout)
        self.querier.set_on_nodes_found_callback(self.routing_m.on_nodes_found)

        self.routing_m.do_bootstrap()

        self.rpc_m.add_msg_callback(QUERY,
                                    self.responder.on_query_received)

        self.lookup_m = LookupManager(self.my_id, self.querier,
                                      self.routing_m)
示例#4
0
    def __init__(self, dht_addr):
        my_addr = dht_addr
        my_id = identifier.RandomId()
        my_node = Node(my_addr, my_id)
        tracker_ = tracker.Tracker()
        token_m = token_manager.TokenManager()

        self.reactor = ThreadedReactor()
        rpc_m = RPCManager(self.reactor, my_addr[1])
        querier_ = Querier(rpc_m, my_id)
        routing_m = RoutingManager(my_node, querier_, bootstrap_nodes)
        responder_ = Responder(my_id, routing_m, tracker_, token_m)

        responder_.set_on_query_received_callback(routing_m.on_query_received)
        querier_.set_on_response_received_callback(
            routing_m.on_response_received)
        querier_.set_on_error_received_callback(routing_m.on_error_received)
        querier_.set_on_timeout_callback(routing_m.on_timeout)
        querier_.set_on_nodes_found_callback(routing_m.on_nodes_found)

        routing_m.do_bootstrap()

        rpc_m.add_msg_callback(QUERY, responder_.on_query_received)

        self.lookup_m = LookupManager(my_id, querier_, routing_m)
        self._routing_m = routing_m
示例#5
0
 def setup(self):
     routing_m = routing_manager.RoutingManagerMock()
     self.tracker = tracker.Tracker()
     self.token_m = token_manager.TokenManager()
     self.responder = responder.Responder(tc.SERVER_ID, routing_m,
                                          self.tracker, self.token_m)
     self.notification_callback_done = False
     self.responder.set_on_query_received_callback(self._notify_routing_m)
 def test_create_find_token(self):
     handle = finder.find("/")
     tm = token_manager.TokenManager()
     token_value, expires_at = tm.create_token(handle.item_id, 50, {"path": "/foo"}, days=10)
     self.assertEquals(len(token_value), 50)
     self.assertTrue(expires_at)
     item_id, data = tm.find_token(token_value)
     self.assertEquals(handle.item_id, item_id)
     self.assertEquals(data, {"path": "/foo"})
 def test_fail_find_expired(self):
     handle = finder.find("/")
     tm = token_manager.TokenManager()
     # Create token that expires immediately
     token_value, expires_at = tm.create_token(handle.item_id, 50, {"path": "/foo"}, seconds=0)
     self.assertEquals(len(token_value), 50)
     self.assertTrue(expires_at)
     time.sleep(1)
     item_id, data = tm.find_token(token_value)
     self.assertIsNone(item_id)
     self.assertIsNone(data)
示例#8
0
    def __init__(self, pymdht_version,
                 my_node, state_filename,
                 routing_m_mod, lookup_m_mod,
                 experimental_m_mod,
                 private_dht_name):
        
        if size_estimation:
            self._size_estimation_file = open('size_estimation.dat', 'w')
        
        
        self.state_filename = state_filename
        saved_id, saved_bootstrap_nodes = state.load(self.state_filename)
        my_addr = my_node.addr
        self._my_id = my_node.id # id indicated by user 
        if not self._my_id:
            self._my_id = saved_id # id loaded from file
        if not self._my_id:
            self._my_id = self._my_id = identifier.RandomId() # random id
        self._my_node = Node(my_addr, self._my_id)
        self.msg_f = message.MsgFactory(pymdht_version, self._my_id,
                                        private_dht_name)
        self._tracker = tracker.Tracker()
        self._token_m = token_manager.TokenManager()

        self._querier = Querier()
        self._routing_m = routing_m_mod.RoutingManager(
            self._my_node, saved_bootstrap_nodes, self.msg_f)
        self._lookup_m = lookup_m_mod.LookupManager(self._my_id, self.msg_f)
        self._experimental_m = experimental_m_mod.ExperimentalManager(
            self._my_node.id, self.msg_f) 
                  
        current_ts = time.time()
        self._next_save_state_ts = current_ts + SAVE_STATE_DELAY
        self._next_maintenance_ts = current_ts
        self._next_timeout_ts = current_ts
        self._next_main_loop_call_ts = current_ts
        self._pending_lookups = []
示例#9
0
 def setup(self):
     self.token_m1 = token_manager.TokenManager()
     self.token_m2 = token_manager.TokenManager()
示例#10
0
 def setup(self):
     self.token_m = token_manager.TokenManager()