electrum

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

commit 8e54d5c4d49e2a5319311fffcb109b6360d6340d
parent d4d93b39285856209b4bd0e3500868e6b936f9a6
Author: Johann Bauer <bauerj@bauerj.eu>
Date:   Sat, 25 Feb 2017 13:36:24 +0100

Make proxies work

Diffstat:
Mgui/qt/__init__.py | 2+-
Mgui/qt/network_dialog.py | 6+++---
Mlib/network.py | 11+++++++----
Mlib/paymentrequest.py | 2+-
4 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/gui/qt/__init__.py b/gui/qt/__init__.py @@ -52,7 +52,7 @@ try: except Exception as e: print(e) print("Error: Could not find icons file.") - print("Please run 'pyrcc4 icons.qrc -o gui/qt/icons_rc.py', and reinstall Electrum") + print("Please run 'pyrcc4 icons.qrc -o gui/qt/icons_rc.py -py3', and reinstall Electrum") sys.exit(1) from .util import * # * needed for plugins diff --git a/gui/qt/network_dialog.py b/gui/qt/network_dialog.py @@ -497,12 +497,12 @@ class TorDetector(QThread): @staticmethod def is_tor_port(port): try: - s = socket._socketobject(socket.AF_INET, socket.SOCK_STREAM) + s = (socket._socketobject if hasattr(socket, "_socketobject") else socket.socket)(socket.AF_INET, socket.SOCK_STREAM) s.settimeout(0.1) s.connect(("127.0.0.1", port)) # Tor responds uniquely to HTTP-like requests - s.send("GET\n") - if "Tor is not an HTTP Proxy" in s.recv(1024): + s.send(b"GET\n") + if b"Tor is not an HTTP Proxy" in s.recv(1024): return True except socket.error: pass diff --git a/lib/network.py b/lib/network.py @@ -40,7 +40,7 @@ import threading import socket import json -from . import socks +import socks from . import util from . import bitcoin from .bitcoin import * @@ -443,13 +443,16 @@ class Network(util.DaemonThread): # socks.py seems to want either None or a non-empty string username=(proxy.get("user", "") or None), password=(proxy.get("password", "") or None)) + # Store these somewhere so we can un-monkey-patch + if not hasattr(socket, "_socketobject"): + socket._socketobject = socket.socket + socket._getaddrinfo = socket.getaddrinfo socket.socket = socks.socksocket # prevent dns leaks, see http://stackoverflow.com/questions/13184205/dns-over-proxy socket.getaddrinfo = lambda *args: [(socket.AF_INET, socket.SOCK_STREAM, 6, '', (args[0], args[1]))] else: - if six.PY2: - socket.socket = socket._socketobject - socket.getaddrinfo = socket._socket.getaddrinfo + socket.socket = socket._socketobject + socket.getaddrinfo = socket._getaddrinfo def start_network(self, protocol, proxy): assert not self.interface and not self.interfaces diff --git a/lib/paymentrequest.py b/lib/paymentrequest.py @@ -42,7 +42,7 @@ from six.moves import urllib_parse try: - from . import paymentrequest_pb2_py3 as pb2 + from . import paymentrequest_pb2 as pb2 except ImportError: sys.exit("Error: could not find paymentrequest_pb2.py. Create it with 'protoc --proto_path=lib/ --python_out=lib/ lib/paymentrequest.proto'")