chenjiandongx / magnet-dht

✌️ Python3 BitTorrent DHT crawler
MIT License
947 stars 284 forks source link

作者在peers_request时搜集hash info,导致大量的hash info不可用 #36

Open 691778949 opened 3 years ago

691778949 commented 3 years ago

def on_get_peers_request(self, msg, address): """ 处理 get_peers 请求,获取 info hash

    :param msg: 节点报文信息
    :param address: 节点地址
    """
    tid = msg[b"t"]
    try:
        info_hash = msg[b"a"][b"info_hash"]
        self.save_magnet(info_hash)
    except KeyError:
        # 没有对应的 info hash,发送错误回复
        self.send_error(tid, address)

get_peers 消息里的 info_hash 我们可以进行忽略,此时对方也是在查找对应 info_hash 的种子文件,只有收到 announce_peer 消息时的 info_hash 对我们才有用,因为它表示当前对方正在指定端口下载该种子文件的 metadata 信息。