electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit b727824eedd7324133e18f698cf7babc156fd801
parent 34c2010e63ec35f88854bf655edebda22adc95b1
Author: ThomasV <thomasv@electrum.org>
Date:   Thu, 19 Nov 2015 12:42:11 +0100

fix #1554: use AF_INET instead of AF_UNIX, and write port number to lockfile

Diffstat:
Melectrum | 25++++++++++---------------
1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/electrum b/electrum @@ -30,7 +30,6 @@ import socket import Queue from collections import defaultdict -DAEMON_SOCKET = 'daemon.sock' script_dir = os.path.dirname(os.path.realpath(__file__)) is_bundle = getattr(sys, 'frozen', False) @@ -350,13 +349,11 @@ class NetworkServer(util.DaemonThread): print_error("client quit:", len(self.clients)) def run(self): - s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) - s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - daemon_socket = os.path.join(self.config.path, DAEMON_SOCKET) - if os.path.exists(daemon_socket): - os.remove(daemon_socket) - daemon_timeout = self.config.get('daemon_timeout', None) - s.bind(daemon_socket) + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.bind(('', 0)) + lockfile = os.path.join(self.config.path, 'lock') + with open(lockfile, 'w') as f: + f.write("%d"%s.getsockname()[1]) s.listen(5) s.settimeout(0.1) while self.is_running(): @@ -370,19 +367,17 @@ class NetworkServer(util.DaemonThread): def get_daemon(config): - daemon_socket = os.path.join(config.path, DAEMON_SOCKET) + lockfile = os.path.join(config.path, 'lock') try: - s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) - s.connect(daemon_socket) + with open(lockfile) as f: + num = int(f.read()) + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.connect(('', num)) return s - except socket.error: - return False except: - # do not use daemon if AF_UNIX is not available (windows) return False - if __name__ == '__main__': # make sure that certificates are here