mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
[tests] Move version message sending from NodeConn to NodeConnCB
This commit moves the logic that sends a version message on connection from NodeConn to NodeConnCB. NodeConn should not be aware of the semantics or meaning of the P2P payloads.
This commit is contained in:
parent
dad596fc37
commit
e9dfa9bccc
@ -75,7 +75,7 @@ class NodeConn(asyncore.dispatcher):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(map=mininode_socket_map)
|
super().__init__(map=mininode_socket_map)
|
||||||
|
|
||||||
def peer_connect(self, dstaddr, dstport, net="regtest", services=NODE_NETWORK|NODE_WITNESS, send_version=True):
|
def peer_connect(self, dstaddr, dstport, net="regtest"):
|
||||||
self.dstaddr = dstaddr
|
self.dstaddr = dstaddr
|
||||||
self.dstport = dstport
|
self.dstport = dstport
|
||||||
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
|
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
@ -86,16 +86,6 @@ class NodeConn(asyncore.dispatcher):
|
|||||||
self.network = net
|
self.network = net
|
||||||
self.disconnect = False
|
self.disconnect = False
|
||||||
|
|
||||||
if send_version:
|
|
||||||
# stuff version msg into sendbuf
|
|
||||||
vt = msg_version()
|
|
||||||
vt.nServices = services
|
|
||||||
vt.addrTo.ip = self.dstaddr
|
|
||||||
vt.addrTo.port = self.dstport
|
|
||||||
vt.addrFrom.ip = "0.0.0.0"
|
|
||||||
vt.addrFrom.port = 0
|
|
||||||
self.send_message(vt, True)
|
|
||||||
|
|
||||||
logger.info('Connecting to Bitcoin Node: %s:%d' % (self.dstaddr, self.dstport))
|
logger.info('Connecting to Bitcoin Node: %s:%d' % (self.dstaddr, self.dstport))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -279,6 +269,19 @@ class NodeConnCB(NodeConn):
|
|||||||
# The network services received from the peer
|
# The network services received from the peer
|
||||||
self.nServices = 0
|
self.nServices = 0
|
||||||
|
|
||||||
|
def peer_connect(self, *args, services=NODE_NETWORK|NODE_WITNESS, send_version=True, **kwargs):
|
||||||
|
super().peer_connect(*args, **kwargs)
|
||||||
|
|
||||||
|
if send_version:
|
||||||
|
# Send a version msg
|
||||||
|
vt = msg_version()
|
||||||
|
vt.nServices = services
|
||||||
|
vt.addrTo.ip = self.dstaddr
|
||||||
|
vt.addrTo.port = self.dstport
|
||||||
|
vt.addrFrom.ip = "0.0.0.0"
|
||||||
|
vt.addrFrom.port = 0
|
||||||
|
self.send_message(vt, True)
|
||||||
|
|
||||||
# Message receiving methods
|
# Message receiving methods
|
||||||
|
|
||||||
def on_message(self, message):
|
def on_message(self, message):
|
||||||
|
Loading…
Reference in New Issue
Block a user