net.i2p.router.client

## Class ClientManager

- java.lang.Object
- - net.i2p.router.client.ClientManager

-     class ClientManager
      extends Object

  Coordinate connections and various tasks

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected RouterContext` | `_ctx`
    `protected boolean` | `_isStarted`
    `protected List<ClientListenerRunner>` | `_listeners`
    `protected int` | `_port`
    `protected boolean` | `_wasStarted`
    `static SessionId` | `UNKNOWN_SESSION_ID`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ClientManager(RouterContext context, int port)` Does not start the listeners.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `destinationEstablished(ClientConnectionRunner runner, Destination dest)` Add to the clients list.
    `(package private) 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.
    `FloodfillNetworkDatabaseFacade` | `getClientFloodfillNetworkDatabaseFacade(Hash destHash)` get the FloodfillNetworkDatabaseFacade associated with a particular client destination.
    `SessionConfig` | `getClientSessionConfig(Destination dest)` Return the client's current config, or null if not connected
    `SessionKeyManager` | `getClientSessionKeyManager(Hash dest)` Return the client's SessionKeyManager Use this instead of the RouterContext.sessionKeyManager() to prevent correlation attacks across destinations
    `Set<Hash>` | `getPrimaryHashes()` get all the primary hashes for all the clients and return them as a set
    `(package private) ClientConnectionRunner` | `getRunner(Destination dest)` Unsynchronized
    `(package private) Set<Destination>` | `getRunnerDestinations()`
    `I2CPMessageQueue` | `internalConnect()` The InternalClientManager interface.
    `boolean` | `isAlive()` As of 0.9.45, this returns true iff the ClientManager is running.
    `boolean` | `isLocal(Destination dest)` Unsynchronized.
    `boolean` | `isLocal(Hash destHash)` Unsynchronized.
    `Set<Destination>` | `listClients()` Unsynchronized.
    `void` | `messageDeliveryStatusUpdate(Destination fromDest, MessageId id, long messageNonce, int status)`
    `void` | `messageReceived(ClientMessage msg)`
    `void` | `registerConnection(ClientConnectionRunner runner)`
    `boolean` | `registerEncryptedDestination(ClientConnectionRunner runner, Hash hash)` Call after destinationEstablished(), when an encrypted leaseset is created, so we know it's local.
    `void` | `registerMetaDest(Destination dest)` Declare that we're going to publish a meta LS for this destination.
    `void` | `reportAbuse(Destination dest, String reason, int severity)` Unused
    `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.
    `void` | `requestLeaseSet(Hash dest, LeaseSet ls)` Request that a particular client authorize the Leases contained in the LeaseSet.
    `void` | `restart()`
    `boolean` | `shouldPublishLeaseSet(Hash destHash)`
    `void` | `shutdown(String msg)`
    `void` | `start()`
    `protected void` | `startListeners()` Call from synchronized method Todo: Start a 3rd listener for IPV6?
    `void` | `unregisterConnection(ClientConnectionRunner runner)` Remove all sessions for this runner.
    `void` | `unregisterEncryptedDestination(ClientConnectionRunner runner, Hash hash)` Remove the hash for the encrypted LS.
    `void` | `unregisterMetaDest(Destination dest)` Declare that we're no longer going to publish a meta LS for this destination.
    `void` | `unregisterSession(SessionId id, Destination dest)` Remove only the following session.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### _ctx

          protected final RouterContext _ctx

    - #### _isStarted

          protected volatile boolean _isStarted

    - #### _listeners

          protected final List<ClientListenerRunner> _listeners

    - #### _port

          protected final int _port

    - #### _wasStarted

          protected volatile boolean _wasStarted

    - #### UNKNOWN_SESSION_ID

          public static final SessionId UNKNOWN_SESSION_ID

  - ### Constructor Detail

    - #### ClientManager

          public ClientManager(RouterContext context,
                               int port)

      Does not start the listeners. Caller must call start()

  - ### Method Detail

    - #### destinationEstablished

          public int destinationEstablished(ClientConnectionRunner runner,
                                            Destination dest)

      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.
      Returns:
        SessionStatusMessage return code, 1 for success, != 1 for 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-null
        `msgId` - the router's ID for this message
        `messageNonce` - the client's ID for this message
        `flags` - ignored for local

    - #### getClientFloodfillNetworkDatabaseFacade

          public FloodfillNetworkDatabaseFacade getClientFloodfillNetworkDatabaseFacade(Hash destHash)

      get 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

    - #### getClientSessionConfig

          public SessionConfig getClientSessionConfig(Destination dest)

      Return the client's current config, or null if not connected

    - #### getClientSessionKeyManager

          public SessionKeyManager getClientSessionKeyManager(Hash dest)

      Return the client's SessionKeyManager Use this instead of the RouterContext.sessionKeyManager() to prevent correlation attacks across destinations

    - #### getPrimaryHashes

          public Set<Hash> getPrimaryHashes()

      get all the primary hashes for all the clients and return them as a set
      Returns:
        non-null

    - #### getRunner

          ClientConnectionRunner getRunner(Destination dest)

      Unsynchronized

    - #### getRunnerDestinations

          Set<Destination> getRunnerDestinations()

      Returns:
        unmodifiable, not a copy

    - #### internalConnect

          public I2CPMessageQueue internalConnect()
                                           throws I2PSessionException

      The InternalClientManager interface. Connects to the router, receiving a message queue to talk to the router with.
      Throws:
        `I2PSessionException` - if the router isn't ready

    - #### isAlive

          public boolean isAlive()

      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.

    - #### isLocal

          public boolean isLocal(Destination dest)

      Unsynchronized. DOES contain meta destinations.

    - #### isLocal

          public boolean isLocal(Hash destHash)

      Unsynchronized. DOES contain meta destinations.

    - #### listClients

          public Set<Destination> listClients()

      Unsynchronized. Does NOT contain meta destinations.

    - #### messageDeliveryStatusUpdate

          public void messageDeliveryStatusUpdate(Destination fromDest,
                                                  MessageId id,
                                                  long messageNonce,
                                                  int status)

      Parameters:
        `id` - the router's ID for this message
        `messageNonce` - the client's ID for this message, greater than zero
        `status` - see I2CP MessageStatusMessage for success/failure codes

    - #### messageReceived

          public void messageReceived(ClientMessage msg)

    - #### registerConnection

          public void registerConnection(ClientConnectionRunner runner)

    - #### registerEncryptedDestination

          public boolean registerEncryptedDestination(ClientConnectionRunner runner,
                                                      Hash hash)

      Call after destinationEstablished(), 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:
        `hash` - the location of the encrypted LS, will change every day
      Returns:
        success, false on dup

    - #### registerMetaDest

          public void registerMetaDest(Destination dest)
                                throws I2PSessionException

      Declare that we're going to publish a meta LS for this destination. Must be called before publishing the leaseset.
      Throws:
        `I2PSessionException` - on duplicate dest

    - #### reportAbuse

          public void reportAbuse(Destination dest,
                                  String reason,
                                  int severity)

      Unused
      Parameters:
        `dest` - null for all local destinations

    - #### 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 requested
        `set` - 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 failing
        `onCreateJob` - Job to run after the LeaseSet is authorized
        `onFailedJob` - Job to run after the timeout passes without receiving authorization

    - #### requestLeaseSet

          public void requestLeaseSet(Hash dest,
                                      LeaseSet ls)

      Request that a particular client authorize the Leases contained in the LeaseSet.
      Parameters:
        `dest` - Destination from which the LeaseSet's authorization should be requested
        `ls` - 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.

    - #### restart

          public void restart()

    - #### shouldPublishLeaseSet

          public boolean shouldPublishLeaseSet(Hash destHash)

      Returns:
        true if we don't know about this destination at all

    - #### shutdown

          public void shutdown(String msg)

      Parameters:
        `msg` - message to send to the clients

    - #### start

          public void start()

    - #### startListeners

          protected void startListeners()

      Call from synchronized method Todo: Start a 3rd listener for IPV6?

    - #### unregisterConnection

          public void unregisterConnection(ClientConnectionRunner runner)

      Remove all sessions for this runner.

    - #### unregisterEncryptedDestination

          public void unregisterEncryptedDestination(ClientConnectionRunner runner,
                                                     Hash hash)

      Remove the hash for the encrypted LS. Call before unregisterConnection, or when the hash changes.

    - #### unregisterMetaDest

          public void unregisterMetaDest(Destination dest)

      Declare that we're no longer going to publish a meta LS for this destination.

    - #### unregisterSession

          public void unregisterSession(SessionId id,
                                        Destination dest)

      Remove only the following session. Does not remove the runner if it has more.