X-Git-Url: https://git.mxchange.org/?p=quix0rs-apt-p2p.git;a=blobdiff_plain;f=apt_p2p%2FHTTPDownloader.py;fp=apt_p2p%2FHTTPDownloader.py;h=13cb237320d24b9ce2c87b6e8940556592701af2;hp=057b5a2befdc6783d1c2e295d8c6b9024c782231;hb=7a84d9fb17076695aba3c0f5a32c6487bdd3f059;hpb=d63ad7d7b1c9e5567bd28450197ef810dc5c5475 diff --git a/apt_p2p/HTTPDownloader.py b/apt_p2p/HTTPDownloader.py index 057b5a2..13cb237 100644 --- a/apt_p2p/HTTPDownloader.py +++ b/apt_p2p/HTTPDownloader.py @@ -56,7 +56,7 @@ class Peer(ClientFactory): assert self.closed and not self.connecting self.connecting = True d = protocol.ClientCreator(reactor, HTTPClientProtocol, self).connectTCP(self.host, self.port) - d.addCallback(self.connected) + d.addCallbacks(self.connected, self.connectionError) def connected(self, proto): """Begin processing the queued requests.""" @@ -65,6 +65,23 @@ class Peer(ClientFactory): self.proto = proto self.processQueue() + def connectionError(self, err): + """Cancel the requests.""" + log.msg('Failed to connect to the peer by HTTP.') + log.err(err) + + # Remove one request so that we don't loop indefinitely + if self.request_queue: + req = self.request_queue.pop(0) + req.deferRequest.errback(err) + + self._completed += 1 + self._errors += 1 + self.rerank() + if self.connecting: + self.connecting = False + self.clientGone(None) + def close(self): """Close the connection to the peer.""" if not self.closed: