test: make reusable SOCKS5 server starting

Extract the part of `p2p_private_broadcast.py` that configures and
starts the SOCKS5 server into a reusable function and put it into
`test_framework/socks5.py`.

Use bind port 0 to let the OS pick an available port instead of
hackishly assuming that `p2p_port(N)` is available where N is more
than the number of the nodes the test uses.

Github-Pull: #35410
Rebased-From: 2ffa81fac4
This commit is contained in:
Vasil Dimov
2026-05-29 09:04:48 +02:00
committed by fanquake
parent 66377c3c84
commit ef20249568
2 changed files with 15 additions and 17 deletions

View File

@@ -327,3 +327,15 @@ class Socks5Server():
logger.debug(f"Stop(): Handler {i} thread joined")
else:
logger.warning(f"Stop(): Handler thread {i} didn't finish after force close")
def start_socks5_server(destinations_factory):
config = Socks5Configuration()
config.addr = ("127.0.0.1", 0) # Use port=0 to let the OS pick one. The actual port is later in server.conf.addr[1].
config.unauth = True
config.auth = True
config.destinations_factory = destinations_factory
server = Socks5Server(config)
server.start()
return server