Package org.johnnei.javatorrent.torrent
Class Torrent
- java.lang.Object
-
- org.johnnei.javatorrent.torrent.Torrent
-
public class Torrent extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTorrent.BuilderA builder to create new instances ofTorrent
-
Constructor Summary
Constructors Constructor Description Torrent(Torrent.Builder builder)Creates a new Torrent.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDiskJob(IDiskJob task)Adds a task to the IOManager of this torrentvoidaddPeer(Peer peer)Adds a peer to the torrent if not already registered to the torrent.voidaddUploadedBytes(long l)Adds the amount of bytes to the uploaded countvoidcheckProgress()Calculates the current progress based on all available fileSet on the HDDbooleanequals(Object obj)StringgetDisplayName()longgetDownloadedBytes()The amount of bytes downloadedintgetDownloadRate()Sums the download rates of all peers.TorrentFileSetgetFileSet()Gets the fileSet which are being downloaded within this torrent.intgetLeecherCount()Counts the amount of peers which don't have all pieces yet.MetadatagetMetadata()List<Peer>getPeers()Creates a copy of the list of connected peers.IPieceSelectorgetPieceSelector()The regulator which is managing this downloadIRequestLimitergetRequestLimiter()intgetSeedCount()Counts the amount of peers which have all pieces.longgetUploadedBytes()The amount of bytes we have uploaded this sessionintgetUploadRate()Sums the upload rates of all peers.inthashCode()booleanisDownloadingMetadata()If the Torrent should be downloading the metadata information.voidonReceivedBlock(AbstractFileSet fileSet, int index, int offset, byte[] data)Tells the torrent to save a block of datavoidpollRates()Polls all peers transfer speeds.voidremovePeer(Peer peer)Removes a peer from the torrent.voidsetFileSet(TorrentFileSet files)Sets the current set of fileSet this torrent is downloading.voidsetPieceSelector(IPieceSelector downloadRegulator)StringtoString()
-
-
-
Constructor Detail
-
Torrent
public Torrent(Torrent.Builder builder)
Creates a new Torrent.- Parameters:
builder- The builder with the components for the torrent.
-
-
Method Detail
-
addPeer
public void addPeer(Peer peer) throws IOException
Adds a peer to the torrent if not already registered to the torrent. Upon accepting the socket will be marked as passed handshake and the currently available message will be shared via eitherMessageBitfieldor one or moreMessageHave.- Parameters:
peer- The peer to add.- Throws:
IOException
-
removePeer
public void removePeer(Peer peer)
Removes a peer from the torrent. This will also clean up the peer state which affects the progress state of the torrent (ex. pending block requests).- Parameters:
peer- the peer to remove.
-
getDisplayName
public String getDisplayName()
-
isDownloadingMetadata
public boolean isDownloadingMetadata()
If the Torrent should be downloading the metadata information. Depending on the installed modules the torrent might be stuck at this point. BEP 10 and UT_METADATA extension must be available to download metadata.- Returns:
truewhen the torrent is currently downloading the metadata, otherwisefalse
-
onReceivedBlock
public void onReceivedBlock(AbstractFileSet fileSet, int index, int offset, byte[] data)
Tells the torrent to save a block of data- Parameters:
fileSet- The fileset for which the block of data has been received.index- The piece indexoffset- The offset within the piecedata- The bytes to be stored
-
addDiskJob
public void addDiskJob(IDiskJob task)
Adds a task to the IOManager of this torrent- Parameters:
task- The task to add
-
checkProgress
public void checkProgress()
Calculates the current progress based on all available fileSet on the HDD
-
addUploadedBytes
public void addUploadedBytes(long l)
Adds the amount of bytes to the uploaded count- Parameters:
l- The amount of bytes to add
-
setFileSet
public void setFileSet(TorrentFileSet files)
Sets the current set of fileSet this torrent is downloading.- Parameters:
files- The file set.
-
getMetadata
public Metadata getMetadata()
-
pollRates
public void pollRates()
Polls all peers transfer speeds.
-
getFileSet
public TorrentFileSet getFileSet()
Gets the fileSet which are being downloaded within this torrent. This could be the metadata of the torrent (.torrent file), the fileSet in the torrent or something else if a module changed it withsetFileSet(TorrentFileSet).- Returns:
- The set of fileSet being downloaded.
- See Also:
setFileSet(TorrentFileSet)
-
getDownloadRate
public int getDownloadRate()
Sums the download rates of all peers.- Returns:
- The sum of all download rates
- See Also:
pollRates()
-
getUploadRate
public int getUploadRate()
Sums the upload rates of all peers.- Returns:
- The sum of all upload rates
- See Also:
pollRates()
-
getSeedCount
public int getSeedCount()
Counts the amount of peers which have all pieces.- Returns:
- The amount of connected seeders.
-
getLeecherCount
public int getLeecherCount()
Counts the amount of peers which don't have all pieces yet.- Returns:
- The amount of connected leechers.
-
getPeers
public List<Peer> getPeers()
Creates a copy of the list of connected peers.- Returns:
- The list of connected peers.
-
getDownloadedBytes
public long getDownloadedBytes()
The amount of bytes downloaded- Returns:
- The amount of bytes downloaded this session
-
getUploadedBytes
public long getUploadedBytes()
The amount of bytes we have uploaded this session- Returns:
- The amount of bytes uploaded this session.
-
getPieceSelector
public IPieceSelector getPieceSelector()
The regulator which is managing this download- Returns:
- The current assigned regulator
-
setPieceSelector
public void setPieceSelector(IPieceSelector downloadRegulator)
-
getRequestLimiter
public IRequestLimiter getRequestLimiter()
-
-