File tree Expand file tree Collapse file tree 1 file changed +20
-9
lines changed
test/functional/test_framework Expand file tree Collapse file tree 1 file changed +20
-9
lines changed Original file line number Diff line number Diff line change 82
82
)
83
83
from test_framework .v2_p2p import (
84
84
EncryptedP2PState ,
85
+ MSGTYPE_TO_SHORTID ,
85
86
SHORTID ,
86
87
)
87
88
@@ -386,15 +387,25 @@ def build_message(self, message):
386
387
"""Build a serialized P2P message"""
387
388
msgtype = message .msgtype
388
389
data = message .serialize ()
389
- tmsg = self .magic_bytes
390
- tmsg += msgtype
391
- tmsg += b"\x00 " * (12 - len (msgtype ))
392
- tmsg += struct .pack ("<I" , len (data ))
393
- th = sha256 (data )
394
- h = sha256 (th )
395
- tmsg += h [:4 ]
396
- tmsg += data
397
- return tmsg
390
+ if self .supports_v2_p2p :
391
+ if msgtype in SHORTID .values ():
392
+ tmsg = MSGTYPE_TO_SHORTID .get (msgtype ).to_bytes (1 , 'big' )
393
+ else :
394
+ tmsg = b"\x00 "
395
+ tmsg += msgtype
396
+ tmsg += b"\x00 " * (12 - len (msgtype ))
397
+ tmsg += data
398
+ return self .v2_state .v2_enc_packet (tmsg )
399
+ else :
400
+ tmsg = self .magic_bytes
401
+ tmsg += msgtype
402
+ tmsg += b"\x00 " * (12 - len (msgtype ))
403
+ tmsg += struct .pack ("<I" , len (data ))
404
+ th = sha256 (data )
405
+ h = sha256 (th )
406
+ tmsg += h [:4 ]
407
+ tmsg += data
408
+ return tmsg
398
409
399
410
def _log_message (self , direction , msg ):
400
411
"""Logs a message being sent or received over the connection."""
You can’t perform that action at this time.
0 commit comments