java.lang.Object
net.i2p.router.client.ClientManager
Coordinate connections and various tasks.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classTell external clients the time periodically.private static classJob delivering a message to a local destination.private classJob handling one message from a client session.Field Summary
Modifier and TypeFieldDescriptionprivate final SimpleTimer2.TimedEventTimer stamping the client sessions' clocks.protected final RouterContextRouter context.protected booleanTrue afterstart()completes.protected final List<ClientListenerRunner> Registered client listener runners.private final LogLogger for the client manager.private final Set<Destination> Destinations of the metadata sessions.Destination hashes of the metadata sessions.private final Set<ClientConnectionRunner> Runners waiting for their session to start.protected final intI2CP listen port.private final Map<Destination, ClientConnectionRunner> The runners, by destination.private final Map<Hash, ClientConnectionRunner> The runners, by destination hash.Session ids taken by the runners.protected booleanTrue if start() was ever called.private static final intDefault session id pool size.private static final intLargest session id assignable.private static final StringDisable external interface, allow internal clients only.private static final StringDisable local-local loopback, force all traffic through tunnels.private static final StringSSL interface (only).private static final String2 bytes; 65535 is reserved for unknown.private static final longTime to wait for a requested lease set.static final SessionIdSentinel session ID for unknown/unidentified sessions.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionintdestinationEstablished(ClientConnectionRunner runner, Destination dest) Add to the clients list.(package private) voiddistributeMessage(ClientConnectionRunner sender, Destination fromDest, Destination toDest, Payload payload, MessageId msgId, long messageNonce, long expiration, int flags) Distribute message to a local or remote destination.getClientFloodfillNetworkDatabaseFacade(Hash destHash) The FloodfillNetworkDatabaseFacade associated with a particular client destination.Return the client's current config, or null if not connected.Return the client's SessionKeyManager Use this instead of theI2PAppContext.sessionKeyManager()to prevent correlation attacks across destinations.All the primary hashes for all the clients as a set.(package private) ClientConnectionRunnergetRunner(Destination dest) Looks up a client's runner without holding the lock.private ClientConnectionRunnerLooks up a client's runner by hash without holding the lock.(package private) Set<Destination> Get the set of all runner destinations.The InternalClientManager interface.booleanisAlive()Test whether the ClientManager is running.booleanisLocal(Destination dest) Unsynchronized.booleanUnsynchronized.Unsynchronized.private SessionIdGenerate a new random, unused sessionId.voidmessageDeliveryStatusUpdate(Destination fromDest, MessageId id, long messageNonce, int status) Update the message delivery status for a client.voidReceive and process an incoming client message inline.voidRegister a new client connection.booleanregisterEncryptedDestination(ClientConnectionRunner runner, Hash hash) Call afterdestinationEstablished(ClientConnectionRunner, Destination), when an encrypted leaseset is created, so we know it's local.voidregisterMetaDest(Destination dest) Declare that we're going to publish a meta LS for this destination.voidreportAbuse(Destination dest, String reason, int severity) Reports abuse on one destination, or on every local destination.voidrequestLeaseSet(Destination dest, LeaseSet set, long timeout, Job onCreateJob, Job onFailedJob) Request that a particular client authorize the Leases contained in the LeaseSet, after which the onCreateJob is queued up.voidrequestLeaseSet(Hash dest, LeaseSet ls) Request that a particular client authorize the Leases contained in the LeaseSet.voidrestart()Restart the client manager, disconnecting and reconnecting all clients.booleanshouldPublishLeaseSet(Hash destHash) Determine if we should publish a leaseSet for this hash.voidShutdown the client manager, disconnecting all clients.voidstart()Start the listeners.protected voidCall from synchronized method Todo: Start a 3rd listener for IPV6?voidRemove all sessions for this runner.voidunregisterEncryptedDestination(ClientConnectionRunner runner, Hash hash) Remove the hash for the encrypted LS.voidDeclare that we're no longer going to publish a meta LS for this destination.voidunregisterSession(SessionId id, Destination dest) Remove only the following session.
Field Details
_log
Logger for the client manager._listeners
Registered client listener runners._runners
The runners, by destination._runnersByHash
The runners, by destination hash._pendingRunners
Runners waiting for their session to start._runnerSessionIds
_metaDests
Destinations of the metadata sessions._metaHashes
_ctx
Router context._port
protected final int _portI2CP listen port._isStarted
protected volatile boolean _isStartedTrue afterstart()completes._wasStarted
protected volatile boolean _wasStartedTrue if start() was ever called._clientTimestamper
Timer stamping the client sessions' clocks.PROP_DISABLE_EXTERNAL
Disable external interface, allow internal clients only.- See Also:
PROP_ENABLE_SSL
PROP_DISABLE_LOOPBACK
Disable local-local loopback, force all traffic through tunnels.- See Also:
REQUEST_LEASESET_TIMEOUT
private static final long REQUEST_LEASESET_TIMEOUTTime to wait for a requested lease set.- See Also:
MAX_SESSION_ID
PROP_MAX_SESSIONS
2 bytes; 65535 is reserved for unknown.- See Also:
DEFAULT_MAX_SESSIONS
private static final int DEFAULT_MAX_SESSIONSDefault session id pool size.UNKNOWN_SESSION_ID
Sentinel session ID for unknown/unidentified sessions.
Constructor Details
ClientManager
Does not start the listeners. Caller must call start().- Parameters:
context- the router contextport- the I2CP port
Method Details
start
public void start()Start the listeners.startListeners
protected void startListeners()Call from synchronized method Todo: Start a 3rd listener for IPV6?restart
public void restart()Restart the client manager, disconnecting and reconnecting all clients.shutdown
Shutdown the client manager, disconnecting all clients.- Parameters:
msg- message to send to the clients
internalConnect
The InternalClientManager interface. Connects to the router, receiving a message queue to talk to the router with.- Returns:
- the message queue for communicating with the router
- Throws:
I2PSessionException- if the router isn't ready
isAlive
public boolean isAlive()Test whether the ClientManager is running.As of 0.9.45, this returns true iff the ClientManager is running. Prior to that, it also required all external I2CP listeners that were registered to be running. Since most of our connections are in-JVM, we now return true even if we have I2CP port conflicts.
- Returns:
- true if the ClientManager is running
registerConnection
Register a new client connection.- Parameters:
runner- the client connection to start and hold as pending until it claims a destination
unregisterConnection
Remove all sessions for this runner.- Parameters:
runner- the client connection whose session IDs and destination mappings are dropped
unregisterSession
Remove only the following session. Does not remove the runner if it has more.- Parameters:
id- the session IDdest- the destination whose registration this session holds
unregisterEncryptedDestination
Remove the hash for the encrypted LS. Call before unregisterConnection, or when the hash changes.- Parameters:
runner- the connection the hash belongs to; not consulted by the bodyhash- the hash to remove
destinationEstablished
Add to the clients list. Check for a dup destination. Side effect: Sets the session ID of the runner. Caller must call runner.disconnectClient() on failure.- Parameters:
runner- the connection claiming the destinationdest- the destination being claimed; must not already be registered- Returns:
- SessionStatusMessage return code, 1 for success, != 1 for failure
registerEncryptedDestination
Call afterdestinationEstablished(ClientConnectionRunner, Destination), when an encrypted leaseset is created, so we know it's local. Add to the clients list. Check for a dup hash. Caller must call runner.disconnectClient() on failure.- Parameters:
runner- the connection to associate with the hashhash- the location of the encrypted LS, will change every day- Returns:
- success, false on dup
registerMetaDest
Declare that we're going to publish a meta LS for this destination. Must be called before publishing the leaseset.- Parameters:
dest- the destination the meta LeaseSet will be published under; must not already be registered- Throws:
I2PSessionException- on duplicate dest
unregisterMetaDest
Declare that we're no longer going to publish a meta LS for this destination.- Parameters:
dest- the destination to stop publishing a meta LeaseSet for
locked_getNextSessionId
Generate a new random, unused sessionId. Caller must synch on _runners.- Returns:
- null on failure
distributeMessage
void distributeMessage(ClientConnectionRunner sender, Destination fromDest, Destination toDest, Payload payload, MessageId msgId, long messageNonce, long expiration, int flags) Distribute message to a local or remote destination.- Parameters:
sender- non-nullfromDest- the sending client's own destination, which must be registered for the remote pathtoDest- the destination being sent to; a local one is delivered inlinepayload- the message payloadmsgId- the router's ID for this messagemessageNonce- the client's ID for this messageexpiration- the expiry deadline carried into the queued message, only used on the remote pathflags- not used for local delivery
requestLeaseSet
public void requestLeaseSet(Destination dest, LeaseSet set, long timeout, Job onCreateJob, Job onFailedJob) Request that a particular client authorize the Leases contained in the LeaseSet, after which the onCreateJob is queued up. If that doesn't occur within the timeout specified, queue up the onFailedJob. This call does not block.UNUSED, the call below without jobs is always used.
- Parameters:
dest- Destination from which the LeaseSet's authorization should be requestedset- LeaseSet with requested leases - this object must be updated to contain the signed version (as well as any changed/added/removed Leases). The LeaseSet contains Leases only; it is unsigned and does not have the destination set.timeout- ms to wait before failingonCreateJob- Job to run after the LeaseSet is authorizedonFailedJob- Job to run after the timeout passes without receiving authorization
requestLeaseSet
Request that a particular client authorize the Leases contained in the LeaseSet.- Parameters:
dest- Destination from which the LeaseSet's authorization should be requestedls- LeaseSet with requested leases - this object must be updated to contain the signed version (as well as any changed/added/removed Leases). The LeaseSet contains Leases only; it is unsigned and does not have the destination set.
isLocal
Unsynchronized. DOES contain meta destinations.- Parameters:
dest- the destination to check- Returns:
- true if local
isLocal
Unsynchronized. DOES contain meta destinations.- Parameters:
destHash- the destination hash to check- Returns:
- true if local
shouldPublishLeaseSet
Determine if we should publish a leaseSet for this hash.- Parameters:
destHash- the destination hash- Returns:
- true if we don't know about this destination at all
listClients
Unsynchronized. Does NOT contain meta destinations.- Returns:
- non-null set of local destinations
getRunner
Looks up a client's runner without holding the lock.- Parameters:
dest- the destination key, as opposed to the hash overload- Returns:
- the runner, or null
getClientSessionConfig
Return the client's current config, or null if not connected.- Parameters:
dest- the destination whose session config is wanted- Returns:
- the SessionConfig, or null
getClientSessionKeyManager
Return the client's SessionKeyManager Use this instead of theI2PAppContext.sessionKeyManager()to prevent correlation attacks across destinations.- Parameters:
dest- the destination hash- Returns:
- the SessionKeyManager, or null
getRunner
Looks up a client's runner by hash without holding the lock.- Parameters:
destHash- the destination hash to look up, null returns null- Returns:
- the runner registered under that hash, or null
messageDeliveryStatusUpdate
public void messageDeliveryStatusUpdate(Destination fromDest, MessageId id, long messageNonce, int status) Update the message delivery status for a client.- Parameters:
fromDest- the source destinationid- the router's ID for this messagemessageNonce- the client's ID for this message, greater than zerostatus- see I2CP MessageStatusMessage for success/failure codes
getRunnerDestinations
Set<Destination> getRunnerDestinations()Get the set of all runner destinations.- Returns:
- unmodifiable, not a copy
reportAbuse
Reports abuse on one destination, or on every local destination.- Parameters:
dest- null for all local destinationsreason- the abuse reasonseverity- the abuse severity
messageReceived
Receive and process an incoming client message inline.- Parameters:
msg- the message to process
getClientFloodfillNetworkDatabaseFacade
The FloodfillNetworkDatabaseFacade associated with a particular client destination. This is inside the runner, so it won't be there if the runner isn't ready.- Parameters:
destHash- destination hash associated with the client who's subDb we're looking for, may be null- Returns:
- will be null if desthash is null or client does not exist or its netDb is not initialized
getPrimaryHashes