|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.ObjectjBittorrentAPI.DownloadManager
public class DownloadManager
Object that manages all concurrent downloads. It chooses which piece to request to which peer.
| Field Summary | |
|---|---|
private ConnectionListener |
cl
|
private byte[] |
clientID
|
private java.util.BitSet |
isComplete
|
private java.util.BitSet |
isRequested
|
private long |
lastTrackerContact
|
private long |
lastUnchoking
|
private long |
left
|
private long |
length
|
private int |
maxConnectionNumber
|
private int |
nbOfFiles
|
private int |
nbPieces
|
private short |
optimisticUnchoke
|
private java.io.RandomAccessFile[] |
output_files
|
private java.util.LinkedHashMap<java.lang.String,java.util.BitSet> |
peerAvailabilies
|
private java.util.LinkedHashMap<java.lang.String,Peer> |
peerList
|
private Piece[] |
pieceList
|
private PeerUpdater |
pu
|
private java.util.TreeMap<java.lang.String,DownloadTask> |
task
|
private TorrentFile |
torrent
|
private java.util.List |
unchokeList
|
(package private) java.util.LinkedHashMap |
unchoken
|
| Constructor Summary | |
|---|---|
DownloadManager(TorrentFile torrent,
byte[] clientID)
Create a new manager according to the given torrent and using the client id provided |
|
| Method Summary | |
|---|---|
void |
addActiveTask(java.lang.String id,
DownloadTask dt)
Add the download task to the list of active (i.e. |
void |
blockUntilCompletion()
Periodically call the unchokePeers method. |
int |
cardinalityR()
Returns the number of pieces currently requested to peers |
int |
checkTempFiles()
Check the existence of the files specified in the torrent and if necessary, create them |
private int |
choosePiece2Download(java.lang.String id)
Returns the index of the piece that could be downloaded by the peer in parameter |
void |
closeTempFiles()
Close all open files |
void |
connectionAccepted(java.net.Socket s)
Called when a new peer connects to the client. |
byte[] |
getBitField()
Compute the bitfield byte array from the isComplete BitSet |
Piece |
getPiece(int index)
Returns the piece with the given index |
byte[] |
getPieceBlock(int piece,
int begin,
int length)
Get a piece block from the existing file(s) |
byte[] |
getPieceFromFiles(int piece)
Load piece data from the existing files |
boolean |
isComplete()
Check if the current download is complete |
boolean |
isPieceComplete(int piece)
Check if the piece with the given index is complete and verified |
boolean |
isPieceRequested(int piece)
Check if the piece with the given index is requested by a peer |
private void |
optimisticUnchoke()
|
void |
peerAvailability(java.lang.String peerID,
java.util.BitSet has)
Update the piece availabilities for a given peer |
void |
peerReady(java.lang.String peerID)
Received when a task is ready to download or upload. |
void |
peerRequest(java.lang.String peerID,
int piece,
int begin,
int length)
Received when a peer request a piece. |
void |
pieceCompleted(java.lang.String peerID,
int i,
boolean complete)
Received when a piece has been fully downloaded by a task. |
void |
pieceRequested(int i,
boolean requested)
Set the status of the piece to requested or not |
java.lang.String |
requestedBits()
Returns a String representing the piece being requested by peers. |
void |
savePiece(int piece)
Save a piece in the corresponding file(s) |
void |
setComplete(int piece,
boolean is)
Mark a piece as complete or not according to the parameters |
void |
setRequested(int piece,
boolean is)
Mark a piece as requested or not according to the parameters |
boolean |
startListening(int minPort,
int maxPort)
Create the ConnectionListener to accept incoming connection from peers |
void |
startTrackerUpdate()
Create and start the peer updater to retrieve new peers sharing the file |
void |
stopTrackerUpdate()
Stop the tracker updates |
void |
taskCompleted(java.lang.String id,
int reason)
Removes a task and peer after the task sends a completion message. |
boolean |
testComplete(int piece)
|
private void |
unchokePeers()
Choose which of the connected peers should be unchoked and authorized to upload from this client. |
void |
updateFailed(int error,
java.lang.String message)
Called when an update try fail. |
void |
updatePeerList(java.util.LinkedHashMap list)
Given the list in parameter, check if the peers are already present in the peer list. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private ConnectionListener cl
private byte[] clientID
private java.util.BitSet isComplete
private java.util.BitSet isRequested
private long lastTrackerContact
private long lastUnchoking
private long left
private long length
private int maxConnectionNumber
private int nbOfFiles
private int nbPieces
private short optimisticUnchoke
private java.io.RandomAccessFile[] output_files
private java.util.LinkedHashMap<java.lang.String,java.util.BitSet> peerAvailabilies
private java.util.LinkedHashMap<java.lang.String,Peer> peerList
private Piece[] pieceList
private PeerUpdater pu
private java.util.TreeMap<java.lang.String,DownloadTask> task
private TorrentFile torrent
private java.util.List unchokeList
java.util.LinkedHashMap unchoken
| Constructor Detail |
|---|
public DownloadManager(TorrentFile torrent,
byte[] clientID)
torrent - TorrentFileclientID - byte[]| Method Detail |
|---|
public void addActiveTask(java.lang.String id,
DownloadTask dt)
addActiveTask in interface DTListenerid - Stringdt - DownloadTaskpublic void blockUntilCompletion()
public int cardinalityR()
public int checkTempFiles()
private int choosePiece2Download(java.lang.String id)
id - The id of the peer that wants to download
public void closeTempFiles()
public void connectionAccepted(java.net.Socket s)
connectionAccepted in interface ConListenerInterfaces - Socketpublic byte[] getBitField()
public Piece getPiece(int index)
index - The piece index
public byte[] getPieceBlock(int piece,
int begin,
int length)
piece - intbegin - intlength - int
public byte[] getPieceFromFiles(int piece)
piece - int
public boolean isComplete()
public boolean isPieceComplete(int piece)
piece - The piece index
public boolean isPieceRequested(int piece)
piece - The piece index
private void optimisticUnchoke()
public void peerAvailability(java.lang.String peerID,
java.util.BitSet has)
peerAvailability in interface DTListenerpeerID - Stringhas - BitSetpublic void peerReady(java.lang.String peerID)
peerReady in interface DTListenerpeerID - String
public void peerRequest(java.lang.String peerID,
int piece,
int begin,
int length)
peerRequest in interface DTListenerpeerID - Stringpiece - intbegin - intlength - int
public void pieceCompleted(java.lang.String peerID,
int i,
boolean complete)
pieceCompleted in interface DTListenerpeerID - Stringi - intcomplete - boolean
public void pieceRequested(int i,
boolean requested)
pieceRequested in interface DTListeneri - intrequested - booleanpublic java.lang.String requestedBits()
public void savePiece(int piece)
piece - int
public void setComplete(int piece,
boolean is)
piece - The index of the piece to be updatedis - True if the piece is now complete, false otherwise
public void setRequested(int piece,
boolean is)
piece - The index of the piece to be updatedis - True if the piece is now requested, false otherwise
public boolean startListening(int minPort,
int maxPort)
minPort - The minimal port number this client should listen onmaxPort - The maximal port number this client should listen on
public void startTrackerUpdate()
public void stopTrackerUpdate()
public void taskCompleted(java.lang.String id,
int reason)
taskCompleted in interface DTListenerid - Task idendityreason - Reason of the completionpublic boolean testComplete(int piece)
private void unchokePeers()
public void updateFailed(int error,
java.lang.String message)
updateFailed in interface PeerUpdateListenererror - intmessage - Stringpublic void updatePeerList(java.util.LinkedHashMap list)
updatePeerList in interface PeerUpdateListenerlist - LinkedHashMap
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||