Class Torrent


  • public class Torrent
    extends Object
    • 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 either MessageBitfield or one or more MessageHave.
        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:
        true when the torrent is currently downloading the metadata, otherwise false
      • 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 index
        offset - The offset within the piece
        data - 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 with setFileSet(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
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • setPieceSelector

        public void setPieceSelector​(IPieceSelector downloadRegulator)