Ejemplo n.º 1
0
    def on_announce_peer(self, tid: bytes, nid: bytes, info_hash: bytes,
                         address: Tuple[str, int]) -> None:
        self.rpc.respond_announce_peer(
            tid=tid,
            nid=dht_utils.generate_neighbor_nid(self.node.nid, nid),
            address=address,
        )
        logger.debug(f"On announce peer, infohash {info_hash.hex()}")

        if not Torrent.exists(info_hash):
            self.metadata_fetcher.fetch(info_hash, address)
Ejemplo n.º 2
0
 def _make_neighbours(self) -> None:
     for node in self.routing_table.nodes:
         neighbour_nid = dht_utils.generate_neighbor_nid(
             self.node.nid, node.nid)
         self.rpc.find_node(neighbour_nid,
                            address=(node.address, node.port))
Ejemplo n.º 3
0
 def test_generate_neighbor_nid(self) -> None:
     neighbor_nid = generate_neighbor_nid(
         b"}\xe9P\x1d\x9ek\n\xfa\xfe\xc3 jc\xfa3\x1frtG\xb3",
         b"$d\xff\x93uy\xfeN]\xd5/\xd5cQ\x7f\xce\xd7\xaf\xca\x1c",
     )
     assert neighbor_nid == b"$d\xff\x93uy\xfeN]\xd5/\xd5cQ\x7f}\xe9P\x1d\x9e"