Browse Source

qa: mininode learns when a socket connects, not its first action

0.14
Matt Corallo 8 years ago committed by Cory Fields
parent
commit
5b5e4f8330
  1. 16
      qa/rpc-tests/test_framework/mininode.py

16
qa/rpc-tests/test_framework/mininode.py

@ -1614,7 +1614,7 @@ class NodeConn(asyncore.dispatcher):
"regtest": b"\xfa\xbf\xb5\xda", # regtest "regtest": b"\xfa\xbf\xb5\xda", # regtest
} }
def __init__(self, dstaddr, dstport, rpc, callback, net="regtest", services=NODE_NETWORK): def __init__(self, dstaddr, dstport, rpc, callback, net="regtest", services=NODE_NETWORK, send_version=True):
asyncore.dispatcher.__init__(self, map=mininode_socket_map) asyncore.dispatcher.__init__(self, map=mininode_socket_map)
self.log = logging.getLogger("NodeConn(%s:%d)" % (dstaddr, dstport)) self.log = logging.getLogger("NodeConn(%s:%d)" % (dstaddr, dstport))
self.dstaddr = dstaddr self.dstaddr = dstaddr
@ -1631,6 +1631,7 @@ class NodeConn(asyncore.dispatcher):
self.disconnect = False self.disconnect = False
self.nServices = 0 self.nServices = 0
if send_version:
# stuff version msg into sendbuf # stuff version msg into sendbuf
vt = msg_version() vt = msg_version()
vt.nServices = services vt.nServices = services
@ -1639,6 +1640,7 @@ class NodeConn(asyncore.dispatcher):
vt.addrFrom.ip = "0.0.0.0" vt.addrFrom.ip = "0.0.0.0"
vt.addrFrom.port = 0 vt.addrFrom.port = 0
self.send_message(vt, True) self.send_message(vt, True)
print('MiniNode: Connecting to Bitcoin Node IP # ' + dstaddr + ':' \ print('MiniNode: Connecting to Bitcoin Node IP # ' + dstaddr + ':' \
+ str(dstport)) + str(dstport))
@ -1652,6 +1654,7 @@ class NodeConn(asyncore.dispatcher):
self.log.debug(msg) self.log.debug(msg)
def handle_connect(self): def handle_connect(self):
if self.state != "connected":
self.show_debug_msg("MiniNode: Connected & Listening: \n") self.show_debug_msg("MiniNode: Connected & Listening: \n")
self.state = "connected" self.state = "connected"
@ -1681,11 +1684,20 @@ class NodeConn(asyncore.dispatcher):
def writable(self): def writable(self):
with mininode_lock: with mininode_lock:
pre_connection = self.state == "connecting"
length = len(self.sendbuf) length = len(self.sendbuf)
return (length > 0) return (length > 0 or pre_connection)
def handle_write(self): def handle_write(self):
with mininode_lock: with mininode_lock:
# asyncore does not expose socket connection, only the first read/write
# event, thus we must check connection manually here to know when we
# actually connect
if self.state == "connecting":
self.handle_connect()
if not self.writable():
return
try: try:
sent = self.send(self.sendbuf) sent = self.send(self.sendbuf)
except: except:

Loading…
Cancel
Save