test: extend the SOCKS5 Python proxy to actually connect to a destination

If requested, make the SOCKS5 Python proxy redirect each connection to a
given destination. Actually act as a real proxy, connecting the
client to a destination, except that the destination is not what the
client asked for.

This would enable us to "connect" to Tor addresses from the functional
tests.
This commit is contained in:
Vasil Dimov
2023-05-19 12:31:22 +02:00
parent ba621ffb9c
commit ebe42c00aa
2 changed files with 77 additions and 0 deletions

View File

@@ -167,3 +167,10 @@ def test_unix_socket():
return False
else:
return True
def format_addr_port(addr, port):
'''Return either "addr:port" or "[addr]:port" based on whether addr looks like an IPv6 address.'''
if ":" in addr:
return f"[{addr}]:{port}"
else:
return f"{addr}:{port}"