I've built a DHT crawler reading/using BEP 5 from the bittorrent standard. With it I can gather infohashes from torrents and query DHT nodes for peers. Thus said, having:
- A torrent infohash.
- Current torrent peers.
How can I download the torrent?
BEP 9 suggest a magnet schema in the following form (omitting the tracker and name part):
magnet:?xt=urn:btih:<info-hash>&dn=<name>&tr=<tracker-url>&x.pe=<peer-address>
With this approach my current torrent client (Transmission) is stuck trying to get peers. In case of compatibility issues, I tried many other clients with no luck.
My second approach was to load the corresponding DHT node to the client temporarily and load the magnet url in the simplest form of:
magnet:?xt=urn:btih:<info-hash>
yielding no results.
In the following code, supposing we have infohash "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" that we received from listening DHT node "router.bittorrent.com:6881", shouldn't the following sample fetch the metadata?
import libtorrent as lt
import time
session = lt.session()
session.listen_on(6881, 6891)
session.add_dht_router("router.bittorrent.com", 6881)
session.start_dht()
time.sleep(1)
params = {"url":"magnet:?xt=urn:btih:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "save_path":'.'}
h = session.add_torrent(params)
while (not h.has_metadata()):
time.sleep(1)
# download...
Small edit to clarify on the first approach:
Having a peer I just discovered from an infohash in the DHT with ip:port of X:Y and another peer in the same logic with ip:port of Z:Y, shouldn't the following magnet, pasted in any torrent client supporting BEP 9, download the torrent?
magnet:?xt=urn:btih:<info-hash>&x.pe=X:Y&x.pe=Z:Y