[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 <git@gzgz.dev>
Closes: https://github.com/deluge-torrent/deluge/pull/477
This commit is contained in:
Gavin Zhao 2025-04-10 09:09:50 -04:00 committed by Calum Lind
commit 3a806973ea
No known key found for this signature in database
GPG key ID: 90597A687B836BA3

View file

@ -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']