public class SessionHandle
extends java.lang.Object
This class belongs to a middle logical layer of abstraction. It's a wrapper of the underlying swig session object (from libtorrent), but it does not expose all the raw features.
| Modifier and Type | Field and Description |
|---|---|
static remove_flags_t |
DELETE_FILES
Delete the files belonging to the torrent from disk,
including the part-file, if there is one.
|
static remove_flags_t |
DELETE_PARTFILE
Delete just the part-file associated with this torrent.
|
static int |
DHT_ANNOUNCE_IMPLIED_PORT |
static int |
DHT_ANNOUNCE_SEED |
static int |
DHT_ANNOUNCE_SSL_TORRENT |
static reopen_network_flags_t |
REOPEN_MAP_PORTS
This option indicates if the ports are mapped using natpmp
and UPnP.
|
protected session_handle |
s |
static save_state_flags_t |
SAVE_DHT_SETTINGS
Saves
DhtSettings. |
static save_state_flags_t |
SAVE_DHT_STATE
Saves dht state such as nodes and node-id, possibly accelerating
joining the DHT if provided at next session startup.
|
static save_state_flags_t |
SAVE_SETTINGS
Saves settings (i.e.
|
| Constructor and Description |
|---|
SessionHandle(session_handle s) |
| Modifier and Type | Method and Description |
|---|---|
void |
addDhtNode(Pair<java.lang.String,java.lang.Integer> node)
takes a host name and port pair.
|
void |
addExtension(Plugin plugin) |
int[] |
addPortMapping(PortmapProtocol t,
int externalPort,
int localPort)
Adds a port forwarding on UPnP and/or NAT-PMP, using PCP if supported,
whichever is enabled.
|
TorrentHandle |
addTorrent(AddTorrentParams params,
ErrorCode ec)
You add torrents through the
addTorrent(AddTorrentParams, ErrorCode)
function where you give an object with all the parameters. |
void |
applySettings(SettingsPack sp)
Applies the settings specified by the settings pack
sp. |
void |
asyncAddTorrent(AddTorrentParams params) |
void |
deletePortMapping(int handle) |
void |
dhtAnnounce(Sha1Hash infoHash) |
void |
dhtAnnounce(Sha1Hash infoHash,
int port,
int flags) |
void |
dhtDirectRequest(UdpEndpoint endp,
Entry entry) |
void |
dhtDirectRequest(UdpEndpoint endp,
Entry entry,
long userdata) |
void |
dhtGetItem(byte[] key,
byte[] salt)
Query the DHT for a mutable item under the public key
key. |
void |
dhtGetItem(Sha1Hash target)
Query the DHT for an immutable item at the target hash.
|
void |
dhtGetPeers(Sha1Hash infoHash) |
void |
dhtPutItem(byte[] publicKey,
byte[] privateKey,
Entry entry,
byte[] salt) |
Sha1Hash |
dhtPutItem(Entry entry)
Store the given bencoded data as an immutable item in the DHT.
|
TorrentHandle |
findTorrent(Sha1Hash infoHash)
Looks for a torrent with the given info-hash.
|
int |
getListenPort()
returns the port we ended up listening on.
|
int |
getSslListenPort() |
boolean |
isDhtRunning() |
boolean |
isListening()
will tell you whether or not the session has
successfully opened a listening port.
|
boolean |
isPaused() |
boolean |
isValid() |
void |
loadState(byte[] data)
Same as calling
loadState(byte[], save_state_flags_t) with all
save state flags. |
void |
loadState(byte[] data,
save_state_flags_t flags)
Loads all session settings, including DHT settings,
encryption settings and proxy settings.
|
void |
pause()
Pausing the session has the same effect as pausing every torrent in
it, except that torrents will not be resumed by the auto-manage
mechanism.
|
void |
postDhtStats()
This will cause a dht_stats_alert to be posted.
|
void |
postSessionStats()
This function will post a
SessionStatsAlert object, containing a
snapshot of the performance counters from the internals of libtorrent. |
void |
postTorrentUpdates()
This functions instructs the session to post the
StateUpdateAlert,
containing the status of all torrents whose state changed since the
last time this function was called. |
void |
postTorrentUpdates(status_flags_t flags)
This functions instructs the session to post the
StateUpdateAlert,
containing the status of all torrents whose state changed since the
last time this function was called. |
void |
removeTorrent(TorrentHandle th)
This method will close all peer connections associated with the torrent and tell the
tracker that we've stopped participating in the swarm.
|
void |
removeTorrent(TorrentHandle th,
remove_flags_t options)
This method will close all peer connections associated with the torrent and tell the
tracker that we've stopped participating in the swarm.
|
void |
reopenNetworkSockets()
Instructs the session to reopen all listen and outgoing sockets.
|
void |
reopenNetworkSockets(reopen_network_flags_t options)
Instructs the session to reopen all listen and outgoing sockets.
|
void |
resume()
Resuming will restore the torrents to their previous paused
state.
|
byte[] |
saveState()
Same as calling
saveState(save_state_flags_t) with all save state flags. |
byte[] |
saveState(save_state_flags_t flags)
Loads and saves all session settings, including dht settings,
encryption settings and proxy settings.
|
SettingsPack |
settings() |
session_handle |
swig() |
java.util.List<TorrentHandle> |
torrents()
Returns a list of torrent handles to all the
torrents currently in the session.
|
protected final session_handle s
public static final save_state_flags_t SAVE_SETTINGS
SettingsPack).public static final save_state_flags_t SAVE_DHT_SETTINGS
DhtSettings.public static final save_state_flags_t SAVE_DHT_STATE
public static final remove_flags_t DELETE_FILES
public static final remove_flags_t DELETE_PARTFILE
public static final reopen_network_flags_t REOPEN_MAP_PORTS
public static final int DHT_ANNOUNCE_SEED
public static final int DHT_ANNOUNCE_IMPLIED_PORT
public static final int DHT_ANNOUNCE_SSL_TORRENT
public SessionHandle(session_handle s)
s - the native objectpublic session_handle swig()
public boolean isValid()
public byte[] saveState(save_state_flags_t flags)
entry that is returned
as a bencoded byte array.
The flags argument passed in to this method can be used to
filter which parts of the session state to save. By default, all state
is saved (except for the individual torrents).
public byte[] saveState()
saveState(save_state_flags_t) with all save state flags.public void loadState(byte[] data,
save_state_flags_t flags)
This method expects a byte array that it is a bencoded buffer.
The flags argument passed in to this method can be used to
filter which parts of the session state to load. By default, all state
is restored (except for the individual torrents).
data - the bencoded byte arraypublic void loadState(byte[] data)
loadState(byte[], save_state_flags_t) with all
save state flags.public void postTorrentUpdates(status_flags_t flags)
StateUpdateAlert,
containing the status of all torrents whose state changed since the
last time this function was called.
Only torrents who has the state subscription flag set will be
included. This flag is on by default. See AddTorrentParams.
the flags argument is the same as for torrent_handle::status().
flags - or-combination of native valuespublic void postTorrentUpdates()
StateUpdateAlert,
containing the status of all torrents whose state changed since the
last time this function was called.
Only torrents who has the state subscription flag set will be included.
public void postSessionStats()
SessionStatsAlert object, containing a
snapshot of the performance counters from the internals of libtorrent.
To interpret these counters, query the session via
session_stats_metrics().public void postDhtStats()
public TorrentHandle findTorrent(Sha1Hash infoHash)
TorrentHandle to that torrent
is returned.
In case the torrent cannot be found, a null is returned.
infoHash - public java.util.List<TorrentHandle> torrents()
public TorrentHandle addTorrent(AddTorrentParams params, ErrorCode ec)
addTorrent(AddTorrentParams, ErrorCode)
function where you give an object with all the parameters.
The addTorrent overloads will block
until the torrent has been added (or failed to be added) and returns
an error code and a TorrentHandle. In order to add torrents more
efficiently, consider using asyncAddTorrent(AddTorrentParams)
which returns immediately, without waiting for the torrent to add.
Notification of the torrent being added is sent as
AddTorrentAlert.
The TorrentHandle returned by this method can be used to retrieve
information about the torrent's progress, its peers etc. It is also
used to abort a torrent.
If the torrent you are trying to add already exists in the session (is
either queued for checking, being checked or downloading)
the error code will be set to libtorrent_errors.duplicate_torrent
unless flag_duplicate_is_error
is set to false. In that case, addTorrent will return the handle
to the existing torrent.
All torrent handles must be destructed before the session is destructed!
params - the parameters to create the torrent downloadec - the error code if no torrent handle was createdpublic void asyncAddTorrent(AddTorrentParams params)
public void removeTorrent(TorrentHandle th, remove_flags_t options)
The optional second argument options can be used to delete all the files downloaded by this torrent. To do so, pass in the value session::delete_files. The removal of the torrent is asynchronous, there is no guarantee that adding the same torrent immediately after it was removed will not throw a libtorrent_exception exception. Once the torrent is deleted, a torrent_deleted_alert is posted.
th - the handlepublic void removeTorrent(TorrentHandle th)
th - public void pause()
public void resume()
public boolean isPaused()
public boolean isDhtRunning()
public void addDhtNode(Pair<java.lang.String,java.lang.Integer> node)
node - public void applySettings(SettingsPack sp)
sp. This is an
asynchronous operation that will return immediately and actually apply
the settings to the main thread of libtorrent some time later.sp - the settingspublic SettingsPack settings()
public int[] addPortMapping(PortmapProtocol t, int externalPort, int localPort)
deletePortMapping(int)
to remove it.t - the mapping protocolexternalPort - the external portlocalPort - the local portpublic void deletePortMapping(int handle)
public void reopenNetworkSockets(reopen_network_flags_t options)
It's useful in the case your platform doesn't support the built in IP notifier mechanism, or if you have a better more reliable way to detect changes in the IP routing table.
options - the optionspublic void reopenNetworkSockets()
It's useful in the case your platform doesn't support the built in IP notifier mechanism, or if you have a better more reliable way to detect changes in the IP routing table.
public void dhtGetItem(Sha1Hash target)
DhtImmutableItemAlert.target - public void dhtGetItem(byte[] key,
byte[] salt)
key.
this is an ed25519 key. The salt argument is optional and may be left
as an empty string if no salt is to be used.
if the item is found in the DHT, a DhtMutableItemAlert is
posted.
key - salt - public Sha1Hash dhtPutItem(Entry entry)
entry - public void dhtPutItem(byte[] publicKey,
byte[] privateKey,
Entry entry,
byte[] salt)
public void dhtGetPeers(Sha1Hash infoHash)
infoHash - public void dhtAnnounce(Sha1Hash infoHash, int port, int flags)
infoHash - port - flags - public void dhtAnnounce(Sha1Hash infoHash)
infoHash - public void dhtDirectRequest(UdpEndpoint endp, Entry entry, long userdata)
endp - entry - userdata - public void dhtDirectRequest(UdpEndpoint endp, Entry entry)
endp - entry - public int getListenPort()
public int getSslListenPort()
public boolean isListening()
true if listeningpublic void addExtension(Plugin plugin)