improved peer heuristic to prefer nodes with long uptime less strongly
authorForrest Voight <forrest.voight@gmail.com>
Thu, 10 May 2012 23:16:47 +0000 (19:16 -0400)
committerForrest Voight <forrest.voight@gmail.com>
Thu, 10 May 2012 23:20:56 +0000 (19:20 -0400)
p2pool/p2p.py

index 26a9578..0d6f5ef 100644 (file)
@@ -1,5 +1,6 @@
 from __future__ import division
 
+import math
 import random
 import time
 
@@ -476,4 +477,6 @@ class Node(object):
     
     def get_good_peers(self, max_count):
         t = time.time()
-        return [x[0] for x in sorted(self.addr_store.iteritems(), key=lambda (k, (services, first_seen, last_seen)): -max(3600, last_seen - first_seen)/max(3600, t - last_seen)*random.expovariate(1))][:max_count]
+        return [x[0] for x in sorted(self.addr_store.iteritems(), key=lambda (k, (services, first_seen, last_seen)):
+            -math.log(max(3600, last_seen - first_seen))/math.log(max(3600, t - last_seen))*random.expovariate(1)
+        )][:max_count]