Skip to content

Commit 335349d

Browse files
committed
Support SOCKS over Unix domain sockets
1 parent 557cb58 commit 335349d

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

electrumx/server/env.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def __init__(self, coin=None):
6060
self.force_proxy = self.boolean('FORCE_PROXY', False)
6161
self.tor_proxy_host = self.default('TOR_PROXY_HOST', 'localhost')
6262
self.tor_proxy_port = self.integer('TOR_PROXY_PORT', None)
63+
self.tor_proxy_path = self.default('TOR_PROXY_IPC_PATH', None)
6364

6465
# Misc
6566

electrumx/server/peers.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
import aiohttp
2020
from aiorpcx import (Event, Notification, RPCError, RPCSession, SOCKSError,
21-
SOCKSProxy, TaskGroup, TaskTimeout, connect_rs,
22-
handler_invocation, ignore_after, sleep)
21+
SOCKSProxy, TaskGroup, TaskTimeout, UnixAddress,
22+
connect_rs, handler_invocation, ignore_after, sleep)
2323
from aiorpcx.jsonrpc import CodeMessageError
2424

2525
from electrumx.lib.peer import Peer
@@ -185,15 +185,21 @@ async def _detect_proxy(self):
185185
186186
If found self.proxy is set to a SOCKSProxy instance, otherwise None.
187187
'''
188-
host = self.env.tor_proxy_host
189-
if self.env.tor_proxy_port is None:
190-
ports = [9050, 9150, 1080]
191-
else:
192-
ports = [self.env.tor_proxy_port]
188+
path = self.env.tor_proxy_path
189+
if path is None:
190+
host = self.env.tor_proxy_host
191+
if self.env.tor_proxy_port is None:
192+
ports = [9050, 9150, 1080]
193+
else:
194+
ports = [self.env.tor_proxy_port]
193195
while True:
194-
self.logger.info(f'trying to detect proxy on "{host}" '
195-
f'ports {ports}')
196-
proxy = await SOCKSProxy.auto_detect_at_host(host, ports, None)
196+
if path is None:
197+
self.logger.info(f'trying to detect proxy on "{host}" '
198+
f'ports {ports}')
199+
proxy = await SOCKSProxy.auto_detect_at_host(host, ports, None)
200+
else:
201+
self.logger.info(f'trying to detect proxy on "{path}"')
202+
proxy = await SOCKSProxy.auto_detect_at_address(UnixAddress(path), None)
197203
if proxy:
198204
self.proxy = proxy
199205
self.logger.info(f'detected {proxy}')

0 commit comments

Comments
 (0)