From: Cameron Dale Date: Tue, 15 Apr 2008 21:59:38 +0000 (-0700) Subject: Krpc now works as before but with a new request infrastructure. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=731f428bbee35a102320ecdcfa8ac46c22804a02;p=quix0rs-apt-p2p.git Krpc now works as before but with a new request infrastructure. --- diff --git a/apt_p2p_Khashmir/krpc.py b/apt_p2p_Khashmir/krpc.py index d4101ad..97b8908 100644 --- a/apt_p2p_Khashmir/krpc.py +++ b/apt_p2p_Khashmir/krpc.py @@ -216,13 +216,15 @@ class KrpcRequest(Deferred): self.later = None def send(self): + assert not self.later, 'There is already a pending request' self.later = reactor.callLater(self.delay, self.timeOut) self.delay *= 2 - self.protocol._sendData(self.method, self.data) + self.protocol.sendData(self.method, self.data) def timeOut(self): """Call the deferred's errback if a timeout occurs.""" - self.protocol._timeOut(self.tid, self.method) + self.later = None + self.protocol.timeOut(self.tid, self.method) def callback(self, resp): self.dropTimeOut() @@ -236,6 +238,7 @@ class KrpcRequest(Deferred): """Cancel the timeout call when a response is received.""" if self.later and self.later.active(): self.later.cancel() + self.later = None class KRPC: """The KRPC protocol implementation. @@ -486,20 +489,22 @@ class KRPC: req.send() return req - def _sendData(self, method, data): + def sendData(self, method, data): # Save some stats self.stats.sentAction(method) self.stats.sentBytes(len(data)) self.transport.write(data, self.addr) - def _timeOut(self, badTID, method): + def timeOut(self, badTID, method): """Call the deferred's errback if a timeout occurs.""" if badTID in self.tids: req = self.tids[badTID] del(self.tids[badTID]) - self.errback(KrpcError(KRPC_ERROR_TIMEOUT, "timeout waiting for '%s' from %r" % - (method, self.addr))) + req.errback(KrpcError(KRPC_ERROR_TIMEOUT, "timeout waiting for '%s' from %r" % + (method, self.addr))) + else: + log.msg('Received a timeout for an unknown request for %s from %r' % (method, self.addr)) def stop(self): """Timeout all pending requests."""