mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-14 11:26:09 -05:00
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.
This commit is contained in:
parent
5aaf988ccc
commit
b4bee4bbf4
1 changed files with 5 additions and 3 deletions
|
@ -40,6 +40,7 @@ class Socks5Configuration():
|
||||||
self.af = socket.AF_INET # Bind address family
|
self.af = socket.AF_INET # Bind address family
|
||||||
self.unauth = False # Support unauthenticated
|
self.unauth = False # Support unauthenticated
|
||||||
self.auth = False # Support authentication
|
self.auth = False # Support authentication
|
||||||
|
self.keep_alive = False # Do not automatically close connections
|
||||||
|
|
||||||
class Socks5Command():
|
class Socks5Command():
|
||||||
"""Information about an incoming socks5 command."""
|
"""Information about an incoming socks5 command."""
|
||||||
|
@ -115,13 +116,14 @@ class Socks5Connection():
|
||||||
|
|
||||||
cmdin = Socks5Command(cmd, atyp, addr, port, username, password)
|
cmdin = Socks5Command(cmd, atyp, addr, port, username, password)
|
||||||
self.serv.queue.put(cmdin)
|
self.serv.queue.put(cmdin)
|
||||||
logger.info('Proxy: %s', cmdin)
|
logger.debug('Proxy: %s', cmdin)
|
||||||
# Fall through to disconnect
|
# Fall through to disconnect
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception("socks5 request handling failed.")
|
logger.exception("socks5 request handling failed.")
|
||||||
self.serv.queue.put(e)
|
self.serv.queue.put(e)
|
||||||
finally:
|
finally:
|
||||||
self.conn.close()
|
if not self.serv.keep_alive:
|
||||||
|
self.conn.close()
|
||||||
|
|
||||||
class Socks5Server():
|
class Socks5Server():
|
||||||
def __init__(self, conf):
|
def __init__(self, conf):
|
||||||
|
@ -133,6 +135,7 @@ class Socks5Server():
|
||||||
self.running = False
|
self.running = False
|
||||||
self.thread = None
|
self.thread = None
|
||||||
self.queue = queue.Queue() # report connections and exceptions to client
|
self.queue = queue.Queue() # report connections and exceptions to client
|
||||||
|
self.keep_alive = conf.keep_alive
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while self.running:
|
while self.running:
|
||||||
|
@ -157,4 +160,3 @@ class Socks5Server():
|
||||||
s.connect(self.conf.addr)
|
s.connect(self.conf.addr)
|
||||||
s.close()
|
s.close()
|
||||||
self.thread.join()
|
self.thread.join()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue