A working subset of #1788 #1875

Merged
g1itch merged 5 commits from compat-short into v0.6 2021-11-11 15:12:34 +01:00
Showing only changes of commit 8a5d90f200 - Show all commits

View File

@ -284,7 +284,7 @@ def isProofOfWorkSufficient(
# Packet creation # Packet creation
def CreatePacket(command, payload=''): def CreatePacket(command, payload=b''):
"""Construct and return a packet""" """Construct and return a packet"""
payload_length = len(payload) payload_length = len(payload)
checksum = hashlib.sha512(payload).digest()[0:4] checksum = hashlib.sha512(payload).digest()[0:4]
@ -302,7 +302,7 @@ def assembleVersionMessage(
Construct the payload of a version message, Construct the payload of a version message,
return the resulting bytes of running `CreatePacket` on it return the resulting bytes of running `CreatePacket` on it
""" """
payload = '' payload = b''
payload += pack('>L', 3) # protocol version. payload += pack('>L', 3) # protocol version.
# bitflags of the services I offer. # bitflags of the services I offer.
payload += pack( payload += pack(
@ -337,7 +337,7 @@ def assembleVersionMessage(
) )
# = 127.0.0.1. This will be ignored by the remote host. # = 127.0.0.1. This will be ignored by the remote host.
# The actual remote connected IP will be used. # The actual remote connected IP will be used.
payload += '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF' + pack( payload += b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF' + pack(
'>L', 2130706433) '>L', 2130706433)
# we have a separate extPort and incoming over clearnet # we have a separate extPort and incoming over clearnet
# or outgoing through clearnet # or outgoing through clearnet
@ -359,7 +359,7 @@ def assembleVersionMessage(
payload += nodeid[0:8] payload += nodeid[0:8]
else: else:
payload += eightBytesOfRandomDataUsedToDetectConnectionsToSelf payload += eightBytesOfRandomDataUsedToDetectConnectionsToSelf
userAgent = '/PyBitmessage:' + softwareVersion + '/' userAgent = ('/PyBitmessage:%s/' % softwareVersion).encode('utf-8')
payload += encodeVarint(len(userAgent)) payload += encodeVarint(len(userAgent))
payload += userAgent payload += userAgent
@ -373,7 +373,7 @@ def assembleVersionMessage(
if count >= 160000: if count >= 160000:
break break
return CreatePacket('version', payload) return CreatePacket(b'version', payload)
def assembleErrorMessage(fatal=0, banTime=0, inventoryVector='', errorText=''): def assembleErrorMessage(fatal=0, banTime=0, inventoryVector='', errorText=''):
@ -387,7 +387,7 @@ def assembleErrorMessage(fatal=0, banTime=0, inventoryVector='', errorText=''):
payload += inventoryVector payload += inventoryVector
payload += encodeVarint(len(errorText)) payload += encodeVarint(len(errorText))
payload += errorText payload += errorText
return CreatePacket('error', payload) return CreatePacket(b'error', payload)
# Packet decoding # Packet decoding