mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-06 16:34:22 +01:00
[test] Build v2 P2P messages
This commit is contained in:
parent
bb7bffed79
commit
a94e350ac0
1 changed files with 20 additions and 9 deletions
|
@ -82,6 +82,7 @@ from test_framework.util import (
|
||||||
)
|
)
|
||||||
from test_framework.v2_p2p import (
|
from test_framework.v2_p2p import (
|
||||||
EncryptedP2PState,
|
EncryptedP2PState,
|
||||||
|
MSGTYPE_TO_SHORTID,
|
||||||
SHORTID,
|
SHORTID,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -386,6 +387,16 @@ class P2PConnection(asyncio.Protocol):
|
||||||
"""Build a serialized P2P message"""
|
"""Build a serialized P2P message"""
|
||||||
msgtype = message.msgtype
|
msgtype = message.msgtype
|
||||||
data = message.serialize()
|
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 = self.magic_bytes
|
||||||
tmsg += msgtype
|
tmsg += msgtype
|
||||||
tmsg += b"\x00" * (12 - len(msgtype))
|
tmsg += b"\x00" * (12 - len(msgtype))
|
||||||
|
|
Loading…
Add table
Reference in a new issue