r416 - in /debtorrent/trunk/DebTorrent: BT1/HTTPDownloader.py bitfield.py download_bt1.py
camrdale at users.alioth.debian.org
camrdale at users.alioth.debian.org
Sat Mar 20 18:29:42 UTC 2010
Author: camrdale
Date: Sat Mar 20 18:29:37 2010
New Revision: 416
URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=416
Log:
Use a Bitfield for the seed, first step toward fixing #516708
Modified:
debtorrent/trunk/DebTorrent/BT1/HTTPDownloader.py
debtorrent/trunk/DebTorrent/bitfield.py
debtorrent/trunk/DebTorrent/download_bt1.py
Modified: debtorrent/trunk/DebTorrent/BT1/HTTPDownloader.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/BT1/HTTPDownloader.py?rev=416&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/BT1/HTTPDownloader.py (original)
+++ debtorrent/trunk/DebTorrent/BT1/HTTPDownloader.py Sat Mar 20 18:29:37 2010
@@ -10,8 +10,6 @@
@var logger: the logger to send all log messages to for this module
@type VERSION: C{string}
@var VERSION: the UserAgent identifier sent to all sites
- at type haveall: L{haveComplete}
- at var haveall: instance of the seed's bitfield
"""
@@ -27,21 +25,6 @@
logger = logging.getLogger('DebTorrent.BT1.HTTPDownloader')
VERSION = product_name+'/'+version_short
-
-class haveComplete:
- """Dummy class similar to L{Debtorrent.bitfield.Bitfield}.
-
- This class represents the HTTP seed's bitfield, which is always complete
- and has every piece because it is a seed.
-
- """
- def complete(self):
- """Dummy function to always return true."""
- return True
- def __getitem__(self, x):
- """Dummy function to always return true."""
- return True
-haveall = haveComplete()
class SingleDownload:
"""Control HTTP downloads from a single site.
@@ -62,7 +45,7 @@
@type query: C{string}
@ivar query: the query component from the L{baseurl}
@type headers: C{dictionary}
- @ivar headres: the HTTP headers to send in the request
+ @ivar headers: the HTTP headers to send in the request
@type measure: L{DebTorrent.CurrentRateMeasure.Measure}
@ivar measure: tracks the download rate from the site
@type index: C{int}
@@ -111,6 +94,7 @@
self.downloader = downloader
self.baseurl = url
+ self.have = Bitfield(length = downloader.numpieces, defaultValue = True)
try:
(scheme, self.netloc, path, params, query, fragment) = urlparse(url)
except:
@@ -200,11 +184,11 @@
if self.downloader.picker.am_I_complete():
self.downloader.downloads.remove(self)
return
- self.index = self.downloader.picker.next(haveall, self._want)
+ self.index = self.downloader.picker.next(self.have, self._want)
if ( self.index is None and not self.endflag
and not self.downloader.peerdownloader.has_downloaders() ):
self.endflag = True
- self.index = self.downloader.picker.next(haveall, self._want)
+ self.index = self.downloader.picker.next(self.have, self._want)
if self.index is None:
self.endflag = True
self.resched()
@@ -429,7 +413,7 @@
def __init__(self, storage, picker, rawserver,
finflag, errorfunc, peerdownloader,
- max_rate_period, infohash, measurefunc, gotpiecefunc,
+ max_rate_period, numpieces, measurefunc, gotpiecefunc,
filenamefunc):
"""Initialize the instance.
@@ -448,8 +432,8 @@
@type max_rate_period: C{float}
@param max_rate_period: maximum amount of time to guess the current
rate estimate represents
- @type infohash: C{string}
- @param infohash: the info hash
+ @type numpieces: C{int}
+ @param numpieces: total number of pieces in the download
@type measurefunc: C{method}
@param measurefunc: the method to call to add downloaded data to the total
download rate measurement
@@ -466,7 +450,7 @@
self.finflag = finflag
self.errorfunc = errorfunc
self.peerdownloader = peerdownloader
- self.infohash = infohash
+ self.numpieces = numpieces
self.max_rate_period = max_rate_period
self.gotpiecefunc = gotpiecefunc
self.measurefunc = measurefunc
Modified: debtorrent/trunk/DebTorrent/bitfield.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/bitfield.py?rev=416&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/bitfield.py (original)
+++ debtorrent/trunk/DebTorrent/bitfield.py Sat Mar 20 18:29:37 2010
@@ -55,7 +55,8 @@
"""
- def __init__(self, length = None, bitstring = None, copyfrom = None):
+ def __init__(self, length = None, bitstring = None, copyfrom = None,
+ defaultValue = False):
"""
@type length: C{int}
@@ -63,10 +64,13 @@
(optional, if missing use length of copyfrom)
@type bitstring: C{string}
@param bitstring: the bitfield string to initialize the bitfield from
- (optional, default is to initialize all to false)
+ (optional, default is to initialize all to L{defaultValue})
@type copyfrom: L{Bitfield}
@param copyfrom: another bitfield to make a copy of
(optional, default is to create a new empty one)
+ @type defaultValue: C{boolean}
+ @param defaultValue: the default value to initialize the bitfield with
+ (optional, default is to initialize all to false)
"""
@@ -98,8 +102,11 @@
self.array = r
self.numfalse = negsum(r)
else:
- self.array = [False] * length
- self.numfalse = length
+ self.array = [defaultValue] * length
+ if defaultValue:
+ self.numfalse = 0
+ else:
+ self.numfalse = length
def __setitem__(self, index, val):
"""Set one of the bitfield entries.
Modified: debtorrent/trunk/DebTorrent/download_bt1.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/download_bt1.py?rev=416&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/download_bt1.py (original)
+++ debtorrent/trunk/DebTorrent/download_bt1.py Sat Mar 20 18:29:37 2010
@@ -1198,7 +1198,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.config['max_rate_period'], self.len_pieces, self._received_http_data,
self.connecter.got_piece, self.getFilename)
if self.response.has_key('deb_mirrors') and not self.finflag.isSet():
if not self.config['disable_http_downloader']:
More information about the Debtorrent-commits
mailing list