]> git.ipfire.org Git - ipfire.org.git/commitdiff
tracker: Make interval for clients random.
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 19 Jan 2011 18:18:33 +0000 (19:18 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 19 Jan 2011 18:18:33 +0000 (19:18 +0100)
Some clients send dozens requests at the same time and this
is not very good for both, the client and the server.

www/webapp/backend/tracker.py

index eae50d359e1c6dc56d9caae952eefa812a237d43..99624faec65f4fb665a7a48241d4f2eba2115f84 100644 (file)
@@ -1,5 +1,6 @@
 #!/usr/bin/python
 
+import random
 import time
 
 from databases import Databases
@@ -20,8 +21,10 @@ class Tracker(object):
        id = "TheIPFireTorrentTracker"
 
        # Intervals # XXX needs to be in Settings
-       interval = 60*60
-       min_interval = 30*60
+       _interval = 60*60
+       _min_interval = 30*60
+
+       random_interval = -60, 60
 
        numwant = 50
 
@@ -151,6 +154,14 @@ class Tracker(object):
        def since(self):
                return int(time.time() - self.interval)
 
+       @property
+       def interval(self):
+               return self._interval + random.randint(*self.random_interval)
+
+       @property
+       def min_interval(self):
+               return self._min_interval + random.randint(*self.random_interval)
+
 
 ##### This is borrowed from the bittorrent client libary #####