37
37
from test_framework .siphash import siphash256
38
38
from test_framework .util import hex_str_to_bytes , bytes_to_hex_str , wait_until
39
39
40
+ MIN_VERSION_SUPPORTED = 60001
40
41
MY_VERSION = 70014 # past bip-31 for ping/pong
41
42
MY_SUBVERSION = b"/python-mininode-tester:0.0.3/"
42
43
MY_RELAY = 1 # from version 70001 onwards, fRelay should be appended to version messages (BIP37)
@@ -1423,11 +1424,8 @@ def on_verack(self, conn, message):
1423
1424
self .verack_received = True
1424
1425
1425
1426
def on_version (self , conn , message ):
1426
- if message .nVersion >= 209 :
1427
- conn .send_message (msg_verack ())
1428
- conn .ver_send = min (MY_VERSION , message .nVersion )
1429
- if message .nVersion < 209 :
1430
- conn .ver_recv = conn .ver_send
1427
+ assert message .nVersion >= MIN_VERSION_SUPPORTED , "Version {} received. Test framework only supports versions greater than {}" .format (message .nVersion , MIN_VERSION_SUPPORTED )
1428
+ conn .send_message (msg_verack ())
1431
1429
conn .nServices = message .nServices
1432
1430
1433
1431
# Connection helper methods
@@ -1609,40 +1607,27 @@ def got_data(self):
1609
1607
return
1610
1608
if self .recvbuf [:4 ] != self .MAGIC_BYTES [self .network ]:
1611
1609
raise ValueError ("got garbage %s" % repr (self .recvbuf ))
1612
- if self .ver_recv < 209 :
1613
- if len (self .recvbuf ) < 4 + 12 + 4 :
1614
- return
1615
- command = self .recvbuf [4 :4 + 12 ].split (b"\x00 " , 1 )[0 ]
1616
- msglen = struct .unpack ("<i" , self .recvbuf [4 + 12 :4 + 12 + 4 ])[0 ]
1617
- checksum = None
1618
- if len (self .recvbuf ) < 4 + 12 + 4 + msglen :
1619
- return
1620
- msg = self .recvbuf [4 + 12 + 4 :4 + 12 + 4 + msglen ]
1621
- self .recvbuf = self .recvbuf [4 + 12 + 4 + msglen :]
1622
- else :
1623
- if len (self .recvbuf ) < 4 + 12 + 4 + 4 :
1624
- return
1625
- command = self .recvbuf [4 :4 + 12 ].split (b"\x00 " , 1 )[0 ]
1626
- msglen = struct .unpack ("<i" , self .recvbuf [4 + 12 :4 + 12 + 4 ])[0 ]
1627
- checksum = self .recvbuf [4 + 12 + 4 :4 + 12 + 4 + 4 ]
1628
- if len (self .recvbuf ) < 4 + 12 + 4 + 4 + msglen :
1629
- return
1630
- msg = self .recvbuf [4 + 12 + 4 + 4 :4 + 12 + 4 + 4 + msglen ]
1631
- th = sha256 (msg )
1632
- h = sha256 (th )
1633
- if checksum != h [:4 ]:
1634
- raise ValueError ("got bad checksum " + repr (self .recvbuf ))
1635
- self .recvbuf = self .recvbuf [4 + 12 + 4 + 4 + msglen :]
1636
- if command in self .messagemap :
1637
- f = BytesIO (msg )
1638
- t = self .messagemap [command ]()
1639
- t .deserialize (f )
1640
- self .got_message (t )
1641
- else :
1642
- logger .warning ("Received unknown command from %s:%d: '%s' %s" % (self .dstaddr , self .dstport , command , repr (msg )))
1643
- raise ValueError ("Unknown command: '%s'" % (command ))
1610
+ if len (self .recvbuf ) < 4 + 12 + 4 + 4 :
1611
+ return
1612
+ command = self .recvbuf [4 :4 + 12 ].split (b"\x00 " , 1 )[0 ]
1613
+ msglen = struct .unpack ("<i" , self .recvbuf [4 + 12 :4 + 12 + 4 ])[0 ]
1614
+ checksum = self .recvbuf [4 + 12 + 4 :4 + 12 + 4 + 4 ]
1615
+ if len (self .recvbuf ) < 4 + 12 + 4 + 4 + msglen :
1616
+ return
1617
+ msg = self .recvbuf [4 + 12 + 4 + 4 :4 + 12 + 4 + 4 + msglen ]
1618
+ th = sha256 (msg )
1619
+ h = sha256 (th )
1620
+ if checksum != h [:4 ]:
1621
+ raise ValueError ("got bad checksum " + repr (self .recvbuf ))
1622
+ self .recvbuf = self .recvbuf [4 + 12 + 4 + 4 + msglen :]
1623
+ if command not in self .messagemap :
1624
+ raise ValueError ("Received unknown command from %s:%d: '%s' %s" % (self .dstaddr , self .dstport , command , repr (msg )))
1625
+ f = BytesIO (msg )
1626
+ t = self .messagemap [command ]()
1627
+ t .deserialize (f )
1628
+ self .got_message (t )
1644
1629
except Exception as e :
1645
- logger .exception ('got_data :' , repr (e ))
1630
+ logger .exception ('Error reading message :' , repr (e ))
1646
1631
raise
1647
1632
1648
1633
def send_message (self , message , pushbuf = False ):
@@ -1655,10 +1640,9 @@ def send_message(self, message, pushbuf=False):
1655
1640
tmsg += command
1656
1641
tmsg += b"\x00 " * (12 - len (command ))
1657
1642
tmsg += struct .pack ("<I" , len (data ))
1658
- if self .ver_send >= 209 :
1659
- th = sha256 (data )
1660
- h = sha256 (th )
1661
- tmsg += h [:4 ]
1643
+ th = sha256 (data )
1644
+ h = sha256 (th )
1645
+ tmsg += h [:4 ]
1662
1646
tmsg += data
1663
1647
with mininode_lock :
1664
1648
if (len (self .sendbuf ) == 0 and not pushbuf ):
0 commit comments