aboutsummaryrefslogtreecommitdiff
path: root/test/functional/test_framework
diff options
context:
space:
mode:
authorSebastian Falbesoner <sebastian.falbesoner@gmail.com>2024-01-30 02:59:01 +0100
committerSebastian Falbesoner <sebastian.falbesoner@gmail.com>2024-02-01 13:33:23 +0100
commitb198b9c2ce28463f7c6a2b4cf08d64138c8509ee (patch)
tree495cddf26bddf0385646e0ab56c4b341429225d6 /test/functional/test_framework
parentaa9231fafe45513134ec8953a217cda07446fae8 (diff)
downloadbitcoin-b198b9c2ce28463f7c6a2b4cf08d64138c8509ee.tar.xz
test: p2p: introduce helper for sending prepared VERSION message
This deduplicates code for sending out the VERSION message (if available and not sent yet), currently used at three different places: 1) in the `connection_made` asyncio callback (for v1 connections that are not v2 reconnects) 2) at the end of `v2_handshake`, if the v2 handshake succeeded 3) in the `on_version` callback, if a reconnection with v1 happens
Diffstat (limited to 'test/functional/test_framework')
-rwxr-xr-xtest/functional/test_framework/p2p.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/test/functional/test_framework/p2p.py b/test/functional/test_framework/p2p.py
index c113a4c8d8..783baf480d 100755
--- a/test/functional/test_framework/p2p.py
+++ b/test/functional/test_framework/p2p.py
@@ -226,9 +226,8 @@ class P2PConnection(asyncio.Protocol):
self.send_raw_message(send_handshake_bytes)
# if v2 connection, send `on_connection_send_msg` after initial v2 handshake.
# if reconnection situation, send `on_connection_send_msg` after version message is received in `on_version()`.
- if self.on_connection_send_msg and not self.supports_v2_p2p and not self.reconnect:
- self.send_message(self.on_connection_send_msg)
- self.on_connection_send_msg = None # Never used again
+ if not self.supports_v2_p2p and not self.reconnect:
+ self.send_version()
self.on_open()
def connection_lost(self, exc):
@@ -284,9 +283,8 @@ class P2PConnection(asyncio.Protocol):
if not is_mac_auth:
raise ValueError("invalid v2 mac tag in handshake authentication")
self.recvbuf = self.recvbuf[length:]
- if self.v2_state.tried_v2_handshake and self.on_connection_send_msg:
- self.send_message(self.on_connection_send_msg)
- self.on_connection_send_msg = None
+ if self.v2_state.tried_v2_handshake:
+ self.send_version()
# Socket read methods
@@ -559,9 +557,7 @@ class P2PInterface(P2PConnection):
assert message.nVersion >= MIN_P2P_VERSION_SUPPORTED, "Version {} received. Test framework only supports versions greater than {}".format(message.nVersion, MIN_P2P_VERSION_SUPPORTED)
# reconnection using v1 P2P has happened since version message can be processed, previously unsent version message is sent using v1 P2P here
if self.reconnect:
- if self.on_connection_send_msg:
- self.send_message(self.on_connection_send_msg)
- self.on_connection_send_msg = None
+ self.send_version()
self.reconnect = False
if message.nVersion >= 70016 and self.wtxidrelay:
self.send_message(msg_wtxidrelay())
@@ -676,6 +672,11 @@ class P2PInterface(P2PConnection):
# Message sending helper functions
+ def send_version(self):
+ if self.on_connection_send_msg:
+ self.send_message(self.on_connection_send_msg)
+ self.on_connection_send_msg = None # Never used again
+
def send_and_ping(self, message, timeout=60):
self.send_message(message)
self.sync_with_ping(timeout=timeout)