ignore trailing payload data in bitcoin p2p messages
authorForrest Voight <forrest@forre.st>
Thu, 27 Jun 2013 15:24:15 +0000 (11:24 -0400)
committerForrest Voight <forrest@forre.st>
Thu, 27 Jun 2013 15:24:29 +0000 (11:24 -0400)
p2pool/bitcoin/p2p.py
p2pool/util/p2protocol.py
p2pool/util/pack.py

index fd403f1..cdb98de 100644 (file)
@@ -14,7 +14,7 @@ from p2pool.util import deferral, p2protocol, pack, variable
 
 class Protocol(p2protocol.Protocol):
     def __init__(self, net):
-        p2protocol.Protocol.__init__(self, net.P2P_PREFIX, 1000000)
+        p2protocol.Protocol.__init__(self, net.P2P_PREFIX, 1000000, ignore_trailing_payload=True)
     
     def connectionMade(self):
         self.send_version(
index 8255886..71d56ea 100644 (file)
@@ -15,11 +15,12 @@ class TooLong(Exception):
     pass
 
 class Protocol(protocol.Protocol):
-    def __init__(self, message_prefix, max_payload_length, traffic_happened=variable.Event()):
+    def __init__(self, message_prefix, max_payload_length, traffic_happened=variable.Event(), ignore_trailing_payload=False):
         self._message_prefix = message_prefix
         self._max_payload_length = max_payload_length
         self.dataReceived2 = datachunker.DataChunker(self.dataReceiver())
         self.traffic_happened = traffic_happened
+        self.ignore_trailing_payload = ignore_trailing_payload
     
     def dataReceived(self, data):
         self.traffic_happened.happened('p2p/in', len(data))
@@ -51,7 +52,7 @@ class Protocol(protocol.Protocol):
                 continue
             
             try:
-                self.packetReceived(command, type_.unpack(payload))
+                self.packetReceived(command, type_.unpack(payload, self.ignore_trailing_payload))
             except:
                 print 'RECV', command, payload[:100].encode('hex') + ('...' if len(payload) > 100 else '')
                 log.err(None, 'Error handling message: (see RECV line)')
index c768258..1ed2629 100644 (file)
@@ -38,12 +38,12 @@ class Type(object):
     def __ne__(self, other):
         return not (self == other)
     
-    def _unpack(self, data):
+    def _unpack(self, data, ignore_trailing=False):
         obj, (data2, pos) = self.read((data, 0))
         
         assert data2 is data
         
-        if pos != len(data):
+        if pos != len(data) and not ignore_trailing:
             raise LateEnd()
         
         return obj
@@ -59,8 +59,8 @@ class Type(object):
         return ''.join(res)
     
     
-    def unpack(self, data):
-        obj = self._unpack(data)
+    def unpack(self, data, ignore_trailing=False):
+        obj = self._unpack(data, ignore_trailing)
         
         if p2pool.DEBUG:
             if self._pack(obj) != data: