diff --git a/electrumx/server/env.py b/electrumx/server/env.py index 1a4cd9c73..fb582323e 100644 --- a/electrumx/server/env.py +++ b/electrumx/server/env.py @@ -60,6 +60,7 @@ def __init__(self, coin=None): self.force_proxy = self.boolean('FORCE_PROXY', False) self.tor_proxy_host = self.default('TOR_PROXY_HOST', 'localhost') self.tor_proxy_port = self.integer('TOR_PROXY_PORT', None) + self.tor_proxy_path = self.default('TOR_PROXY_IPC_PATH', None) # Misc diff --git a/electrumx/server/peers.py b/electrumx/server/peers.py index dcb9ab7db..359c652ae 100644 --- a/electrumx/server/peers.py +++ b/electrumx/server/peers.py @@ -18,8 +18,8 @@ import aiohttp from aiorpcx import (Event, Notification, RPCError, RPCSession, SOCKSError, - SOCKSProxy, TaskGroup, TaskTimeout, connect_rs, - handler_invocation, ignore_after, sleep) + SOCKSProxy, TaskGroup, TaskTimeout, UnixAddress, + connect_rs, handler_invocation, ignore_after, sleep) from aiorpcx.jsonrpc import CodeMessageError from electrumx.lib.peer import Peer @@ -185,15 +185,21 @@ async def _detect_proxy(self): If found self.proxy is set to a SOCKSProxy instance, otherwise None. ''' - host = self.env.tor_proxy_host - if self.env.tor_proxy_port is None: - ports = [9050, 9150, 1080] - else: - ports = [self.env.tor_proxy_port] + path = self.env.tor_proxy_path + if path is None: + host = self.env.tor_proxy_host + if self.env.tor_proxy_port is None: + ports = [9050, 9150, 1080] + else: + ports = [self.env.tor_proxy_port] while True: - self.logger.info(f'trying to detect proxy on "{host}" ' - f'ports {ports}') - proxy = await SOCKSProxy.auto_detect_at_host(host, ports, None) + if path is None: + self.logger.info(f'trying to detect proxy on "{host}" ' + f'ports {ports}') + proxy = await SOCKSProxy.auto_detect_at_host(host, ports, None) + else: + self.logger.info(f'trying to detect proxy on "{path}"') + proxy = await SOCKSProxy.auto_detect_at_address(UnixAddress(path), None) if proxy: self.proxy = proxy self.logger.info(f'detected {proxy}') diff --git a/electrumx/server/session.py b/electrumx/server/session.py index fa2cbd676..3418b6d41 100644 --- a/electrumx/server/session.py +++ b/electrumx/server/session.py @@ -23,9 +23,10 @@ import attr import pylru -from aiorpcx import (Event, JSONRPCAutoDetect, JSONRPCConnection, +from aiorpcx import (Event, JSONRPCAutoDetect, JSONRPCConnection, NetAddress, ReplyAndDisconnect, Request, RPCError, RPCSession, - TaskGroup, handler_invocation, serve_rs, serve_ws, sleep) + TaskGroup, UnixAddress, handler_invocation, serve_rs, + serve_ws, sleep) import electrumx import electrumx.lib.util as util @@ -1236,6 +1237,8 @@ def is_tor(self): proxy_address = self.peer_mgr.proxy_address() if not proxy_address: return False + if isinstance(proxy_address, UnixAddress): + proxy_address = NetAddress("127.0.0.1", 9150) return self.remote_address().host == proxy_address.host async def replaced_banner(self, banner):