Package DebTorrent :: Module download_bt1 :: Class BT1Download
[hide private]
[frames] | no frames]

Class BT1Download

source code

Manage a single download.

Instance Methods [hide private]
 
__init__(self, statusfunc, finfunc, errorfunc, doneflag, config, response, infohash, id, rawserver, port, appdataobj)
Initialize the instance.
source code
boolean
checkSaveLocation(self, loc)
Check whether the download location exists.
source code
string
saveAs(self, filefunc, pathfunc=None)
Initialize the location to save the download to.
source code
string
getFilename(self)
Get the download location.
source code
 
_finished(self)
Finish the download.
source code
 
_data_flunked(self, amount, index)
Process a failed hash check on a piece.
source code
 
_failed(self, reason)
Stop the failed download.
source code
list of boolean
find_files(self)
Search through the save directory to find files which already exist.
source code
boolean
initFiles(self, old_style=True)
Initialize the files for the download.
source code
BT1.Uploader.Upload
_make_upload(self, connection, ratelimiter, totalup)
Create a new Upload instance
source code
 
_kick_peer(self, connection)
Disconnect a peer.
source code
 
_ban_peer(self, ip)
Ban a peer from the download.
source code
 
_received_raw_data(self, x)
Update the rate limiter when data comes in.
source code
 
_received_data(self, x)
Add received data to the rate measures.
source code
 
_received_http_data(self, x)
Add received HTTP data to the rate measures.
source code
 
_cancelfunc(self, pieces)
Cancel the download of pieces.
source code
 
_reqmorefunc(self, pieces)
Request to download the pieces.
source code
boolean
startEngine(self, ratelimiter=None)
Start various downloader engines.
source code
 
rerequest_complete(self)
Send the completed event to the tracker.
source code
 
rerequest_stopped(self)
Send the stopped event to the tracker.
source code
boolean
rerequest_lastfailed(self)
Check if the last tracker request failed.
source code
 
rerequest_ondownloadmore(self)
Try to trigger a tracker request.
source code
 
startRerequester(self, seededfunc=None, force_rapid_update=True)
Start the tracker requester.
source code
 
_init_stats(self)
Start the statistics aggregater.
source code
method
startStats(self)
Start a statistics gatherer.
source code
BT1.Encrypter.Encoder
getPortHandler(self)
Get the object that is called when a connection comes in.
source code
boolean
shutdown(self, torrentdata={})
Shutdown the running download.
source code
 
setUploadRate(self, rate)
Set a new maximum upload rate.
source code
 
setConns(self, conns, conns2=None)
Set the number of connections limits.
source code
 
setDownloadRate(self, rate)
Set a new maximum download rate.
source code
 
startConnection(self, ip, port, id)
Start a new connection to a peer.
source code
 
_startConnection(self, ipandport, id)
Start a new connection to a peer.
source code
 
setInitiate(self, initiate)
Set the maximum number of connections to initiate.
source code
dictionary
getConfig(self)
Get the current configuration parameters.
source code
dictionary
getDefaults(self)
Get the default configuration parameters.
source code
string
getUsageText(self)
Get the header only for the usage text (not used).
source code
 
reannounce(self, special=None)
Reannounce to the tracker.
source code
dictionary
getResponse(self)
Get the response data from the metainfo file.
source code
boolean
Pause(self)
Schedule the pausing of the download.
source code
 
onPause(self)
Pause the download.
source code
 
Unpause(self)
Schedule the resuming of the download.
source code
 
onUnpause(self)
Resume the download.
source code
 
set_super_seed(self)
Schedule the change of the upload into super-seed mode.
source code
 
