No metadata download
<p>I'm using libtorrent 1.0.9 and custom bindings (reproducible with python). Sometimes I can not download magnets because they're stuck without metadata (while there're >200 DHT nodes available). I'm able to reproduce the issue with this magnet:</p>

<pre><code>magnet:?xt=urn:btih:565DB305A27FFB321FCC7B064AFD7BD73AEDDA2B&amp;dn=bbb_sunflower_1080p_60fps_normal.mp4&amp;tr=udp%3a%2f%2ftracker.openbittorrent.com%3a80%2fannounce&amp;tr=udp%3a%2f%2ftracker.publicbt.com%3a80%2fannounce&amp;ws=http%3a%2f%2fdistribution.bbb3d.renderfarming.net%2fvideo%2fmp4%2fbbb_sunflower_1080p_60fps_normal.mp4
</code></pre>

<p>Meanwhile in other torrent clients (qBittorrent, Vuze) it gets the metadata very quickly. It's reproducible with following code:</p>

<pre><code>import libtorrent as lt
import time

session = lt.session()
session.listen_on(6881, 6891)
session.add_extension('ut_metadata')
session.add_extension('ut_pex')
session.add_extension('metadata_transfer')
session.add_dht_router("router.utorrent.com", 6881)
session.add_dht_router("router.bittorrent.com", 6881)
session.add_dht_router("dht.transmissionbt.com", 6881)
session.add_dht_router("dht.aelitis.com", 6881)
session.start_dht()
session.start_lsd()
session.start_upnp()
session.start_natpmp()

params = { 'save_path': '/tmp/'}
link ="magnet:?xt=urn:btih:565DB305A27FFB321FCC7B064AFD7BD73AEDDA2B&amp;dn=bbb_sunflower_1080p_60fps_normal.mp4&amp;tr=udp%3a%2f%2ftracker.openbittorrent.com%3a80%2fannounce&amp;tr=udp%3a%2f%2ftracker.publicbt.com%3a80%2fannounce&amp;ws=http%3a%2f%2fdistribution.bbb3d.renderfarming.net%2fvideo%2fmp4%2fbbb_sunflower_1080p_60fps_normal.mp4"
handle = lt.add_magnet_uri(session, link, params)

print('downloading metadata...')
while (not handle.has_metadata()):
    status=session.status()
    print('dht nodes: ', status.dht_nodes)
    time.sleep(1)
print ('got metadata, starting torrent download...')
while (handle.status().state != lt.torrent_status.seeding):
    print('%d %% done' % (handle.status().progress*100))
    time.sleep(1)
</code></pre>

<p>What I'm doing wrong?</p>

<p>This is most likely caused by a problem in the 1.0.x series, where some of the first responses from the DHT will make the node change its node ID (to match its external IP address, see <a href="http://libtorrent.org/dht_sec.html" rel="nofollow">this post</a>).</p>

<p>It does this by restarting the DHT node. Any in-flight torrent announces at that time will be lost. Waiting 15 minutes for the next announce should make the announce go through. Another option is to wait for the <a href="http://libtorrent.org/reference-Alerts.html#dht_bootstrap_alert" rel="nofollow">dht_bootstrap_alert</a> before adding the first torrent to the session.</p>

<p>This issue was fixed in the 1.1.x releases.</p>

python bittorrent dht libtorrent libtorrent-rasterbar