r320 - in /debtorrent/trunk: DebTorrent/BT1/AptListener.py DebTorrent/HTTPHandler.py DebTorrent/launchmanycore.py debian/changelog
camrdale-guest at users.alioth.debian.org
camrdale-guest at users.alioth.debian.org
Wed Nov 7 00:06:50 UTC 2007
Author: camrdale-guest
Date: Wed Nov 7 00:06:50 2007
New Revision: 320
URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=320
Log:
Disable piece update messages.
Add support for new general status update messages.
Modified:
debtorrent/trunk/DebTorrent/BT1/AptListener.py
debtorrent/trunk/DebTorrent/HTTPHandler.py
debtorrent/trunk/DebTorrent/launchmanycore.py
debtorrent/trunk/debian/changelog
Modified: debtorrent/trunk/DebTorrent/BT1/AptListener.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/BT1/AptListener.py?rev=320&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/BT1/AptListener.py (original)
+++ debtorrent/trunk/DebTorrent/BT1/AptListener.py Wed Nov 7 00:06:50 2007
@@ -184,6 +184,7 @@
self.rawserver.add_task(self.process_queue, 1)
closed_conns = []
+ open_conns = {}
for file, queue in self.request_queue.items():
for c, v in queue.items():
# Check for a closed connection
@@ -206,15 +207,21 @@
closed_conns.append((file, c))
v[0].storagewrapper.set_file_readonly(v[1])
self.answer_package(c, file, v[0], v[1], v[2])
+ continue
# Otherwise send an update message
- elif piece_removed:
- self.send_update(c, file, v[0], v[1], v[2], v[3])
+ # Currently disabled due to apt not handling this well
+ #elif piece_removed:
+ # self.package_update(c, file, v[0], v[1], v[2], v[3])
+
+ open_conns.setdefault(c, {}).setdefault(v[0], []).extend(v[3])
# Remove closed/finished connections from the queue
for (file, c) in closed_conns:
self.request_queue[file].pop(c)
if not self.request_queue[file]:
self.request_queue.pop(file)
+
+ self.connection_update(open_conns)
def get_infopage(self):
@@ -466,7 +473,63 @@
return None
- def send_update(self, connection, file, d, f, httpreq, pieces_needed):
+ def connection_update(self, connections):
+ """Send a status 103 update message to the open requesters.
+
+ The input dictionary has keys which are HTTP connections
+ (L{DebTorrent.HTTPHandler.HTTPConnection}), while the values are
+ dictionaries with keys of downloaders
+ (L{DebTorrent.download_bt1.BT1Download}) and values of the list of
+ pieces still needed for that connection from that downloader
+ (C{list} of C{int}).
+
+ @type connections: C{dictionary} of L{DebTorrent.HTTPHandler.HTTPConnection}
+ @param connections: the conections to send updates to
+
+ """
+
+ for connection in connections:
+ # Check to make sure the requester is still waiting
+ if connection.closed:
+ return
+
+ file_needed = 0L
+ for d in connections[connection]:
+ logger.debug('pieces needed: '+ str(connections[connection][d]))
+ processed_piece = []
+ for piece in connections[connection][d]:
+ if piece not in processed_piece:
+ file_needed += d.storagewrapper.piece_sizes[piece]
+ processed_piece.append(piece)
+
+ message = size_format(file_needed) + ' left'
+ logger.debug('file needed: '+str(file_needed)+' from '+ str(processed_piece))
+
+ # Get the data from the statistics gatherer
+ data = self.handler.gather_stats()
+
+ if not data:
+ message += ' no torrents'
+ else:
+ # Display a table row for each running torrent
+ total_size = 0L
+ total_dnrate = 0
+
+ for x in data:
+ ( name, hash, status, progress, peers, seeds, seedsmsg, dist,
+ uprate, dnrate, upamt, dnamt, size, t, msg ) = x
+
+ total_size += size
+ total_dnrate += dnrate
+
+ message += ' at ' + size_format(total_dnrate) + '/s'
+ if total_dnrate > 0:
+ message += ' (' + hours(file_needed/total_dnrate) + ')'
+
+ connection.answer((103, 'Status Update', {'Server': VERSION, 'Content-Type': 'text/plain',
+ 'Message': 'DebTorrent: ' + message}, ''), None)
+
+ def package_update(self, connection, file, d, f, httpreq, pieces_needed):
"""Send a status 102 update message to the requester.
@type connection: L{DebTorrent.HTTPHandler.HTTPConnection}
@@ -499,7 +562,6 @@
connection.answer((102, 'Size Update', {'Server': VERSION, 'Content-Type': 'text/plain',
'Pieces-Downloaded': piece_string}, ''), httpreq)
- return
def answer_package(self, connection, file, d, f, httpreq):
"""Send the newly downloaded package file to the requester.
@@ -750,8 +812,16 @@
if (s < 1024):
r = str(s) + 'B'
+ elif (s < 10485):
+ r = str(int((s/1024.0)*100.0)/100.0) + 'KiB'
+ elif (s < 104857):
+ r = str(int((s/1024.0)*10.0)/10.0) + 'KiB'
elif (s < 1048576):
r = str(int(s/1024)) + 'KiB'
+ elif (s < 10737418L):
+ r = str(int((s/1048576.0)*100.0)/100.0) + 'MiB'
+ elif (s < 107374182L):
+ r = str(int((s/1048576.0)*10.0)/10.0) + 'MiB'
elif (s < 1073741824L):
r = str(int(s/1048576)) + 'MiB'
elif (s < 1099511627776L):
@@ -783,7 +853,7 @@
m, s = divmod(n, 60)
h, m = divmod(m, 60)
if h > 0:
- return '%d hour %02d min %02d sec' % (h, m, s)
+ return '%dh%02dm%02ds' % (h, m, s)
else:
- return '%d min %02d sec' % (m, s)
-
+ return '%dm%02ds' % (m, s)
+
Modified: debtorrent/trunk/DebTorrent/HTTPHandler.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/HTTPHandler.py?rev=320&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/HTTPHandler.py (original)
+++ debtorrent/trunk/DebTorrent/HTTPHandler.py Wed Nov 7 00:06:50 2007
@@ -382,8 +382,9 @@
if not self.requests:
if httpreq is None:
# There's only one request allowed, so send the answer
- if r[0] != 102 or (self.protocol == "DEBTORRENT" and
- self.version >= (0, 2)):
+ if (r[0] != 102 and r[0] != 103) or (
+ self.protocol == "DEBTORRENT" and
+ self.version >= (0, 2)):
self.send_answer(r, self.header, self.command, self.path,
self.encoding, self.headers)
else:
@@ -405,6 +406,9 @@
else:
if r[0] != 102:
httpreq.save_answer(r)
+ elif r[0] == 103 and self.protocol == "DEBTORRENT" and self.version >= (0, 2):
+ self.send_answer(r, 'GET None DEBTORRENT/0.2', 'GET', 'None', 'identity', {})
+
# Answer all possible requests
while self.requests and self.requests[0].has_answer():
Modified: debtorrent/trunk/DebTorrent/launchmanycore.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/launchmanycore.py?rev=320&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/launchmanycore.py (original)
+++ debtorrent/trunk/DebTorrent/launchmanycore.py Wed Nov 7 00:06:50 2007
@@ -432,7 +432,7 @@
name = cache['path']
else:
name = cache['name']
- size = cache['length']
+ size = 0
d = self.downloads[hash]
progress = '0.0%'
peers = 0
@@ -477,6 +477,7 @@
uprate = stats['up']
upamt = s.upTotal
dnamt = s.downTotal
+ size = stats['wanted']
if d.is_dead() or d.status_errtime+300 > clock():
msg = d.status_err[-1]
Modified: debtorrent/trunk/debian/changelog
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/debian/changelog?rev=320&op=diff
==============================================================================
--- debtorrent/trunk/debian/changelog (original)
+++ debtorrent/trunk/debian/changelog Wed Nov 7 00:06:50 2007
@@ -2,6 +2,8 @@
* Update to support apt debtorrent transport version 0.2
- send piece downloaded status messages
+ (currently disbaled due to apt not liking it)
+ - send general status update messages
-- Cameron Dale <camrdale at gmail.com> Sun, 04 Nov 2007 23:31:20 -0800
More information about the Debtorrent-commits
mailing list