|
1 | 1 | #!/usr/bin/env python3
|
2 |
| -# Copyright (c) 2020-2021 The Bitcoin Core developers |
| 2 | +# Copyright (c) 2020-present The Bitcoin Core developers |
3 | 3 | # Distributed under the MIT software license, see the accompanying
|
4 | 4 | # file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
5 | 5 | """Test add_outbound_p2p_connection test framework functionality"""
|
|
11 | 11 | check_node_connections,
|
12 | 12 | )
|
13 | 13 |
|
| 14 | + |
| 15 | +class VersionSender(P2PInterface): |
| 16 | + def on_open(self): |
| 17 | + assert self.on_connection_send_msg is not None |
| 18 | + self.send_version() |
| 19 | + assert self.on_connection_send_msg is None |
| 20 | + |
| 21 | + |
14 | 22 | class P2PFeelerReceiver(P2PInterface):
|
15 | 23 | def on_version(self, message):
|
16 | 24 | # The bitcoind node closes feeler connections as soon as a version
|
@@ -106,5 +114,19 @@ def run_test(self):
|
106 | 114 | # Feeler connections do not request tx relay
|
107 | 115 | assert_equal(feeler_conn.last_message["version"].relay, 0)
|
108 | 116 |
|
| 117 | + self.log.info("Send version message early to node") |
| 118 | + # Normally the test framework would be shy and send the version message |
| 119 | + # only after it received one. See the on_version method. Check that |
| 120 | + # bitcoind behaves properly when a version is sent unexpectedly (but |
| 121 | + # tolerably) early. |
| 122 | + # |
| 123 | + # This checks that bitcoind sends its own version prior to processing |
| 124 | + # the remote version (and replying with a verack). Otherwise it would |
| 125 | + # be violating its own rules, such as "non-version message before |
| 126 | + # version handshake". |
| 127 | + ver_conn = self.nodes[0].add_outbound_p2p_connection(VersionSender(), p2p_idx=6, connection_type="outbound-full-relay", supports_v2_p2p=False, advertise_v2_p2p=False) |
| 128 | + ver_conn.sync_with_ping() |
| 129 | + |
| 130 | + |
109 | 131 | if __name__ == '__main__':
|
110 | 132 | P2PAddConnections().main()
|
0 commit comments