_set_super_seed(self)
Change the upload into super-seed mode.
source code
boolean
am_I_finished(self)
Determine if the download is complete or still under way.
source code
(long, long)
get_transfer_stats(self)
Get the total amount of data transferred.
source code
Instance Variables [hide private]
ConfigDir.ConfigDir appdataobj
the configuration and cache directory manager
string argslistheader
the header to print before the default config
boolean checking
whether the download is in the initialization phase
BT1.Choker.Choker choker
the Choker instance
dictionary config
the configuration variables
BT1.Connecter.Connecter connecter
the Connecter instance to manage all the connections
long datalength
the total length of the download
threading.Event doneflag
the flag that indicates when the program is to be shutdown
BT1.Downloader.Downloader downloader
the Downloader instance
CurrentRateMeasure.Measure downmeasure
the measure of the download rate
BT1.Encrypter.Encoder encoder
the port listener for connections
method encoder_ban
the method to call to ban and IP address
method errorfunc
the method to call when an error occurs
threading.Event excflag
whether an exception has occurred
boolean failed
whether the download failed
threading.Event filedatflag
not used
string filename
the save location
list of (string, long) files
the full file names and lengths of all the files in the download
BT1.FileSelector.FileSelector fileselector
the FileSelector instance
threading.Event finflag
whether the download is complete
method finfunc
the method to call when the download is completed
BT1.HTTPDownloader.HTTPDownloader httpdownloader
the backup HTTP downloader
dictionary info
the info data from the response data
string infohash
the hash of the info from the response data
int len_pieces
the number of pieces
string myid
the peer ID to use
BT1.PiecePicker.PiecePicker picker
the PiecePicker instance
list of int piece_lengths
the lengths of the pieces
list of string pieces
the hashes of the pieces
int port
the port being listened to
RateLimiter.RateLimiter ratelimiter
the RateLimiter instance to limit the upload rate
RateMeasure.RateMeasure ratemeasure
the RateMeasure instance
method ratemeasure_datarejected
the method to call when incoming data failed
RawServer.RawServer rawserver
the server controlling the program
BT1.Rerequester.Rerequester rerequest
the Rerequester instance to use to communicate with the tracker
dictionary response
the response data from the metainfo file
boolean started
whether the download has been started
BT1.Statistics.Statistics statistics
the statistics gathering instance
method statusfunc
the method to call to print status updates
BT1.Storage.Storage storage
the file storage instance
BT1.StorageWrapper.StorageWrapper storagewrapper
the StorageWrapper instance
boolean super_seeding_active
whether the download is in super-seed mode
threading.Event superseedflag
indicates the upload is in super-seed mode
float tcp_ack_fudge
the fraction of TCP ACK download overhead to add to upload rate calculations
threading.Event unpauseflag
the flag to unset to pause the download
CurrentRateMeasure.Measure upmeasure
the measure of the upload rate
float whenpaused
the time when the download was paused
Method Details [hide private]

__init__(self, statusfunc, finfunc, errorfunc, doneflag, config, response, infohash, id, rawserver, port, appdataobj)
(Constructor)

source code 
Initialize the instance.
Parameters:
  • statusfunc (method) - the method to call to print status updates
  • finfunc (method) - the method to call when the download is completed
  • errorfunc (method) - the method to call when an error occurs
  • doneflag (threading.Event) - the flag that indicates when the program is to be shutdown
  • config (dictionary) - the configuration variables
  • response (dictionary) - the response data from the metainfo file
  • infohash (string) - the hash of the info from the response data
  • id (string) - the peer ID to use
  • rawserver (RawServer.RawServer) - the server controlling the program
  • port (int) - the port being listened to
  • appdataobj (ConfigDir.ConfigDir) - the configuration and cache directory manager

checkSaveLocation(self, loc)

source code 

Check whether the download location exists.

For multiple files, returns true if a single one exists.
Parameters:
  • loc (string) - the save location to check
Returns: boolean
whether the location exists.

saveAs(self, filefunc, pathfunc=None)

source code 
Initialize the location to save the download to.
Parameters:
  • filefunc (method) - the method to call to get the location to save the download
  • pathfunc (method) - the method to call to alert the UI to any possible change in the download location
Returns: string
the location to save to

getFilename(self)

source code 
Get the download location.
Returns: string
the download location

_finished(self)

source code 

Finish the download.

Set the files to read-only, update the Choker for seeding, stop the piece requester.

_data_flunked(self, amount, index)

source code 
Process a failed hash check on a piece.
Parameters:
  • amount (int) - the amount of failed data
  • index (int) - the piece that failed

_failed(self, reason)

source code 
Stop the failed download.
Parameters:
  • reason (string) - the reason for the failure

find_files(self)

source code 
Search through the save directory to find files which already exist.
Returns: list of boolean
a list of which entries in the list files already exist

initFiles(self, old_style=True)

source code 

Initialize the files for the download.

Initialize the priorities, then create the Storage, StorageWrapper, and FileSelector. Then initialize the StorageWrapper.
Parameters:
  • old_style (boolean) - whether to use the old-style StorageWrapper initialization (optional, defaults to False)
Returns: boolean
whether the initialization was successful

_make_upload(self, connection, ratelimiter, totalup)

