Browse Source

tracker update

master
Robin Thoni 9 years ago
parent
commit
a51f218b53
1 changed files with 14 additions and 6 deletions
  1. 14
    6
      torrentmanager.py

+ 14
- 6
torrentmanager.py View File

2
 
2
 
3
 import copy
3
 import copy
4
 import time
4
 import time
5
+import random
5
 import torrenttracker
6
 import torrenttracker
6
 
7
 
7
 class TorrentManager:
8
 class TorrentManager:
8
     torrents = []
9
     torrents = []
9
     next_torrents = []
10
     next_torrents = []
10
     last_time = 0
11
     last_time = 0
11
-    def __init__(self, torrents):
12
-        self.torrents = torrents
12
+    max_ratio = 0
13
+    max_rate = 0
14
+    def __init__(self, max_ratio = 1, max_rate = 120):
15
+        self.max_ratio = max_ratio
16
+        self.max_rate = max_rate * 1024
13
 
17
 
14
-    def start(self):
15
-        for torrent in self.torrents:
16
-            torrent.getTracker().start()
18
+    def appendTorrent(self, torrent):
19
+        self.torrents.append(torrent)
20
+
21
+    def getTorrents(self):
22
+        return self.torrents
17
 
23
 
18
     def resetNextTorrents(self):
24
     def resetNextTorrents(self):
19
         self.last_time = int(time.time())
25
         self.last_time = int(time.time())
37
     def updateTorrent(self, torrent = None):
43
     def updateTorrent(self, torrent = None):
38
         if torrent == None:
44
         if torrent == None:
39
             torrent = self.getNextTorrent()
45
             torrent = self.getNextTorrent()
40
-        torrent.getTracker().interval(0, 0, 0)
46
+        uploaded = (self.max_rate / len(self.torrents)) * torrent.getTracker().getInterval()
47
+        uploaded += random.randint(-uploaded / 10, uploaded / 10)
41
         self.next_torrents.remove(torrent)
48
         self.next_torrents.remove(torrent)
49
+        torrent.getTracker().update(uploaded)
42
 
50
 

Loading…
Cancel
Save