java.lang.Object
org.klomp.snark.TorrentDest
Bundles the transient I2P destination, session, server socket, DHT instance, and UDP tracker client for one torrent or for a pool of torrents, so that all of a torrent's network activity goes out through its own identity. Created lazily when a torrent starts, destroyed when its last torrent stops, and recreated by the pooling logic when a pool index is reused. Not persisted; a new destination is generated on each start.
Field Summary
Modifier and TypeFieldDescriptionprivate intTunnel quantity most recently pushed to this pool's session byIdleChecker, so each pool's floor can be judged against what it was actually given rather than against the client-wide configured option.private final I2PAppContextThe context the destination runs in.private TorrentKRPCThe DHT node serving the torrent, if any.private final StringBase64-encoded info hash of the first torrent assigned, for thread names and logs.private final I2PSocketManagerOpens this destination's sockets.Assigned torrent names by Base64-encoded info hash key, for the pool tooltip.private final int-1 when dedicated to a single torrent, else the shared pool index.private final intSequential pool number for the "I2PSnark - Pool N" nickname, -1 when dedicated.private final I2PServerSocketAccepts incoming connections for the torrent.Assigned torrents by Base64-encoded info hash key, guarded by synchronized methods.private UDPTrackerClientThe UDP tracker client, if any.static final StringSession property carrying the pool's torrent names, for the /tunnels pool tooltip.Constructor Summary
ConstructorsConstructorDescriptionTorrentDest(I2PAppContext ctx, String key, int poolIndex, int poolNum, I2PSocketManager mgr, I2PServerSocket serverSocket) Assign a torrent to this destination.Method Summary
Modifier and TypeMethodDescriptionvoidAssign a torrent to this destination, serving its infohash on the DHT instance when one already runs, and updating the pool tooltip and tunnel nickname.voiddestroy()Stop the DHT instance and UDP tracker client and destroy the destination.intThe tunnel quantity last applied to this pool's own session, which is also its floor.Lazily create the DHT instance on this destination's session, sharing the main instance's routing table, tracker, and blacklist, serving tracker queries only for the torrents assigned here.getKey()The Base64-encoded info hash of the first torrent assigned.This router's own destination.intIdentifies the shared tunnel pool serving this destination.intThe sequential pool number shown in the tunnel nickname "I2PSnark - Pool <n>", or -1 when dedicated to a single torrent.The inbound server socket for this destination.The socket manager of the transient destination this pool's traffic uses.getUDPTracker(I2PSnarkUtil util) Lazily create the UDP tracker client on this destination's session.booleanWhether any torrent is assigned to this destination, so it still needs its tunnel floor even with no peers connected yet.voidsetAppliedTunnelQuantity(int qty) Record the tunnel quantity pushed to this pool's session.booleanRemove a torrent from this destination, stopping its DHT serving when an instance runs and updating the pool tooltip and tunnel nickname.private voidPush the pool's torrent names to the session's i2psnark.poolMembers property, which the console reads to render the pool tooltip on the tunnels page.
Field Details
_context
The context the destination runs in._key
Base64-encoded info hash of the first torrent assigned, for thread names and logs._poolIndex
private final int _poolIndex-1 when dedicated to a single torrent, else the shared pool index._poolNum
private final int _poolNumSequential pool number for the "I2PSnark - Pool N" nickname, -1 when dedicated._mgr
Opens this destination's sockets._serverSocket
Accepts incoming connections for the torrent.PROP_POOL_MEMBERS
Session property carrying the pool's torrent names, for the /tunnels pool tooltip.- See Also:
_appliedTunnelQuantity
private volatile int _appliedTunnelQuantityTunnel quantity most recently pushed to this pool's session byIdleChecker, so each pool's floor can be judged against what it was actually given rather than against the client-wide configured option. Starts at the floor, which is howI2PSnarkUtilcreates a pool._torrents
_names
_dht
The DHT node serving the torrent, if any._udpTracker
The UDP tracker client, if any.
Constructor Details
TorrentDest
public TorrentDest(I2PAppContext ctx, String key, int poolIndex, int poolNum, I2PSocketManager mgr, I2PServerSocket serverSocket) Assign a torrent to this destination.- Parameters:
ctx- the application context supplying the logging and timing services this destination and its DHT and tracker clients needkey- Base64 encoding of the first torrent's info hashpoolIndex- the shared pool index, or -1 for a dedicated destinationpoolNum- the sequential pool number for the nickname, -1 when dedicatedmgr- the socket manager of the new transient destination; must be connectedserverSocket- the destination's server socket, or null
Method Details
getKey
The Base64-encoded info hash of the first torrent assigned.- Returns:
- the info hash as base64
getPoolIndex
public int getPoolIndex()Identifies the shared tunnel pool serving this destination.- Returns:
- the pool index, or -1 when dedicated to a single torrent
getPoolNum
public int getPoolNum()The sequential pool number shown in the tunnel nickname "I2PSnark - Pool <n>", or -1 when dedicated to a single torrent.- Returns:
- the pool number, or -1 when dedicated
hasTorrents
public boolean hasTorrents()Whether any torrent is assigned to this destination, so it still needs its tunnel floor even with no peers connected yet.- Returns:
- true if at least one torrent is assigned
getAppliedTunnelQuantity
public int getAppliedTunnelQuantity()The tunnel quantity last applied to this pool's own session, which is also its floor.- Returns:
- the applied quantity in each direction, never below 2
setAppliedTunnelQuantity
public void setAppliedTunnelQuantity(int qty) Record the tunnel quantity pushed to this pool's session.- Parameters:
qty- the quantity in each direction
getSocketManager
The socket manager of the transient destination this pool's traffic uses.- Returns:
- the socket manager, never null
getServerSocket
The inbound server socket for this destination.- Returns:
- the server socket, or null when the destination has none
getMyDestination
This router's own destination.- Returns:
- null if the session is not open
assign
Assign a torrent to this destination, serving its infohash on the DHT instance when one already runs, and updating the pool tooltip and tunnel nickname. The nickname changes only when the pool crosses the one-to-two torrent boundary; further members keep the pool name until the pool reverts to a single torrent.- Parameters:
key- the Base64-encoded info hash keyih- the torrent's info hashname- the torrent name, shown in the pool tooltip
unassign
Remove a torrent from this destination, stopping its DHT serving when an instance runs and updating the pool tooltip and tunnel nickname. The nickname reverts to the remaining torrent's name when the pool drops back to a single torrent.- Parameters:
key- the Base64-encoded info hash key- Returns:
- true when no torrents remain assigned
updatePoolProps
private void updatePoolProps()Push the pool's torrent names to the session's i2psnark.poolMembers property, which the console reads to render the pool tooltip on the tunnels page. The property must carry the inbound./outbound. prefix, because the router only stores prefixed session options in the pool settings. Also sets the tunnel nickname: the single torrent's name while one torrent is assigned, the "I2PSnark - Pool N" name once a second joins and until the pool reverts to one. Dedicated destinations have no tooltip and skip the update.getDHT
Lazily create the DHT instance on this destination's session, sharing the main instance's routing table, tracker, and blacklist, serving tracker queries only for the torrents assigned here.- Parameters:
shared- the main DHT instance, or null if the DHT is disabled- Returns:
- the DHT instance, or null if disabled
getUDPTracker
Lazily create the UDP tracker client on this destination's session.- Parameters:
util- the shared util, for destination lookups- Returns:
- the tracker client, or null if the session is gone
destroy
public void destroy()Stop the DHT instance and UDP tracker client and destroy the destination. Call only when no torrents remain assigned.