r95 - in /debtorrent/branches/http-listen/DebTorrent: BT1/HTTPDownloader.py download_bt1.py
camrdale-guest at users.alioth.debian.org
camrdale-guest at users.alioth.debian.org
Sat Jun 9 02:55:23 UTC 2007
Author: camrdale-guest
Date: Sat Jun 9 02:55:23 2007
New Revision: 95
URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=95
Log:
Make deb_mirrors backup HTTP downloading work.
Tested to work on a mirror, including with sub-package pieces (Yay).
Modified:
debtorrent/branches/http-listen/DebTorrent/BT1/HTTPDownloader.py
debtorrent/branches/http-listen/DebTorrent/download_bt1.py
Modified: debtorrent/branches/http-listen/DebTorrent/BT1/HTTPDownloader.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/branches/http-listen/DebTorrent/BT1/HTTPDownloader.py?rev=95&op=diff
==============================================================================
--- debtorrent/branches/http-listen/DebTorrent/BT1/HTTPDownloader.py (original)
+++ debtorrent/branches/http-listen/DebTorrent/BT1/HTTPDownloader.py Sat Jun 9 02:55:23 2007
@@ -25,6 +25,8 @@
except:
True = 1
False = 0
+
+DEBUG = True
VERSION = product_name+'/'+version_short
@@ -188,6 +190,7 @@
request, and then starts the request.
"""
+
self.cancelled = False
if self.downloader.picker.am_I_complete():
self.downloader.downloads.remove(self)
@@ -201,13 +204,18 @@
self.endflag = True
self.resched()
else:
+ if DEBUG:
+ print 'HTTPDownloader: downloading piece', self.index
(start, end, length, file) = self.downloader.storage.storage.get_file_range(self.index)
+ filename = self.downloader.filenamefunc()
+ if len(filename) > 0 and file.startswith(filename):
+ file = file[1+len(filename):]
self.url = ( self.seedurl + file + self.params + self.query )
self._get_requests()
if self.headers.has_key('Range'):
del self.headers['Range']
if self.request_size < length:
- self.headers['Range'] = 'bytes=' + self._request_ranges()
+ self.headers['Range'] = 'bytes=' + self._request_ranges(start, end)
rq = Thread(target = self._request)
rq.setDaemon(False)
rq.start()
@@ -227,12 +235,20 @@
self.error = None
self.received_data = None
try:
+ if DEBUG:
+ print 'HTTPDownloader: sending request'
+ print 'GET', self.url, self.headers
self.connection.request('GET',self.url, None, self.headers)
r = self.connection.getresponse()
+ if DEBUG:
+ print 'HTTPDownloader: got response'
+ print r.status, r.reason, r.getheaders()
self.connection_status = r.status
self.received_data = r.read()
except Exception, e:
self.error = 'error accessing http seed: '+str(e)
+ if DEBUG:
+ print 'error accessing http seed: '+str(e)
try:
self.connection.close()
except:
@@ -280,7 +296,7 @@
except:
pass
return False
- if self.connection_status != 206:
+ if self.connection_status not in [200, 206]:
self.errorcount += 1
return False
self._retry_period = 1
@@ -338,9 +354,13 @@
self.downloader.storage.request_lost(self.index, begin, length)
self.requests = []
- def _request_ranges(self):
+ def _request_ranges(self, offset, end):
"""Build a list of ranges to request from the site.
-
+
+ @type offset: C{long}
+ @param offset: the offset within the file that the piece starts at
+ @type end: C{long}
+ @param end: the offset within the file that the piece ends at
@rtype: C{string}
@return: the comma separated ranges to request
@@ -355,11 +375,13 @@
else:
if s:
s += ','
- s += str(begin)+'-'+str(begin+length-1)
+ assert offset+begin+length <= end
+ s += str(offset + begin)+'-'+str(offset+begin+length-1)
begin, length = begin1, length1
if s:
s += ','
- s += str(begin)+'-'+str(begin+length-1)
+ assert offset+begin+length <= end
+ s += str(offset+begin)+'-'+str(offset+begin+length-1)
return s
@@ -388,6 +410,9 @@
@type measurefunc: C{method}
@ivar measurefunc: the method to call to add downloaded data to the total
download rate measurement
+ @type filenamefunc: C{method}
+ @ivar filenamefunc: the method to call to determine the file name that
+ the download is being saved under
@type downloads: C{list} of L{SingleDownload}
@ivar downloads: the list of all current download connections to sites
@type seedsfound: C{int}
@@ -397,7 +422,8 @@
def __init__(self, storage, picker, rawserver,
finflag, errorfunc, peerdownloader,
- max_rate_period, infohash, measurefunc, gotpiecefunc):
+ max_rate_period, infohash, measurefunc, gotpiecefunc,
+ filenamefunc):
"""Initialize the instance.
@type storage: L{StorageWrapper.StorageWrapper}
@@ -422,6 +448,8 @@
download rate measurement
@type gotpiecefunc: C{method}
@param gotpiecefunc: the method to call when a piece comes in
+ @type filenamefunc: C{method}
+ @param filenamefunc: the method to call to determine the save location
"""
@@ -437,6 +465,7 @@
self.measurefunc = measurefunc
self.downloads = []
self.seedsfound = 0
+ self.filenamefunc = filenamefunc
def make_download(self, url):
"""Create a new download from a site.
@@ -448,6 +477,8 @@
"""
+ if DEBUG:
+ print 'Starting a deb_mirror downloader for:', url
self.downloads.append(SingleDownload(self, url))
return self.downloads[-1]
@@ -471,6 +502,8 @@
"""
+ if DEBUG:
+ print 'Cancelling all HTTP downloads for pieces:', pieces
for d in self.downloads:
if d.active and d.index in pieces:
d.cancelled = True
Modified: debtorrent/branches/http-listen/DebTorrent/download_bt1.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/branches/http-listen/DebTorrent/download_bt1.py?rev=95&op=diff
==============================================================================
--- debtorrent/branches/http-listen/DebTorrent/download_bt1.py (original)
+++ debtorrent/branches/http-listen/DebTorrent/download_bt1.py Sat Jun 9 02:55:23 2007
@@ -1195,7 +1195,7 @@
self.httpdownloader = HTTPDownloader(self.storagewrapper, self.picker,
self.rawserver, self.finflag, self.errorfunc, self.downloader,
self.config['max_rate_period'], self.infohash, self._received_http_data,
- self.connecter.got_piece)
+ self.connecter.got_piece, self.getFilename)
if self.response.has_key('deb_mirrors') and not self.finflag.isSet():
for u in self.response['deb_mirrors']:
self.httpdownloader.make_download(u)
More information about the Debtorrent-commits
mailing list