Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14864840
D14287.id41518.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
D14287.id41518.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Tue, May 20, 22:46 (4 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5863905
Default Alt Text
D14287.id41518.diff (1 KB)
Attached To
D14287: [electrum] always close the socket object in is_tor_port
Event Timeline
Log In to Comment