Skip to content

Commit

Permalink
test: make python p2p not send getaddr messages when it's being conne…
Browse files Browse the repository at this point in the history
…cted 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.
  • Loading branch information
mzumsande committed Oct 10, 2023
1 parent 04265ba commit 88c33c6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test/functional/test_framework/p2p.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,8 @@ def on_version(self, message):
self.send_message(msg_verack())
self.nServices = message.nServices
self.relay = message.relay
self.send_message(msg_getaddr())
if self.p2p_connected_to_node:
self.send_message(msg_getaddr())

# Connection helper methods

Expand Down
2 changes: 2 additions & 0 deletions test/functional/test_framework/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ def add_p2p_connection(self, p2p_conn, *, wait_for_verack=True, **kwargs):
if 'dstaddr' not in kwargs:
kwargs['dstaddr'] = '127.0.0.1'

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

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

if connection_type == "feeler":
Expand Down

0 comments on commit 88c33c6

Please sign in to comment.