Page MenuHomePhabricator

D14287.id41515.diff
No OneTemporary

D14287.id41515.diff

diff --git a/electrum/electrumabc_plugins/fusion/covert.py b/electrum/electrumabc_plugins/fusion/covert.py
--- a/electrum/electrumabc_plugins/fusion/covert.py
+++ b/electrum/electrumabc_plugins/fusion/covert.py
@@ -66,26 +66,25 @@
def is_tor_port(host, port):
if not 0 <= port < 65536:
return False
- try:
+
+ if not hasattr(socket, "_socketobject"):
socketclass = socket.socket
+ else:
+ # socket.socket could be monkeypatched (see electrumabc/network.py),
+ # in which case we need to get the real one.
+ socketclass = socket._socketobject
+
+ ret = False
+ with socketclass(socket.AF_INET, socket.SOCK_STREAM) as s:
+ s.settimeout(0.1)
try:
- # socket.socket could be monkeypatched (see electrumabc/network.py),
- # in which case we need to get the real one.
- socketclass = socket._socketobject
- except AttributeError:
+ s.connect((host, port))
+ # Tor responds uniquely to HTTP-like requests
+ s.send(b"GET\n")
+ ret = b"Tor is not an HTTP Proxy" in s.recv(1024)
+ except socket.error:
pass
- s = socketclass(socket.AF_INET, socket.SOCK_STREAM)
- s.settimeout(0.1)
- s.connect((host, port))
- # Tor responds uniquely to HTTP-like requests
- s.send(b"GET\n")
- if b"Tor is not an HTTP Proxy" in s.recv(1024):
- s.close()
- return True
- s.close()
- except socket.error:
- pass
- return False
+ return ret
class TorLimiter:

File Metadata

Mime Type
text/plain
Expires
Tue, May 20, 21:48 (10 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5863905
Default Alt Text
D14287.id41515.diff (1 KB)

Event Timeline