UNIX domain sockets are a mechanism for inter-process communication that are faster than local TCP ports (because there is no need for TCP overhead) and potentially more secure because access is managed by the filesystem instead of serving an open port on the system.
There has been work on unix domain sockets before but for now I just wanted to start on this single use-case which is enabling unix sockets from the client side, specifically connecting to a local Tor proxy (Tor can listen on unix sockets and even enforces strict curent-user-only access permission before binding) configured by -onion= or -proxy=
I copied the prefix unix: usage from Tor. With this patch built locally you can test with your own filesystem path (example):
tor --SocksPort unix:/Users/matthewzipkin/torsocket/x bitcoind -proxy=unix:/Users/matthewzipkin/torsocket/x
Prep work for this feature includes:
- Moving where and how we create sockaddr and Sock to accommodate AF_UNIX without disturbing CService
- Expanding Proxy class to represent either a CService or a UNIX socket (by its file path)
Future work:
- Enable UNIX sockets for ZMQ
- Enable UNIX sockets for I2P SAM proxy (some code is included in this PR but not tested or exposed to user options yet)
- Enable UNIX sockets on windows where supported
- Update Network Proxies dialog in GUI to support UNIX sockets
This is a backport of core#27375