Package DebTorrent :: Package BT1 :: Module Downloader :: Class Downloader
[hide private]
[frames] | no frames]

Class Downloader

source code

A collection of all single downloads.

Instance Methods [hide private]
 
__init__(self, storage, picker, max_rate_period, numpieces, chunksize, measurefunc, snub_time, kickbans_ok, kickfunc, banfunc)
Initialize the instance.
source code
 
set_download_rate(self, rate)
Set the maximum download rate for all downloads.
source code
int
queue_limit(self)
Get the maximum number of bytes to request.
source code
 
chunk_requested(self, size)
Add the new request size to the tally.
source code
 
external_data_received(self, size)
Add the new request size to the tally.
source code
SingleDownload
make_download(self, connection)
Create a new SingleDownload instance for a new connection.
source code
 
piece_flunked(self, index)
Request a failed piece from other peers.
source code
int
has_downloaders(self)
Get the number of active downloads.
source code
 
lost_peer(self, download)
Remove a lost peer from the collection of downloads.
source code
 
_reset_endgame(self)
Stop the endgame mode.
source code
 
add_disconnected_seed(self, id)
Save the time of a disconnected seed.
source code
 
expire_disconnected_seeds(self)
Expire old disconnected seeds.
source code
int
num_disconnected_seeds(self)
Calculate the number or recently seen seeds.
source code
boolean
_check_kicks_ok(self)
Check whether peers can be kicked for bad data.
source code
 
try_kick(self, download)
If allowed, kick a peer.
source code
 
try_ban(self, ip)
If allowed, ban a peer.
source code
 
set_super_seed(self)
Enable super-seed mode.
source code
boolean
check_complete(self, index)
Check whether the download is complete.
source code
boolean
too_many_partials(self)
Check whether there are too many outstanding incomplete pieces.
source code
 
cancel_piece_download(self, pieces)
Cancel any outstanding requests for the pieces.
source code
 
requeue_piece_download(self, pieces=[])
Request more pieces.
source code
 
start_endgame(self)
Switch to endgame mode.
source code
 
pause(self, flag)
Pause or unpause the download.
source code
Instance Variables [hide private]
list of (int, int, int) all_requests
all outstanding requests to all peers
method banfunc
method to call to ban a peer
dictionary banned
keys are the IP addresses of peers that have been banned, values are their peer IDs
int bytes_requested
the number of bytes in oustanding requests
int chunksize
the number of bytes to query for per request
long discarded
the amount of downloaded data that has been discarded
dictionary disconnectedseeds
seeds that have recently been seen, keys are the seed's peer ID, values are the last time the seed was seen
float download_rate
the maximum rate to download at
list of SingleDownload downloads
the active downloads from peers
list of int endgame_queued_pieces
the list of pieces that are queued in end-game mode
boolean endgamemode
whether the download is in end-game mode
dictionary gotbaddata
keys are the IP addresses that have sent bad data
boolean kickbans_halted
not used
boolean kickbans_ok
whether to automatically kick/ban peers that send bad data
dictionary kicked
keys are the IP address, values are the peer ID for peers that have been kicked
method kickfunc
method to call to kick a peer
float last_time
the last time the queue limit was calculated
float max_rate_period
maximum amount of time to guess the current rate estimate represents
method measurefunc
the method to call to add downloaded data to the measurement of the download rate
int numpieces
total number of pieces in the download
boolean paused
whether the download is paused
dictionary perip
keys are the IP addresses of peers, values are their PerIPStats
PiecePicker.PiecePicker picker
the PiecePicker instance
dictionary queued_out
keys are SingleDownload that are queued waiting for download
boolean requeueing
whether requeueing is currently underway
float snub_time
seconds to wait for data to come in over a connection before assuming it's semi-permanently choked
StorageWrapper.StorageWrapper storage
the StorageWrapper instance
boolean super_seeding
whether we are in super-seed mode
DebTorrent.CurrentRateMeasure.Measure totalmeasure
for measuring the total download rate from all peers
Method Details [hide private]

__init__(self, storage, picker, max_rate_period, numpieces, chunksize, measurefunc, snub_time, kickbans_ok, kickfunc, banfunc)
(Constructor)

source code 
Initialize the instance.
Parameters:
  • storage (StorageWrapper.StorageWrapper) - the StorageWrapper instance
  • picker (PiecePicker.PiecePicker) - the PiecePicker instance
  • max_rate_period (float) - maximum amount of time to guess the current rate estimate represents
  • numpieces (int) - total number of pieces in the download
  • chunksize (int) - the number of bytes to query for per request
  • measurefunc (method) - the method to call to add downloaded data to the measurement of the download rate
  • snub_time (float) - seconds to wait for data to come in over a connection before assuming it's semi-permanently choked
  • kickbans_ok (boolean) - whether to automatically kick/ban peers that send bad data
  • kickfunc (method) - method to call to kick a peer
  • banfunc (method) - method to call to ban a peer

set_download_rate(self, rate)

source code 
Set the maximum download rate for all downloads.
Parameters:
  • rate (float) - maximum kB/s to download at (0 = no limit)

queue_limit(self)

source code 
Get the maximum number of bytes to request.
Returns: int
the limit on the number of bytes to request

chunk_requested(self, size)

source code 
Add the new request size to the tally.
Parameters:
  • size (int) - the number of bytes that were requested

external_data_received(self, size)

source code 
Add the new request size to the tally.
Parameters:
  • size (int) - the number of bytes that were requested

make_download(self, connection)

source code 
Create a new SingleDownload instance for a new connection.
Parameters:
Returns: SingleDownload
the newly created SingleDownload instance

piece_flunked(self, index)

source code 
Request a failed piece from other peers.
Parameters:
  • index (int) - the piece index that failed

has_downloaders(self)

source code 
Get the number of active downloads.
Returns: int
the number of active download connections

lost_peer(self, download)

source code 
Remove a lost peer from the collection of downloads.
Parameters:

add_disconnected_seed(self, id)

source code 
Save the time of a disconnected seed.
Parameters:
  • id (string) - the peer ID of the disconnected seed

num_disconnected_seeds(self)

source code 
Calculate the number or recently seen seeds.
Returns: int
the number of recently seen disconnected seeds

_check_kicks_ok(self)

source code 
Check whether peers can be kicked for bad data.
Returns: boolean
whether it is OK to kick peers

try_kick(self, download)

source code 
If allowed, kick a peer.
Parameters:

try_ban(self, ip)

source code 
If allowed, ban a peer.
Parameters:
  • ip (string) - the IP address of the peer

check_complete(self, index)

source code 

Check whether the download is complete.

If it is complete, send the piece to the connected seeds and then disconnect them.
Parameters:
  • index (int) - the last received piece
Returns: boolean
whether the download is complete

too_many_partials(self)

source code 
Check whether there are too many outstanding incomplete pieces.
Returns: boolean
if the number of incomplete pieces is greater than half the number of connected downloads

cancel_piece_download(self, pieces)

source code 
Cancel any outstanding requests for the pieces.
Parameters:
  • pieces (list of int) - the list of pieces to cancel

requeue_piece_download(self, pieces=[])

source code 
Request more pieces.
Parameters:
  • pieces (list of int) - the list of pieces to requeue

pause(self, flag)

source code 
Pause or unpause the download.
Parameters:
  • flag (boolean) - whether to pause of unpause.