From f740f77f7eb6b0d0cf1b84d5e2e01fbdfd40292a Mon Sep 17 00:00:00 2001 From: Egbert Bouman Date: Mon, 12 Aug 2024 19:34:57 +0200 Subject: [PATCH] Ensure the default hop count is respected --- .../libtorrent/download_manager/download_config.py | 5 ++++- .../core/libtorrent/restapi/downloads_endpoint.py | 12 ++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/tribler/core/libtorrent/download_manager/download_config.py b/src/tribler/core/libtorrent/download_manager/download_config.py index 03050822fb..aff2e089f5 100644 --- a/src/tribler/core/libtorrent/download_manager/download_config.py +++ b/src/tribler/core/libtorrent/download_manager/download_config.py @@ -133,7 +133,10 @@ def from_defaults(settings: TriblerConfigManager) -> DownloadConfig: defaults.validate(Validator()) config = DownloadConfig(defaults) - config.set_hops(int(settings.get("libtorrent/download_defaults/number_hops"))) + if settings.get("libtorrent/download_defaults/anonymity_enabled"): + config.set_hops(int(settings.get("libtorrent/download_defaults/number_hops"))) + else: + config.set_hops(0) config.set_safe_seeding(settings.get("libtorrent/download_defaults/safeseeding_enabled")) config.set_dest_dir(settings.get("libtorrent/download_defaults/saveas")) diff --git a/src/tribler/core/libtorrent/restapi/downloads_endpoint.py b/src/tribler/core/libtorrent/restapi/downloads_endpoint.py index 8f7c10b185..56841c8d80 100644 --- a/src/tribler/core/libtorrent/restapi/downloads_endpoint.py +++ b/src/tribler/core/libtorrent/restapi/downloads_endpoint.py @@ -101,14 +101,14 @@ def create_dconfig_from_params(self, parameters: dict) -> tuple[DownloadConfig, """ download_config = DownloadConfig.from_defaults(self.download_manager.config) - anon_hops = parameters.get('anon_hops', 0) + anon_hops = parameters.get('anon_hops') safe_seeding = bool(parameters.get('safe_seeding', 0)) - if anon_hops > 0 and not safe_seeding: - return None, "Cannot set anonymous download without safe seeding enabled" - - if anon_hops >= 0: - download_config.set_hops(anon_hops) + if anon_hops is not None: + if anon_hops > 0 and not safe_seeding: + return None, "Cannot set anonymous download without safe seeding enabled" + if anon_hops >= 0: + download_config.set_hops(anon_hops) if safe_seeding: download_config.set_safe_seeding(True)