1
# Written by Bram Cohen
2
# see LICENSE.txt for license information
6
class DownloaderFeedback:
7
def __init__(self, choker, add_task, statusfunc, upfunc, downfunc, uptotal, downtotal,
8
remainingfunc, leftfunc, file_length, finflag, interval, spewflag):
10
self.add_task = add_task
11
self.statusfunc = statusfunc
13
self.downfunc = downfunc
14
self.uptotal = uptotal
15
self.downtotal = downtotal
16
self.remainingfunc = remainingfunc
17
self.leftfunc = leftfunc
18
self.file_length = file_length
19
self.finflag = finflag
20
self.interval = interval
21
self.spewflag = spewflag
26
cs = self.choker.connections
27
for id in self.lastids:
28
for i in xrange(len(cs)):
29
if cs[i].get_id() == id:
30
return cs[i:] + cs[:i]
33
def collect_spew(self):
36
self.lastids = [c.get_id() for c in cs]
39
rec["ip"] = c.get_ip()
40
if c is self.choker.connections[0]:
41
rec["is_optimistic_unchoke"] = 1
43
rec["is_optimistic_unchoke"] = 0
44
if c.is_locally_initiated():
45
rec["initiation"] = "local"
47
rec["initiation"] = "remote"
49
rec["upload"] = (int(u.measure.get_rate()), u.is_interested(), u.is_choked())
52
rec["download"] = (int(d.measure.get_rate()), d.is_interested(), d.is_choked(), d.is_snubbed())
58
self.add_task(self.display, self.interval)
60
if self.finflag.isSet():
61
status = {"upRate" : self.upfunc(), "upTotal" : self.uptotal() / 1048576.0}
62
if self.spewflag.isSet():
63
status['spew'] = self.collect_spew()
64
self.statusfunc(status)
66
timeEst = self.remainingfunc()
68
if self.file_length > 0:
69
fractionDone = (self.file_length - self.leftfunc()) / float(self.file_length)
73
"fractionDone" : fractionDone,
74
"downRate" : self.downfunc(),
75
"upRate" : self.upfunc(),
76
"upTotal" : self.uptotal() / 1048576.0,
77
"downTotal" : self.downtotal() / 1048576.0
79
if timeEst is not None:
80
status['timeEst'] = timeEst
81
if self.spewflag.isSet():
82
status['spew'] = self.collect_spew()
83
self.statusfunc(status)