Fix mininode version message format

pull/8894/head
jnewbery 8 years ago committed by John Newbery
parent ed64bcec2d
commit e5d682faa3

@ -41,6 +41,7 @@ from test_framework.siphash import siphash256
BIP0031_VERSION = 60000 BIP0031_VERSION = 60000
MY_VERSION = 70014 # past bip-31 for ping/pong MY_VERSION = 70014 # past bip-31 for ping/pong
MY_SUBVERSION = b"/python-mininode-tester:0.0.3/" MY_SUBVERSION = b"/python-mininode-tester:0.0.3/"
MY_RELAY = 1 # from version 70001 onwards, fRelay should be appended to version messages (BIP37)
MAX_INV_SZ = 50000 MAX_INV_SZ = 50000
MAX_BLOCK_SIZE = 1000000 MAX_BLOCK_SIZE = 1000000
@ -951,6 +952,7 @@ class msg_version(object):
self.nNonce = random.getrandbits(64) self.nNonce = random.getrandbits(64)
self.strSubVer = MY_SUBVERSION self.strSubVer = MY_SUBVERSION
self.nStartingHeight = -1 self.nStartingHeight = -1
self.nRelay = MY_RELAY
def deserialize(self, f): def deserialize(self, f):
self.nVersion = struct.unpack("<i", f.read(4))[0] self.nVersion = struct.unpack("<i", f.read(4))[0]
@ -960,21 +962,32 @@ class msg_version(object):
self.nTime = struct.unpack("<q", f.read(8))[0] self.nTime = struct.unpack("<q", f.read(8))[0]
self.addrTo = CAddress() self.addrTo = CAddress()
self.addrTo.deserialize(f) self.addrTo.deserialize(f)
if self.nVersion >= 106: if self.nVersion >= 106:
self.addrFrom = CAddress() self.addrFrom = CAddress()
self.addrFrom.deserialize(f) self.addrFrom.deserialize(f)
self.nNonce = struct.unpack("<Q", f.read(8))[0] self.nNonce = struct.unpack("<Q", f.read(8))[0]
self.strSubVer = deser_string(f) self.strSubVer = deser_string(f)
if self.nVersion >= 209:
self.nStartingHeight = struct.unpack("<i", f.read(4))[0]
else:
self.nStartingHeight = None
else: else:
self.addrFrom = None self.addrFrom = None
self.nNonce = None self.nNonce = None
self.strSubVer = None self.strSubVer = None
self.nStartingHeight = None self.nStartingHeight = None
if self.nVersion >= 209:
self.nStartingHeight = struct.unpack("<i", f.read(4))[0]
else:
self.nStartingHeight = None
if self.nVersion >= 70001:
# Relay field is optional for version 70001 onwards
try:
self.nRelay = struct.unpack("<b", f.read(1))[0]
except:
self.nRelay = 0
else:
self.nRelay = 0
def serialize(self): def serialize(self):
r = b"" r = b""
r += struct.pack("<i", self.nVersion) r += struct.pack("<i", self.nVersion)
@ -985,13 +998,14 @@ class msg_version(object):
r += struct.pack("<Q", self.nNonce) r += struct.pack("<Q", self.nNonce)
r += ser_string(self.strSubVer) r += ser_string(self.strSubVer)
r += struct.pack("<i", self.nStartingHeight) r += struct.pack("<i", self.nStartingHeight)
r += struct.pack("<b", self.nRelay)
return r return r
def __repr__(self): def __repr__(self):
return 'msg_version(nVersion=%i nServices=%i nTime=%s addrTo=%s addrFrom=%s nNonce=0x%016X strSubVer=%s nStartingHeight=%i)' \ return 'msg_version(nVersion=%i nServices=%i nTime=%s addrTo=%s addrFrom=%s nNonce=0x%016X strSubVer=%s nStartingHeight=%i nRelay=%i)' \
% (self.nVersion, self.nServices, time.ctime(self.nTime), % (self.nVersion, self.nServices, time.ctime(self.nTime),
repr(self.addrTo), repr(self.addrFrom), self.nNonce, repr(self.addrTo), repr(self.addrFrom), self.nNonce,
self.strSubVer, self.nStartingHeight) self.strSubVer, self.nStartingHeight, self.nRelay)
class msg_verack(object): class msg_verack(object):

Loading…
Cancel
Save