1
0

network: use TOR stream isolation

also refactor, for proxy instantiation, use Network instance, not a proxy dict.
This commit is contained in:
Sander van Grieken
2024-10-14 13:32:22 +02:00
parent 0f26f38d18
commit f4520b9e0d
7 changed files with 35 additions and 23 deletions

View File

@@ -1938,7 +1938,7 @@ class NetworkRetryManager(Generic[_NetAddrType]):
self._last_tried_addr.clear()
class MySocksProxy(aiorpcx.SOCKSProxy):
class ESocksProxy(aiorpcx.SOCKSProxy):
# note: proxy will not leak DNS as create_connection()
# sets (local DNS) resolve=False by default
@@ -1952,12 +1952,17 @@ class MySocksProxy(aiorpcx.SOCKSProxy):
return reader, writer
@classmethod
def from_proxy_dict(cls, proxy: dict = None) -> Optional['MySocksProxy']:
if not proxy:
def from_network_settings(cls, network: Optional['Network']) -> Optional['ESocksProxy']:
if not network or not network.proxy:
return None
proxy = network.proxy
username, pw = proxy.get('user'), proxy.get('password')
if not username or not pw:
auth = None
# is_proxy_tor is tri-state; None indicates it is still probing the proxy to test for TOR
if network.is_proxy_tor:
auth = aiorpcx.socks.SOCKSRandomAuth()
else:
auth = None
else:
auth = aiorpcx.socks.SOCKSUserAuth(username, pw)
addr = aiorpcx.NetAddress(proxy['host'], proxy['port'])