Fix missing trackers adding magnets

The changes to remove deprecated lt methods didn't account for magnet
trackers so magnets are missing trackers when added.

Previously the addition of trackers was handled by libtorrent when a url
was passed in add_torrent_params. The url parameter is deprecated so
instead we need to add both the info_hash and trackers.

Trac: https://dev.deluge-torrent.org/ticket/3530
This commit is contained in:
Calum Lind 2022-07-03 09:54:03 +01:00
parent 94d790c159
commit f52cf760e4
No known key found for this signature in database
GPG Key ID: 90597A687B836BA3
2 changed files with 7 additions and 2 deletions

View File

@ -436,8 +436,8 @@ class TorrentManager(component.Component):
magnet_info = get_magnet_info(magnet)
if magnet_info:
add_torrent_params['name'] = magnet_info['name']
add_torrent_params['trackers'] = list(magnet_info['trackers'])
torrent_id = magnet_info['info_hash']
# Workaround lt 1.2 bug for magnet resume data with no metadata
add_torrent_params['info_hash'] = bytes(bytearray.fromhex(torrent_id))
else:
raise AddTorrentError(

View File

@ -222,10 +222,15 @@ class TestCore(BaseTestCase):
@pytest_twisted.inlineCallbacks
def test_add_torrent_magnet(self):
info_hash = '60d5d82328b4547511fdeac9bf4d0112daa0ce00'
uri = deluge.common.create_magnet_uri(info_hash)
tracker = 'udp://tracker.example.com'
name = 'test magnet'
uri = deluge.common.create_magnet_uri(info_hash, name=name, trackers=[tracker])
options = {}
torrent_id = yield self.core.add_torrent_magnet(uri, options)
assert torrent_id == info_hash
torrent_status = self.core.get_torrent_status(torrent_id, ['name', 'trackers'])
assert torrent_status['trackers'][0]['url'] == tracker
assert torrent_status['name'] == name
def test_resume_torrent(self):
tid1 = self.add_torrent('test.torrent', paused=True)