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, not expose a very high level interface
like com.frostwire.jlibtorrent.Dht
.
Modifier and Type | Class and Description |
---|---|
static class |
SessionHandle.Options
Flags to be passed in to
removeTorrent(TorrentHandle, Options) . |
static class |
SessionHandle.ProtocolType
protocols used by
addPortMapping(ProtocolType, int, int) . |
static class |
SessionHandle.SaveStateFlags
Flags that determines which aspects of the session should be
saved when calling
saveState(long) |
Modifier and Type | Field and Description |
---|---|
protected session_handle |
s |
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 |
addDHTRouter(Pair<java.lang.String,java.lang.Integer> node)
adds the given endpoint to a list of DHT router nodes.
|
void |
addExtension(Plugin plugin) |
int |
addPortMapping(SessionHandle.ProtocolType t,
int externalPort,
int localPort)
add_port_mapping adds a port forwarding on UPnP and/or NAT-PMP,
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[], long) with all save state flags. |
void |
loadState(byte[] data,
long 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 state_update_alert,
containing the status of all torrents whose state changed since the
last time this function was called.
|
void |
postTorrentUpdates(TorrentHandle.StatusFlags flags)
This functions instructs the session to post the state_update_alert,
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,
SessionHandle.Options 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 |
resume()
Resuming will restore the torrents to their previous paused
state.
|
byte[] |
saveState()
Same as calling
saveState(long) with all save state flags. |
byte[] |
saveState(long 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 SessionHandle(session_handle s)
s
- public session_handle swig()
public boolean isValid()
public byte[] saveState(long flags)
saveState(long)
internally writes all keys to an entry
that's passed in,
which needs to either not be initialized, or initialized as a dictionary.
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).
com.frostwire.jlibtorrent.swig.session_handle.save_state_flags_t}
public byte[] saveState()
saveState(long)
with all save state flags.saveState(long)
public void loadState(byte[] data, long flags)
loadState(byte[], long)
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
- com.frostwire.jlibtorrent.swig.session_handle.save_state_flags_t}
public void loadState(byte[] data)
loadState(byte[], long)
with all save state flags.loadState(byte[], long)
public void postTorrentUpdates(TorrentHandle.StatusFlags flags)
Only torrents who has the state subscription flag set will be included. This flag is on by default. See add_torrent_params. the ``flags`` argument is the same as for torrent_handle::status(). see torrent_handle::status_flags_t.
flags
- public void postTorrentUpdates()
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 add_torrent_params.flags_t.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
- ec
- public void asyncAddTorrent(AddTorrentParams params)
public void removeTorrent(TorrentHandle th, SessionHandle.Options 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
- public 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 addDHTRouter(Pair<java.lang.String,java.lang.Integer> node)
An example routing node that you could typically add is ``router.bittorrent.com``.
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
- public SettingsPack settings()
public int addPortMapping(SessionHandle.ProtocolType t, int externalPort, int localPort)
t
- externalPort
- localPort
- public void deletePortMapping(int handle)
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()
public void addExtension(Plugin plugin)