Class TorrentClient


  • public class TorrentClient
    extends Object
    The Torrent Client is the main entry point for the configuration and initiation of downloads/uploads.
    • Method Detail

      • download

        public void download​(Torrent torrent,
                             Collection<String> trackerUrls)
        Initiates the downloading of a torrent.
        Parameters:
        torrent - The torrent to download.
        trackerUrls - The trackers which are known for this torrent.
      • download

        public void download​(Torrent torrent)
        Initiates the downloading of a torrent.
        Parameters:
        torrent - The torrent to download.
      • shutdown

        public void shutdown()
        Shuts down all components of the TorrentClient.
      • createUniqueTransactionId

        public int createUniqueTransactionId()
      • addDiskJob

        public void addDiskJob​(IDiskJob task)
        Submits the disk job to be processed by the IO manager.
        Parameters:
        task - The disk job to execute.
      • getConnectingCountFor

        public int getConnectingCountFor​(Torrent torrent)
        Calculates how many connections are assigned to the torrent but haven't passed the BitTorrent handshake yet.
        Parameters:
        torrent - The torrent for which connections must be counted.
        Returns:
        The amount of pending peers.
      • getTrackersFor

        public List<ITracker> getTrackersFor​(Torrent torrent)
        Gets all trackers which know the given torrent
        Parameters:
        torrent - the torrent which the tracker must support
        Returns:
        a collection of trackers which support the given torrent
      • getConnectionDegradation

        public ConnectionDegradation getConnectionDegradation()
        Gets the configured connection degradation rules.
        Returns:
        The socket degradation rules.
      • getPhaseRegulator

        public PhaseRegulator getPhaseRegulator()
        Gets the PhaseRegulator which manages the ordering of the download states.
        Returns:
        The configured phase regulator.
      • getPeerConnector

        public IPeerConnector getPeerConnector()
        Gets the IPeerConnector which connects new peers
        Returns:
        The peer connector implementation
      • getExtensionBytes

        public byte[] getExtensionBytes()
        Gets the eight extension bytes which represent which BitTorrent extensions are enabled on this client.
        Returns:
        The extension bytes
      • getPeerId

        public byte[] getPeerId()
        Gets the 20-byte peer ID associated to this tracker manager
        Returns:
        The peer ID
      • getModule

        public <T extends IModuleOptional<T> getModule​(Class<T> type)
        Gets the module instance if it is registered to this Torrent Client.
        Type Parameters:
        T - The module type.
        Parameters:
        type - The module class.
        Returns:
        The module instance or Optional.empty() if not found.
      • getModules

        public Collection<IModule> getModules()
        Gets an unmodifiable view of the registered modules to this torrent client.
        Returns:
        The collection of modules.
      • getTorrentByHash

        public Optional<Torrent> getTorrentByHash​(byte[] torrentHash)
        Gets the torrent associated with the given hash.
        Parameters:
        torrentHash - The BTIH of the torrent
        Returns:
        The torrent if known.
      • getTorrentCount

        public int getTorrentCount()
        Returns:
        The amount of torrents that are being downloaded.
      • getRequestLimiter

        public IRequestLimiter getRequestLimiter()
        Returns:
        The configured limiter.
      • getHandshakeHandler

        public BitTorrentHandshakeHandler getHandshakeHandler()
        Returns:
        A handler instance which is able to process the BitTorrent handshake on freshly connected sockets.
      • getSettings

        public TorrentClientSettings getSettings()
        Returns:
        The configuration of the Torrent Client