From 3a806973eae8b670cf3d1026d68586e8537fe167 Mon Sep 17 00:00:00 2001 From: Gavin Zhao Date: Thu, 10 Apr 2025 09:09:50 -0400 Subject: [PATCH] [Core] Respect listen_reuse_port to randomize port on startup The `listen_reuse_port` config is never respected in deluge. Practically, this means that users cannot randomize the listen port on startup. Before this change, this is what happens in `_set_listen_on`: 1. On run 1, `listen_random_port` is empty. 2. A random port is chosen, and its value is written into `listen_random_port` in `core.conf`. 3. On all subsequent runs, `deluged` reads `core.conf` and picks up `listen_random_port` from the previous run, so `listen_random_port` will never be randomized again. To fix this, we should read `listen_reuse_port` and if it's `false`, always disregard the current `listen_random_port` and randomly pick a new value for it. Signed-off-by: Gavin Zhao Closes: https://github.com/deluge-torrent/deluge/pull/477 --- deluge/core/preferencesmanager.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/deluge/core/preferencesmanager.py b/deluge/core/preferencesmanager.py index 7e5c207a1..4dbf4d156 100644 --- a/deluge/core/preferencesmanager.py +++ b/deluge/core/preferencesmanager.py @@ -200,7 +200,10 @@ class PreferencesManager(component.Component): def __set_listen_on(self): """Set the ports and interface address to listen for incoming connections on.""" if self.config['random_port']: - if not self.config['listen_random_port']: + if ( + not self.config['listen_reuse_port'] + or not self.config['listen_random_port'] + ): self.config['listen_random_port'] = random.randrange(49152, 65525) listen_ports = [ self.config['listen_random_port']