Skip to content

Commit 88c33c6

Browse files
committed
test: make python p2p not send getaddr messages when it's being connected to
Bitcoind nodes send getaddr msgs only to outbound nodes (and ignore those received by outgoing connections). The python p2p node should mirror this behavior by not sending a getaddr message when it is not the initiator of the connection.
1 parent 04265ba commit 88c33c6

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

test/functional/test_framework/p2p.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,8 @@ def on_version(self, message):
456456
self.send_message(msg_verack())
457457
self.nServices = message.nServices
458458
self.relay = message.relay
459-
self.send_message(msg_getaddr())
459+
if self.p2p_connected_to_node:
460+
self.send_message(msg_getaddr())
460461

461462
# Connection helper methods
462463

test/functional/test_framework/test_node.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ def add_p2p_connection(self, p2p_conn, *, wait_for_verack=True, **kwargs):
646646
if 'dstaddr' not in kwargs:
647647
kwargs['dstaddr'] = '127.0.0.1'
648648

649+
p2p_conn.p2p_connected_to_node = True
649650
p2p_conn.peer_connect(**kwargs, net=self.chain, timeout_factor=self.timeout_factor)()
650651
self.p2ps.append(p2p_conn)
651652
p2p_conn.wait_until(lambda: p2p_conn.is_connected, check_connected=False)
@@ -691,6 +692,7 @@ def addconnection_callback(address, port):
691692
self.log.debug("Connecting to %s:%d %s" % (address, port, connection_type))
692693
self.addconnection('%s:%d' % (address, port), connection_type)
693694

695+
p2p_conn.p2p_connected_to_node = False
694696
p2p_conn.peer_accept_connection(connect_cb=addconnection_callback, connect_id=p2p_idx + 1, net=self.chain, timeout_factor=self.timeout_factor, **kwargs)()
695697

696698
if connection_type == "feeler":

0 commit comments

Comments
 (0)