Skip to content

Commit b4bee4b

Browse files
committed
test: add keep_alive option to socks5 proxy in test_framework
The Socks5 server we use in the test framework would disconnect by default immediately after the handshake and sometimes would not register as a connected peer by bitcoind.
1 parent 5aaf988 commit b4bee4b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Diff for: test/functional/test_framework/socks5.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def __init__(self):
4040
self.af = socket.AF_INET # Bind address family
4141
self.unauth = False # Support unauthenticated
4242
self.auth = False # Support authentication
43+
self.keep_alive = False # Do not automatically close connections
4344

4445
class Socks5Command():
4546
"""Information about an incoming socks5 command."""
@@ -115,13 +116,14 @@ def handle(self):
115116

116117
cmdin = Socks5Command(cmd, atyp, addr, port, username, password)
117118
self.serv.queue.put(cmdin)
118-
logger.info('Proxy: %s', cmdin)
119+
logger.debug('Proxy: %s', cmdin)
119120
# Fall through to disconnect
120121
except Exception as e:
121122
logger.exception("socks5 request handling failed.")
122123
self.serv.queue.put(e)
123124
finally:
124-
self.conn.close()
125+
if not self.serv.keep_alive:
126+
self.conn.close()
125127

126128
class Socks5Server():
127129
def __init__(self, conf):
@@ -133,6 +135,7 @@ def __init__(self, conf):
133135
self.running = False
134136
self.thread = None
135137
self.queue = queue.Queue() # report connections and exceptions to client
138+
self.keep_alive = conf.keep_alive
136139

137140
def run(self):
138141
while self.running:
@@ -157,4 +160,3 @@ def stop(self):
157160
s.connect(self.conf.addr)
158161
s.close()
159162
self.thread.join()
160-

0 commit comments

Comments
 (0)