Package org.johnnei.javatorrent
Class TorrentClient
- java.lang.Object
-
- org.johnnei.javatorrent.TorrentClient
-
public class TorrentClient extends Object
The Torrent Client is the main entry point for the configuration and initiation of downloads/uploads.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTorrentClient.Builder
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddDiskJob(IDiskJob task)Submits the disk job to be processed by the IO manager.intcreateUniqueTransactionId()voiddownload(Torrent torrent)Initiates the downloading of a torrent.voiddownload(Torrent torrent, Collection<String> trackerUrls)Initiates the downloading of a torrent.intgetConnectingCountFor(Torrent torrent)Calculates how many connections are assigned to the torrent but haven't passed the BitTorrent handshake yet.ConnectionDegradationgetConnectionDegradation()Gets the configured connection degradation rules.intgetDownloadPort()Deprecated.UseTorrentClientSettings.getAcceptingPort()instead.ScheduledExecutorServicegetExecutorService()Gets theScheduledExecutorServicewhich will execute the small tasksbyte[]getExtensionBytes()Gets the eight extension bytes which represent which BitTorrent extensions are enabled on this client.BitTorrentHandshakeHandlergetHandshakeHandler()MessageFactorygetMessageFactory()Gets the message factory for this client<T extends IModule>
Optional<T>getModule(Class<T> type)Gets the module instance if it is registered to this Torrent Client.Collection<IModule>getModules()Gets an unmodifiable view of the registered modules to this torrent client.IPeerConnectorgetPeerConnector()Gets theIPeerConnectorwhich connects new peersIPeerDistributorgetPeerDistributor()byte[]getPeerId()Gets the 20-byte peer ID associated to this tracker managerPhaseRegulatorgetPhaseRegulator()Gets thePhaseRegulatorwhich manages the ordering of the download states.IRequestLimitergetRequestLimiter()TorrentClientSettingsgetSettings()Optional<Torrent>getTorrentByHash(byte[] torrentHash)Gets the torrent associated with the given hash.intgetTorrentCount()List<ITracker>getTrackersFor(Torrent torrent)Gets all trackers which know the given torrentvoidshutdown()Shuts down all components of the TorrentClient.
-
-
-
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
-
getMessageFactory
public MessageFactory getMessageFactory()
Gets the message factory for this client- Returns:
- The
MessageFactory
-
getConnectionDegradation
public ConnectionDegradation getConnectionDegradation()
Gets the configured connection degradation rules.- Returns:
- The socket degradation rules.
-
getPhaseRegulator
public PhaseRegulator getPhaseRegulator()
Gets thePhaseRegulatorwhich manages the ordering of the download states.- Returns:
- The configured phase regulator.
-
getExecutorService
public ScheduledExecutorService getExecutorService()
Gets theScheduledExecutorServicewhich will execute the small tasks- Returns:
- The executor service implementation
-
getPeerConnector
public IPeerConnector getPeerConnector()
Gets theIPeerConnectorwhich connects new peers- Returns:
- The peer connector implementation
-
getDownloadPort
@Deprecated public int getDownloadPort()
Deprecated.UseTorrentClientSettings.getAcceptingPort()instead.Gets the port at which we are listening for peers- Returns:
- The port at which we are listening
-
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 IModule> Optional<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.
-
getPeerDistributor
public IPeerDistributor getPeerDistributor()
- Returns:
- The configured
IPeerDistributorfor thisTorrentClient
-
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
-
-