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

Class SingleDownload

source code

Manage downloads from a single peer.

Instance Methods [hide private]
 
__init__(self, downloader, connection)
Initialize the instance.
source code
int
_backlog(self, just_unchoked)
Calculate the backlog of chunk requests to the peer.
source code
 
disconnected(self)
Remove the newly disconnected peer.
source code
 
_letgo(self)
Remove the oustanding requests to the peer.
source code
 
got_choke(self)
Update the choked status and remove any active requests.
source code
 
got_unchoke(self)
Update the choked status and request any needed pieces.
source code
boolean
is_choked(self)
Get the choked status of the connection.
source code
boolean
is_interested(self)
Get the interest in the peer.
source code
 
send_interested(self)
Send the interested message to the peer.
source code
 
send_not_interested(self)
Send the not interested message to the peer.
source code
boolean
got_piece(self, index, begin, piece)
Process a received chunk.
source code
 
_request_more(self, new_unchoke=True)
Request more chunks from the peer.
source code
 
fix_download_endgame(self, new_unchoke=True)
Request more chunks from the peer in endgame mode.
source code
boolean
got_have(self, index)
Receive a Have message from the peer.
source code
 
_check_interests(self)
Check if the peer is now interesting.
source code
boolean
got_have_bitfield(self, have)
Receive a Bitfield message from the peer.
source code
float
get_rate(self)
Get the current download rate from the peer.
source code
boolean
is_snubbed(self)
Check if the peer is snubbing the download.
source code
Instance Variables [hide private]
list of (int, int, int) active_requests
the requests that have been sent, the piece, offset within the piece, and the length of the request
int backlog
the current backlog of chunk requests
boolean choked
whether the peer is choking the download
Connecter.Connection connection
the connection to the peer
Downloader downloader
the Downloader instance
int example_interest
an example piece to request
BadDataGuard guard
the guard to use to process pieces
DebTorrent.bitfield.Bitfield have
the bitfield the peer has
boolean interested
whether the peer is interesting
string ip
the IP address of the peer
float last
the last time a chunk was received from the peer
float last2
the last time a chunk or an unchoke was received
DebTorrent.CurrentRateMeasure.Measure measure
for measuring the download rate from the peer
DebTorrent.CurrentRateMeasure.Measure peermeasure
for measuring the download rate of the peer
Method Details [hide private]

__init__(self, downloader, connection)
(Constructor)

source code 
Initialize the instance.
Parameters:

_backlog(self, just_unchoked)

source code 
Calculate the backlog of chunk requests to the peer.
Parameters:
  • just_unchoked (boolean) - whether the connection was just unchoked
Returns: int
the new backlog

_letgo(self)

source code 

Remove the oustanding requests to the peer.

For each active request that was unfulfilled by the peer, inform the Storage that the request was lost, and send interested messages to any remaining peers that have the piece.

is_choked(self)

source code 
Get the choked status of the connection.
Returns: boolean
whether the peer is choking the connection

is_interested(self)

source code 
Get the interest in the peer.
Returns: boolean
whether the peer is interesting

got_piece(self, index, begin, piece)

source code 

Process a received chunk.

Add the newly received chunk to the Storage, remove any oustanding requests for it, and request more chunks from the peer.
Parameters:
  • index (int) - the piece index
  • begin (int) - the offset within the piece
  • piece (string) - the chunk
Returns: boolean
whether the piece was accepted by the Storage (valid)

_request_more(self, new_unchoke=True)

source code 
Request more chunks from the peer.
Parameters:
  • new_unchoke (boolean) - whether this request was the result of a recent unchoke (optional, defaults to False)

fix_download_endgame(self, new_unchoke=True)

source code 
Request more chunks from the peer in endgame mode.
Parameters:
  • new_unchoke (boolean) - whether this request was the result of a recent unchoke (optional, defaults to False)

got_have(self, index)

source code 
Receive a Have message from the peer.
Parameters:
  • index (int) - the piece the peer now has
Returns: boolean
whether the peer is now a seed

got_have_bitfield(self, have)

source code 
Receive a Bitfield message from the peer.
Parameters:
Returns: boolean
whether the peer is a seed

get_rate(self)

source code 
Get the current download rate from the peer.
Returns: float
the peer's download rate

is_snubbed(self)

source code 
Check if the peer is snubbing the download.
Returns: boolean
whether the peer is snubbing the connection