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

Class PiecePicker

source code

Choose pieces to download.

Instance Methods [hide private]
 
__init__(self, numpieces, rarest_first_cutoff=1, rarest_first_priority_cutoff=3, priority_step=20)
Initialize the instance and the piece interests.
source code
 
_init_interests(self)
Initialize the interests in pieces to all not interested.
source code
 
got_have(self, piece)
Process a piece that has a new copy found.
source code
 
lost_have(self, piece)
Process a piece that lost a copy.
source code
 
_shift_over(self, piece, l1, l2)
Remove a piece from an old interest level to a new one.
source code
 
got_seed(self)
Process a newly found seed.
source code
 
became_seed(self)
Process this client becoming a seed.
source code
 
lost_seed(self)
Process a lost seed.
source code
 
requested(self, piece)
Add a piece that a request has been sent for to the list of started pieces.
source code
 
_remove_from_interests(self, piece, keep_partial=True)
Remove a piece from the interests.
source code
 
complete(self, piece)
Process a successfully received piece.
source code
int
next(self, haves, wantfunc, complete_first=True)
Choose a piece to request to download next from a peer.
source code
boolean
am_I_complete(self)
Determine if the download is complete.
source code
 
bump(self, piece)
Move a piece to the end of its interest level.
source code
boolean
set_priority(self, piece, p)
Adjust the priority for a piece.
source code
boolean
is_blocked(self, piece)
Determine whether a piece is disabled.
source code
 
set_superseed(self)
Switch to super-seeding mode.
source code
int
next_have(self, connection, looser_upload)
Determine the next piece to tell a peer we have in super-seed mode.
source code
 
lost_peer(self, connection)
Process a lost peer in super-seed mode.
source code
Instance Variables [hide private]
list of int crosscount
at each index, the value is the number of pieces that have that many copies in the non-seeding peers
list of int crosscount2
at each index, the value is the number of pieces that have that many copies in the non-seeding peers (including this peer)
int cutoff
the number of peers which need to have a piece before other partials take priority over rarest first
boolean done
whether the download is complete
list of int has
values are 1 for the pieces that this peer has
list of list of int interests
the interest levels, each level is a list of piece indexes that are at that level
list of int level_in_interests
one per piece, the level that each piece is at in the interests
int numgot
the number of pieces this peer has
list of int numhaves
the number of copies of each piece in non-seeding peers
int numpieces
total number of pieces in the download
dictionary past_ips
the IPs that have previously connected in super-seed mode, keys are IP addresses, values are the piece have that was last sent to the peer
list of int pos_in_interests
the position within the interest level that each piece is at
list of int priority
the priority of each piece:
int priority_step
the difference bewteen priority levels 0, 1, and 2
int rarest_first_cutoff
number of completed piece downloads at which to switch from random piece selection to rarest first
int rarest_first_priority_cutoff
the number of peers which need to have a piece before other partials take priority over rarest first
dictionary removed_partials
keys are the pieces that were started but then disabled
dictionary seed_connections
connections that have been made in super-seed mode, keys are Connecter.Connection, values are the piece have that was last sent to the peer
list of int seed_got_haves
the number of copies of pieces in super-seed mode
float seed_time
the time when the first peer was seen in super-seed mode
int seeds_connected
the number of connected seeds
list of int started
the pieces that have been requested for download
boolean superseed
whether we are in super-seed mode
int totalcount
the total number of copies of all pieces in non-seeding peers
Method Details [hide private]

__init__(self, numpieces, rarest_first_cutoff=1, rarest_first_priority_cutoff=3, priority_step=20)
(Constructor)

source code 
Initialize the instance and the piece interests.
Parameters:
  • numpieces (int) - total number of pieces in the download
  • rarest_first_cutoff (int) - number of completed piece downloads at which to switch from random piece selection to rarest first (optional, defaults to 1)
  • rarest_first_priority_cutoff (int) - the number of peers which need to have a piece before other partials take priority over rarest first (optional, defaults to 3)
  • priority_step (int) - the difference bewteen priority levels 0, 1, and 2 (optional, defaults to 20)

got_have(self, piece)

source code 
Process a piece that has a new copy found.
Parameters:
  • piece (int) - the piece that was copied

lost_have(self, piece)

source code 
Process a piece that lost a copy.
Parameters:
  • piece (int) - the piece that lost a copy

_shift_over(self, piece, l1, l2)

source code 
Remove a piece from an old interest level to a new one.
Parameters:
  • piece (int) - the piece that is to be moved
  • l1 (list of int) - the old interest level list
  • l2 (list of int) - the new interest level list

requested(self, piece)

source code 
Add a piece that a request has been sent for to the list of started pieces.
Parameters:
  • piece (int) - the piece that is started

_remove_from_interests(self, piece, keep_partial=True)

source code 
Remove a piece from the interests.
Parameters:
  • piece (int) - the piece that is to be removed
  • keep_partial (boolean) - if the piece has been started, whether to keep a note of that so that if it becomes interesting again it can be immediately added to the list of started pieces (optional, defaults to False)

complete(self, piece)

source code 
Process a successfully received piece.
Parameters:
  • piece (int) - the piece that was received

next(self, haves, wantfunc, complete_first=True)

source code 
Choose a piece to request to download next from a peer.
Parameters:
  • haves (list of int) - the list of pieces that the peer has
  • wantfunc (method) - a method that returns True if the piece is desired
  • complete_first (boolean) - whether to complete a partially dowloaded piece before requsting a new one (optional, defaults to False)
Returns: int
the index of the piece to download

am_I_complete(self)

source code 
Determine if the download is complete.
Returns: boolean
whether the download is complete

bump(self, piece)

source code 

Move a piece to the end of its interest level.

Reduces the priority for downloading this piece, unless it is the only one in its level.
Parameters:
  • piece (int) - the piece that is to be downgraded

set_priority(self, piece, p)

source code 
Adjust the priority for a piece.
Parameters:
  • piece (int) - the piece that is to be prioritised
  • p (int) - the new priority for the piece
Returns: boolean
whether the downloader should try requesting more

is_blocked(self, piece)

source code 
Determine whether a piece is disabled.
Parameters:
  • piece (int) - the piece that is to be checked
Returns: boolean
whether the priority is to not download the piece

next_have(self, connection, looser_upload)

source code 
Determine the next piece to tell a peer we have in super-seed mode.
Parameters:
  • connection (Connecter.Connection) - the peer connection the have will be sent on
  • looser_upload (boolean) - whether to be looser in determining the piece
Returns: int
the piece index to send in the have message, or -1 if something has gone wrong and the connection is to be closed

lost_peer(self, connection)

source code 
Process a lost peer in super-seed mode.
Parameters:

Instance Variable Details [hide private]

priority

the priority of each piece:
   -1 -- do not download
    0 -- highest priority
    1 -- medium priority
    2 -- lowest priority
Type:
list of int