From 5b91fb14aba7d7fe45c9ac364526815bec742356 Mon Sep 17 00:00:00 2001 From: stratospher <44024636+stratospher@users.noreply.github.com> Date: Sun, 11 Dec 2022 00:22:20 +0530 Subject: [PATCH] [test] Read v2 P2P messages --- test/functional/test_framework/p2p.py | 58 +++++++++++++++++++-------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/test/functional/test_framework/p2p.py b/test/functional/test_framework/p2p.py index 308cefdbc27..27f921702cf 100755 --- a/test/functional/test_framework/p2p.py +++ b/test/functional/test_framework/p2p.py @@ -82,6 +82,7 @@ from test_framework.util import ( ) from test_framework.v2_p2p import ( EncryptedP2PState, + SHORTID, ) logger = logging.getLogger("TestFramework.p2p") @@ -297,23 +298,46 @@ class P2PConnection(asyncio.Protocol): the on_message callback for processing.""" try: while True: - if len(self.recvbuf) < 4: - return - if self.recvbuf[:4] != self.magic_bytes: - raise ValueError("magic bytes mismatch: {} != {}".format(repr(self.magic_bytes), repr(self.recvbuf))) - if len(self.recvbuf) < 4 + 12 + 4 + 4: - return - msgtype = self.recvbuf[4:4+12].split(b"\x00", 1)[0] - msglen = struct.unpack("