From f52cf760e4934f1270c077305a479a9d2ec5fd47 Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Sun, 3 Jul 2022 09:54:03 +0100 Subject: [PATCH] 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 --- deluge/core/torrentmanager.py | 2 +- deluge/tests/test_core.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py index 4904e94ed..5609df4bd 100644 --- a/deluge/core/torrentmanager.py +++ b/deluge/core/torrentmanager.py @@ -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( diff --git a/deluge/tests/test_core.py b/deluge/tests/test_core.py index f1c2e3be8..6a3fb9506 100644 --- a/deluge/tests/test_core.py +++ b/deluge/tests/test_core.py @@ -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)