[test] Build v2 P2P messages

This commit is contained in:
stratospher 2022-02-05 23:28:02 +05:30
parent bb7bffed79
commit a94e350ac0

View file

@ -82,6 +82,7 @@ from test_framework.util import (
)
from test_framework.v2_p2p import (
EncryptedP2PState,
MSGTYPE_TO_SHORTID,
SHORTID,
)
@ -386,6 +387,16 @@ class P2PConnection(asyncio.Protocol):
"""Build a serialized P2P message"""
msgtype = message.msgtype
data = message.serialize()
if self.supports_v2_p2p:
if msgtype in SHORTID.values():
tmsg = MSGTYPE_TO_SHORTID.get(msgtype).to_bytes(1, 'big')
else:
tmsg = b"\x00"
tmsg += msgtype
tmsg += b"\x00" * (12 - len(msgtype))
tmsg += data
return self.v2_state.v2_enc_packet(tmsg)
else:
tmsg = self.magic_bytes
tmsg += msgtype
tmsg += b"\x00" * (12 - len(msgtype))