]> git.mxchange.org Git - quix0rs-apt-p2p.git/commitdiff
Improve the peer ranking and fix a minor bug.
authorCameron Dale <camrdale@gmail.com>
Thu, 17 Apr 2008 19:58:00 +0000 (12:58 -0700)
committerCameron Dale <camrdale@gmail.com>
Thu, 17 Apr 2008 19:58:00 +0000 (12:58 -0700)
apt_p2p/HTTPDownloader.py

index f1488e540481a51a75b445a2bf2fa48ca465ec4c..97346db878aa5adfdb06feb84c68b1dad11eb92e 100644 (file)
@@ -51,7 +51,7 @@ class Peer(ClientFactory):
         self.port = port
         self.stats = stats
         self.mirror = False
-        self.rank = 0.5
+        self.rank = 0.1
         self.busy = False
         self.pipeline = False
         self.closed = True
@@ -189,7 +189,8 @@ class Peer(ClientFactory):
         """Mark sent requests as errors."""
         self._processLastResponse()
         for req in self.response_queue:
-            req.deferRequest.errback(ProtocolError('lost connection'))
+            reactor.callLater(0, req.deferRequest.errback,
+                                 ProtocolError('lost connection'))
         self.busy = False
         self.pipeline = False
         self.closed = True
@@ -314,12 +315,12 @@ class Peer(ClientFactory):
         rank = 1.0
         if self.closed:
             rank *= 0.9
-        rank *= exp(-(len(self.request_queue) - len(self.response_queue)))
+        rank *= exp(-(len(self.request_queue) + len(self.response_queue)))
         speed = self.downloadSpeed()
         if speed > 0.0:
             rank *= exp(-512.0*1024 / speed)
         if self._completed:
-            rank *= exp(-float(self._errors) / self._completed)
+            rank *= exp(-10.0 * self._errors / self._completed)
         rank *= exp(-self.responseTime() / 5.0)
         self.rank = rank