|
@@ -2,18 +2,24 @@
|
2
|
2
|
|
3
|
3
|
import copy
|
4
|
4
|
import time
|
|
5
|
+import random
|
5
|
6
|
import torrenttracker
|
6
|
7
|
|
7
|
8
|
class TorrentManager:
|
8
|
9
|
torrents = []
|
9
|
10
|
next_torrents = []
|
10
|
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
|
24
|
def resetNextTorrents(self):
|
19
|
25
|
self.last_time = int(time.time())
|
|
@@ -37,6 +43,8 @@ class TorrentManager:
|
37
|
43
|
def updateTorrent(self, torrent = None):
|
38
|
44
|
if torrent == None:
|
39
|
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
|
48
|
self.next_torrents.remove(torrent)
|
|
49
|
+ torrent.getTracker().update(uploaded)
|
42
|
50
|
|