gps.protocol.BT.algorithm
Class BTAlgorithmPieceSelection
java.lang.Object
gps.protocol.BT.algorithm.BTAlgorithmPieceSelection
public class BTAlgorithmPieceSelection
- extends java.lang.Object
selects a suitable piece to request.
BitTorrent uses strict priority as a first policy for piece
selection, i.e., once a single sub-piece has been requested,
the remaining sub-pieces from that particular piece are
requested before sub-pieces from any other piece. This does
a good job of getting complete pieces as quickly as possible.
When selecting which piece to start downloading next, peers
generally download pieces which the fewest of their own peers
have first, a technique referred to as 'rarest first'.
An exception to rarest first is when downloading starts. At
that time, the peer has nothing to upload, so it's important
to get a complete piece as quickly as possible. Rare pieces
are generally only present on one peer, so they would be
downloaded slower than pieces which are present on multiple
peers for which it's possible to download sub-pieces from
different places. For this reason, pieces to download are
selected at random until the first complete piece is assembled,
and then the strategy changes to rarest first.
once all sub-pieces which a peer doesn't have are actively being
requested, it sends requests for all sub-pieces to all peers.
Cancels are set for sub-pieces which arrive to keep too much
bandwidth from being wasted on redundant sends.
- Version:
- 1.0, 5/10/2005
- Author:
- Weishuai Yang
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
BTAlgorithmPieceSelection
public BTAlgorithmPieceSelection(int n)
- constructs a piece selection object
- Parameters:
n - seed for random object
selectPiece
public int selectPiece(BTSession bts,
BTPeer p)
- select a suitable piece for request
- Parameters:
bts - downloading sessionp - bt peer from which to request
- Returns:
- selected piece index, negative if can't find one