source code 
Create a new Upload instance
Parameters:
Returns: BT1.Uploader.Upload
the new Upload instance

_kick_peer(self, connection)

source code 
Disconnect a peer.
Parameters:

_ban_peer(self, ip)

source code 
Ban a peer from the download.
Parameters:
  • ip (string) - the IP address of the peer to ban

_received_raw_data(self, x)

source code 
Update the rate limiter when data comes in.
Parameters:
  • x (int) - the number of bytes that were received

_received_data(self, x)

source code 
Add received data to the rate measures.
Parameters:
  • x (int) - the number of bytes that were received

_received_http_data(self, x)

source code 
Add received HTTP data to the rate measures.
Parameters:
  • x (int) - the number of bytes that were received

_cancelfunc(self, pieces)

source code 
Cancel the download of pieces.
Parameters:
  • pieces (list of int) - the pieces to stop downloading

_reqmorefunc(self, pieces)

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

startEngine(self, ratelimiter=None)

source code 

Start various downloader engines.

Starts the upload and download CurrentRateMeasure.Measure, RateLimiter.RateLimiter, BT1.Downloader.Downloader, BT1.Connecter.Connecter, BT1.Encrypter.Encoder, and BT1.HTTPDownloader.HTTPDownloader.
Parameters:
  • ratelimiter (RateLimiter.RateLimiter) - the RateLimiter instance to use (optional, defaults to starting a new one)
Returns: boolean
whether the engines were started

rerequest_lastfailed(self)

source code 
Check if the last tracker request failed.
Returns: boolean
whether it failed (or False if there is no Rerequester)

startRerequester(self, seededfunc=None, force_rapid_update=True)

source code 
Start the tracker requester.
Parameters:
  • seededfunc (method) - method to call if the tracker reports the torrent is seeded (optional, defaults to not checking)
  • force_rapid_update (boolean) - whether to do quick tracker updates when requested (optional, defaults to False)

startStats(self)

source code 
Start a statistics gatherer.
Returns: method
the method to call to get the gathered statistics

getPortHandler(self)

source code 
Get the object that is called when a connection comes in.
Returns: BT1.Encrypter.Encoder
the object responsible for listening to a port

shutdown(self, torrentdata={})

source code 
Shutdown the running download.
Parameters:
  • torrentdata (dictionary) - any data that needs to be saved (pickled)
Returns: boolean
False if a failure or exception occurred

setUploadRate(self, rate)

source code 
Set a new maximum upload rate.
Parameters:
  • rate (float) - the new upload rate (kB/s)

setConns(self, conns, conns2=None)

source code 
Set the number of connections limits.
Parameters:
  • conns (int) - the number of uploads to fill out to with extra optimistic unchokes
  • conns2 (int) - the maximum number of uploads to allow at once (optional, defaults to the value of conns)

setDownloadRate(self, rate)

source code 
Set a new maximum download rate.
Parameters:
  • rate (float) - the new download rate (kB/s)

startConnection(self, ip, port, id)

source code 
Start a new connection to a peer.
Parameters:
  • ip (string) - the IP address of the peer
  • port (int) - the port to contact the peer on
  • id (string) - the peer's ID

_startConnection(self, ipandport, id)

source code 
Start a new connection to a peer.
Parameters:
  • ipandport ((string, int)) - the IP address and port to contact the peer on
  • id (string) - the peer's ID

setInitiate(self, initiate)

source code 
Set the maximum number of connections to initiate.
Parameters:
  • initiate (int) - the new maximum

getConfig(self)

source code 
Get the current configuration parameters.
Returns: dictionary
the configuration parameters

getDefaults(self)

source code 
Get the default configuration parameters.
Returns: dictionary
the default configuration parameters

getUsageText(self)

source code 
Get the header only for the usage text (not used).
Returns: string
the header of the usage text

reannounce(self, special=None)

source code 
Reannounce to the tracker.
Parameters:
  • special (string) - the URL of the tracker to announce to (optional, defaults to the tracker list from the metainfo file)

getResponse(self)

source code 
Get the response data from the metainfo file.
Returns: dictionary
the response data (or None if there isn't any

Pause(self)

source code 
Schedule the pausing of the download.
Returns: boolean
whether the download pause was schedules

am_I_finished(self)

source code 
Determine if the download is complete or still under way.
Returns: boolean
whether the download is complete

get_transfer_stats(self)

source code 
Get the total amount of data transferred.
Returns: (long, long)
the measured total upload and download bytes