made p2p timeout reset on received data instead of entire received message, so that...
authorForrest Voight <forrest@forre.st>
Sat, 4 Feb 2012 19:49:34 +0000 (14:49 -0500)
committerForrest Voight <forrest@forre.st>
Sun, 5 Feb 2012 03:43:57 +0000 (22:43 -0500)
p2pool/p2p.py

index 859e884..983d9f6 100644 (file)
@@ -57,6 +57,9 @@ class Protocol(bitcoin_p2p.BaseProtocol):
         
         reactor.callLater(10, self._connect_timeout)
         self.timeout_delayed = reactor.callLater(100, self._timeout)
+        
+        old_dataReceived = self.dataReceived
+        self.dataReceived = lambda data: (self.timeout_delayed.reset(100) if not self.timeout_delayed.called else None, old_dataReceived(data))[0]
     
     def _connect_timeout(self):
         if not self.connected2 and self.transport.connected:
@@ -68,10 +71,6 @@ class Protocol(bitcoin_p2p.BaseProtocol):
             self.transport.loseConnection()
             return
         
-        if not self.timeout_delayed.called:
-            self.timeout_delayed.cancel()
-            self.timeout_delayed = reactor.callLater(100, self._timeout)
-        
         bitcoin_p2p.BaseProtocol.packetReceived(self, command, payload2)
     
     def _timeout(self):