mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-04 10:12:28 +02:00
[test] Add testing for outbound feeler connections
Extend the addconnection RPC method to allow creating outbound feeler connections. Extend the test framework to accept those feeler connections.
This commit is contained in:
@@ -14,6 +14,13 @@ def check_node_connections(*, node, num_in, num_out):
|
||||
assert_equal(info["connections_in"], num_in)
|
||||
assert_equal(info["connections_out"], num_out)
|
||||
|
||||
class P2PFeelerReceiver(P2PInterface):
|
||||
def on_version(self, message):
|
||||
# The bitcoind node closes feeler connections as soon as a version
|
||||
# message is received from the test framework. Don't send any responses
|
||||
# to the node's version message since the connection will already be
|
||||
# closed.
|
||||
pass
|
||||
|
||||
class P2PAddConnections(BitcoinTestFramework):
|
||||
def set_test_params(self):
|
||||
@@ -91,6 +98,14 @@ class P2PAddConnections(BitcoinTestFramework):
|
||||
|
||||
check_node_connections(node=self.nodes[1], num_in=5, num_out=10)
|
||||
|
||||
self.log.info("Add 1 feeler connection to node 0")
|
||||
feeler_conn = self.nodes[0].add_outbound_p2p_connection(P2PFeelerReceiver(), p2p_idx=6, connection_type="feeler")
|
||||
|
||||
# Feeler connection is closed
|
||||
assert not feeler_conn.is_connected
|
||||
|
||||
# Verify version message received
|
||||
assert_equal(feeler_conn.message_count["version"], 1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
P2PAddConnections().main()
|
||||
|
||||
@@ -558,7 +558,7 @@ class TestNode():
|
||||
|
||||
def add_outbound_p2p_connection(self, p2p_conn, *, p2p_idx, connection_type="outbound-full-relay", **kwargs):
|
||||
"""Add an outbound p2p connection from node. Must be an
|
||||
"outbound-full-relay", "block-relay-only" or "addr-fetch" connection.
|
||||
"outbound-full-relay", "block-relay-only", "addr-fetch" or "feeler" connection.
|
||||
|
||||
This method adds the p2p connection to the self.p2ps list and returns
|
||||
the connection to the caller.
|
||||
@@ -570,11 +570,16 @@ class TestNode():
|
||||
|
||||
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.wait_for_connect()
|
||||
self.p2ps.append(p2p_conn)
|
||||
if connection_type == "feeler":
|
||||
# feeler connections are closed as soon as the node receives a `version` message
|
||||
p2p_conn.wait_until(lambda: p2p_conn.message_count["version"] == 1, check_connected=False)
|
||||
p2p_conn.wait_until(lambda: not p2p_conn.is_connected, check_connected=False)
|
||||
else:
|
||||
p2p_conn.wait_for_connect()
|
||||
self.p2ps.append(p2p_conn)
|
||||
|
||||
p2p_conn.wait_for_verack()
|
||||
p2p_conn.sync_with_ping()
|
||||
p2p_conn.wait_for_verack()
|
||||
p2p_conn.sync_with_ping()
|
||||
|
||||
return p2p_conn
|
||||
|
||||
|
||||
Reference in New Issue
Block a user