disconnect from peer when error parsing or processing packet
authorForrest Voight <forrest@forre.st>
Mon, 27 Feb 2012 00:10:12 +0000 (19:10 -0500)
committerForrest Voight <forrest@forre.st>
Mon, 27 Feb 2012 03:12:56 +0000 (22:12 -0500)
p2pool/bitcoin/p2p.py

index 0e66ffe..7312d3c 100644 (file)
@@ -50,13 +50,11 @@ class BaseProtocol(protocol.Protocol):
                 continue
             
             try:
-                payload2 = type_.unpack(payload)
+                self.packetReceived(command, type_.unpack(payload))
             except:
-                print 'RECV', command, repr(payload.encode('hex')), len(payload)
-                log.err(None, 'Error parsing message: (see RECV line)')
-                continue
-            
-            self.packetReceived(command, payload2)
+                print 'RECV', command, payload[:100].encode('hex') + ('...' if len(payload) > 100 else '')
+                log.err(None, 'Error handling message: (see RECV line)')
+                self.transport.loseConnection()
     
     def packetReceived(self, command, payload2):
         handler = getattr(self, 'handle_' + command, None)
@@ -65,11 +63,7 @@ class BaseProtocol(protocol.Protocol):
                 print 'no handler for', repr(command)
             return
         
-        try:
-            handler(**payload2)
-        except:
-            print 'RECV', command, repr(payload2)[:100]
-            log.err(None, 'Error handling message: (see RECV line)')
+        handler(**payload2)
     
     def sendPacket(self, command, payload2):
         if len(command) >= 12: