mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 15:04:44 +01:00
Merge bitcoin/bitcoin#28632: test: make python p2p not send getaddr on incoming connections
9cfc1c9440
test: check that we don't send a getaddr msg to an inbound peer (Martin Zumsande)88c33c6748
test: make python p2p not send getaddr messages when it's being connected to (Martin Zumsande) Pull request description: `bitcoind` nodes send `getaddr` messages only to outbound nodes (and ignore `getaddr` 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. This is currently causing several unnecessary messages being sent and then ignored (`Ignoring "getaddr" from outbound-full-relay connection.`) in tests like `p2p_add_connections.py`. ACKs for top commit: pinheadmz: concept ACK9cfc1c9440
pablomartin4btc: re ACK9cfc1c9440
BrandonOdiwuor: re ACK9cfc1c9440
Tree-SHA512: 812bec5d8a4828b4384d4cdd4362d6eec09acb2363e888f2b3e3bf8b925e0e17f15e13dc297d6b616c68b93ace9ede7245b07b405d3f5f8eada98350f74230dc
This commit is contained in:
commit
eca2e430ac
3 changed files with 7 additions and 3 deletions
|
@ -270,15 +270,16 @@ class AddrTest(BitcoinTestFramework):
|
||||||
full_outbound_peer.sync_with_ping()
|
full_outbound_peer.sync_with_ping()
|
||||||
assert full_outbound_peer.getaddr_received()
|
assert full_outbound_peer.getaddr_received()
|
||||||
|
|
||||||
self.log.info('Check that we do not send a getaddr message upon connecting to a block-relay-only peer')
|
self.log.info('Check that we do not send a getaddr message to a block-relay-only or inbound peer')
|
||||||
block_relay_peer = self.nodes[0].add_outbound_p2p_connection(AddrReceiver(), p2p_idx=1, connection_type="block-relay-only")
|
block_relay_peer = self.nodes[0].add_outbound_p2p_connection(AddrReceiver(), p2p_idx=1, connection_type="block-relay-only")
|
||||||
block_relay_peer.sync_with_ping()
|
block_relay_peer.sync_with_ping()
|
||||||
assert_equal(block_relay_peer.getaddr_received(), False)
|
assert_equal(block_relay_peer.getaddr_received(), False)
|
||||||
|
|
||||||
self.log.info('Check that we answer getaddr messages only from inbound peers')
|
|
||||||
inbound_peer = self.nodes[0].add_p2p_connection(AddrReceiver(send_getaddr=False))
|
inbound_peer = self.nodes[0].add_p2p_connection(AddrReceiver(send_getaddr=False))
|
||||||
inbound_peer.sync_with_ping()
|
inbound_peer.sync_with_ping()
|
||||||
|
assert_equal(inbound_peer.getaddr_received(), False)
|
||||||
|
|
||||||
|
self.log.info('Check that we answer getaddr messages only from inbound peers')
|
||||||
# Add some addresses to addrman
|
# Add some addresses to addrman
|
||||||
for i in range(1000):
|
for i in range(1000):
|
||||||
first_octet = i >> 8
|
first_octet = i >> 8
|
||||||
|
|
|
@ -456,6 +456,7 @@ class P2PInterface(P2PConnection):
|
||||||
self.send_message(msg_verack())
|
self.send_message(msg_verack())
|
||||||
self.nServices = message.nServices
|
self.nServices = message.nServices
|
||||||
self.relay = message.relay
|
self.relay = message.relay
|
||||||
|
if self.p2p_connected_to_node:
|
||||||
self.send_message(msg_getaddr())
|
self.send_message(msg_getaddr())
|
||||||
|
|
||||||
# Connection helper methods
|
# Connection helper methods
|
||||||
|
|
|
@ -644,6 +644,7 @@ class TestNode():
|
||||||
if 'dstaddr' not in kwargs:
|
if 'dstaddr' not in kwargs:
|
||||||
kwargs['dstaddr'] = '127.0.0.1'
|
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)()
|
p2p_conn.peer_connect(**kwargs, net=self.chain, timeout_factor=self.timeout_factor)()
|
||||||
self.p2ps.append(p2p_conn)
|
self.p2ps.append(p2p_conn)
|
||||||
p2p_conn.wait_until(lambda: p2p_conn.is_connected, check_connected=False)
|
p2p_conn.wait_until(lambda: p2p_conn.is_connected, check_connected=False)
|
||||||
|
@ -689,6 +690,7 @@ class TestNode():
|
||||||
self.log.debug("Connecting to %s:%d %s" % (address, port, connection_type))
|
self.log.debug("Connecting to %s:%d %s" % (address, port, connection_type))
|
||||||
self.addconnection('%s:%d' % (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)()
|
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":
|
if connection_type == "feeler":
|
||||||
|
|
Loading…
Add table
Reference in a new issue