Browse Source

daemon: change rpcsock default to "unix" where available

The daemon by default listens for RPC over a socket.
Before this change, this socket was a TCP/IP network socket (over localhost),
but now we change it to be a unix domain socket by default (if available).

This socket is used not only when sending commands over JSON-RPC,
but also when using the CLI, and to a tiny extent even used when running the GUI.
The type of socket used (and hence this change) is invisible to CLI and GUI users.
JSON-RPC users might want to use either the --rpcsock CLI flag
or set the "rpcsock" config key (to "tcp") to switch back to using a TCP/IP socket.

In practice it seems unix domain sockets are available on
all mainstream OSes/platforms, except for Windows.

closes https://github.com/spesmilo/electrum/issues/7553
patch-4
SomberNight 3 years ago
parent
commit
12b659ff99
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 10
      electrum/daemon.py

10
electrum/daemon.py

@ -33,6 +33,7 @@ from typing import Dict, Optional, Tuple, Iterable, Callable, Union, Sequence, M
from base64 import b64decode, b64encode
from collections import defaultdict
import json
import socket
import aiohttp
from aiohttp import web, client_exceptions
@ -64,7 +65,12 @@ class DaemonNotRunning(Exception):
def get_rpcsock_defaultpath(config: SimpleConfig):
return os.path.join(config.path, 'daemon_rpc_socket')
def get_rpcsock_default_type(osname):
def get_rpcsock_default_type():
# Use unix domain sockets when available,
# with the extra paranoia that in case windows "implements" them,
# we want to test it before making it the default there.
if hasattr(socket, 'AF_UNIX') and sys.platform != 'win32':
return 'unix'
return 'tcp'
def get_lockfile(config: SimpleConfig):
@ -245,7 +251,7 @@ class CommandsServer(AuthenticatedServer):
self.fd = fd
self.config = daemon.config
sockettype = self.config.get('rpcsock', 'auto')
self.socktype = sockettype if sockettype != 'auto' else get_rpcsock_default_type(os.name)
self.socktype = sockettype if sockettype != 'auto' else get_rpcsock_default_type()
self.sockpath = self.config.get('rpcsockpath', get_rpcsock_defaultpath(self.config))
self.host = self.config.get('rpchost', '127.0.0.1')
self.port = self.config.get('rpcport', 0)

Loading…
Cancel
Save