Example #1
0
    def __handle_announce_request(self, msg, address):

        if 'implied_port' in msg['a'].keys() and msg['a']['implied_port'] != 0:
            port = address[1]
        else:
            port = msg['a']['port']

        info = dht_store.SRC_INFO(dht_utils.id_to_hex(msg['a']['info_hash']), address[0], port, 1, int(time.time()))
        self.store.save(info)

        node = dht_bucket.Node(msg['a']['id'], *address)
        self.bucket.update(node.node_id, node)
Example #2
0
    def __handle_announce_request(self, msg, address):

        if 'implied_port' in msg['a'].keys() and msg['a']['implied_port'] != 0:
            port = address[1]
        else:
            port = msg['a']['port']

        info = dht_store.SRC_INFO(dht_utils.id_to_hex(msg['a']['info_hash']),
                                  address[0], port, 1, int(time.time()))
        self.store.save(info)

        node = dht_bucket.Node(msg['a']['id'], *address)
        self.bucket.update(node.node_id, node)
Example #3
0
    def __handle_get_peers_request(self, msg, address):
        # 接收到查询某个资源的请求,说明网络上可能存在该资源,因此保存该资源信息
        info = dht_store.SRC_INFO(dht_utils.id_to_hex(msg['a']['info_hash']), address[0], address[1], 0, int(time.time()))
        self.store.save(info)

        # 更新或保存发送请求的节点信息
        node = dht_bucket.Node(msg['a']['id'], *address)
        self.bucket.update(node.node_id, node)

        # 答复该节点的请求,以便下接收到announce_peer消息
        nodes = dht_utils.encode_nodes(self.bucket.get_kclose())
        data = {
            't': msg['t'],
            'y': 'r',
            'r': {'id': self.server_id, 'token': dht_utils.random_tranid(), 'nodes': nodes}
        }
        self.__send_message(data, address)
Example #4
0
    def __handle_get_peers_request(self, msg, address):
        # 接收到查询某个资源的请求,说明网络上可能存在该资源,因此保存该资源信息
        info = dht_store.SRC_INFO(dht_utils.id_to_hex(msg['a']['info_hash']),
                                  address[0], address[1], 0, int(time.time()))
        self.store.save(info)

        # 更新或保存发送请求的节点信息
        node = dht_bucket.Node(msg['a']['id'], *address)
        self.bucket.update(node.node_id, node)

        # 答复该节点的请求,以便下接收到announce_peer消息
        nodes = dht_utils.encode_nodes(self.bucket.get_kclose())
        data = {
            't': msg['t'],
            'y': 'r',
            'r': {
                'id': self.server_id,
                'token': dht_utils.random_tranid(),
                'nodes': nodes
            }
        }
        self.__send_message(data, address)