java.lang.Object
net.i2p.router.ClientManagerFacade
net.i2p.router.client.ClientManagerFacadeImpl
All Implemented Interfaces:
InternalClientManager, Service

public class ClientManagerFacadeImplextends ClientManagerFacade implements InternalClientManager
Base impl of the client facade.
  • Field Details

    • _log

      private final Log _log
      Logger for this class.
    • _manager

      private ClientManager _manager
      The manager doing the work, null while rebuilding.
    • _context

      private final RouterContext _context
      The router running the clients.
    • LOG_THROTTLE

      private static final long LOG_THROTTLE
      Throttle lease expiration logging - only log once per client per interval.
      See Also:
    • _lastExpiredLogTime

      private final ConcurrentHashMap<Hash,Long> _lastExpiredLogTime
      When each client's expiration was last logged.
    • PROP_CLIENT_PORT

      public static final String PROP_CLIENT_PORT
      Note that this is different than the property the client side uses, i2cp.tcp.port.
      See Also:
    • DEFAULT_PORT

      public static final int DEFAULT_PORT
      Default port.
      See Also:
    • PROP_CLIENT_HOST

      public static final String PROP_CLIENT_HOST
      Note that this is different than the property the client side uses, i2cp.tcp.host.
      See Also:
    • DEFAULT_HOST

      public static final String DEFAULT_HOST
      Default host.
      See Also:
    • MAX_TIME_TO_REBUILD

      private static final long MAX_TIME_TO_REBUILD
      Longest to wait for a rebuild - up to 10 minutes.
      See Also:
  • Constructor Details

    • ClientManagerFacadeImpl

      public ClientManagerFacadeImpl(RouterContext context)
      Creates the facade without starting anything; call startup() to listen for I2CP connections.
      Parameters:
      context - the router context this facade and the manager it creates are scoped to
  • Method Details

    • startup

      public void startup()
      Start the client manager to accept I2CP connections.
      Specified by:
      startup in interface Service
    • shutdown

      public void shutdown()
      Shut down the client manager, disconnecting all clients.
      Specified by:
      shutdown in interface Service
    • shutdown

      public void shutdown(String msg)
      Disconnect all clients with the given error message.
      Specified by:
      shutdown in class ClientManagerFacade
      Parameters:
      msg - message to send to the clients
    • restart

      public void restart()
      Restart the service.
      Specified by:
      restart in interface Service
    • isAlive

      public boolean isAlive()
      Whether the client manager is running.
      Overrides:
      isAlive in class ClientManagerFacade
      Returns:
      true if the manager exists and is running
    • getMinTimeToLeaseExpiry

      public long getMinTimeToLeaseExpiry()
      Minimum time to lease expiry across all clients. Used by RouterWatchdog to adjust the sleep interval.
      Returns:
      minimum time to expiry in milliseconds, or Long.MAX_VALUE if no leases
    • verifyClientLiveliness

      public boolean verifyClientLiveliness()
      Verify that client lease sets are still live, requesting renewal when they have expired or are about to expire.
      Overrides:
      verifyClientLiveliness in class ClientManagerFacade
      Returns:
      true if the client manager is alive
    • pruneStaleExpiredLogEntries

      static int pruneStaleExpiredLogEntries(ConcurrentHashMap<Hash,Long> map, Set<Hash> active)
      Remove lease-expiration log-throttle entries whose destination no longer has a live runner. The throttle is only consulted for currently-connected clients (see verifyClientLiveliness()), so an entry for a disconnected destination can never be read again — retaining it would let the map grow with every I2CP client the router has ever served.
      Parameters:
      map - the throttle map to prune in place
      active - the destination hashes that currently have a live runner
      Returns:
      the number of stale entries removed
    • 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.

      Specified by:
      requestLeaseSet in class ClientManagerFacade
      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 set)
      Request that a particular client authorize the Leases contained in the LeaseSet.
      Specified by:
      requestLeaseSet in class ClientManagerFacade
      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.
    • reportAbuse

      public void reportAbuse(Destination dest, String reason, int severity)
      Instruct the client (or all clients) that they are under attack. This call does not block.
      Specified by:
      reportAbuse in class ClientManagerFacade
      Parameters:
      dest - Destination under attack, or null if all destinations are affected
      reason - Why the router thinks that there is abusive behavior
      severity - How severe the abuse is, with 0 being not severe and 255 is the max
    • isLocal

      public boolean isLocal(Destination dest)
      Determine if the destination specified is managed locally. This call DOES block.
      Specified by:
      isLocal in class ClientManagerFacade
      Parameters:
      dest - Destination to be checked
      Returns:
      true if a local client is running for that destination
    • isLocal

      public boolean isLocal(Hash destHash)
      Determine if the destination specified is managed locally. This call DOES block.
      Specified by:
      isLocal in class ClientManagerFacade
      Parameters:
      destHash - Hash of Destination to be checked
      Returns:
      true if a local client is running for that destination
    • shouldPublishLeaseSet

      public boolean shouldPublishLeaseSet(Hash destinationHash)
      Whether the lease set for the destination should be published.
      Overrides:
      shouldPublishLeaseSet in class ClientManagerFacade
      Parameters:
      destinationHash - the destination hash to check
      Returns:
      whether publish lease set
    • messageDeliveryStatusUpdate

      public void messageDeliveryStatusUpdate(Destination fromDest, MessageId id, long messageNonce, int status)
      Report whether a client message was delivered or lost.
      Specified by:
      messageDeliveryStatusUpdate in class ClientManagerFacade
      Parameters:
      fromDest - the source destination of the message
      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)
      Description copied from class: ClientManagerFacade
      Receive a message from the network for a local client.
      Specified by:
      messageReceived in class ClientManagerFacade
      Parameters:
      msg - the received client message
    • getClientSessionConfig

      public SessionConfig getClientSessionConfig(Destination dest)
      Return the client's current config, or null if not connected.
      Specified by:
      getClientSessionConfig in class ClientManagerFacade
      Parameters:
      dest - the client destination
      Returns:
      the client session config
    • getClientSessionKeyManager

      public SessionKeyManager getClientSessionKeyManager(Hash dest)
      Return the client's current manager or null if not connected.
      Specified by:
      getClientSessionKeyManager in class ClientManagerFacade
      Parameters:
      dest - the destination hash
      Returns:
      the client session key manager
    • listClients

      public Set<Destination> listClients()
      Return the list of locally connected clients.
      Overrides:
      listClients in class ClientManagerFacade
      Returns:
      set of Destination objects
    • connect

      public I2CPMessageQueue connect() throws I2PSessionException
      The InternalClientManager interface. Connect to the router, receiving a message queue to talk to the router with.
      Specified by:
      connect in interface InternalClientManager
      Returns:
      the message queue for communicating with the router
      Throws:
      I2PSessionException - if the router isn't ready
    • 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.
      Overrides:
      registerMetaDest in class ClientManagerFacade
      Parameters:
      dest - the destination to register
      Throws:
      I2PSessionException - on duplicate dest
    • unregisterMetaDest

      public void unregisterMetaDest(Destination dest)
      Declare that we're no longer going to publish a meta LS for this destination.
      Overrides:
      unregisterMetaDest in class ClientManagerFacade
      Parameters:
      dest - the destination to unregister
    • getClientFloodfillNetworkDatabaseFacade

      public FloodfillNetworkDatabaseFacade getClientFloodfillNetworkDatabaseFacade(Hash destHash)
      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.
      Specified by:
      getClientFloodfillNetworkDatabaseFacade in class ClientManagerFacade
      Parameters:
      destHash - destination hash associated with the client who's subDb we're looking for
      Returns:
      the netdb or null
    • getPrimaryHashes

      public Set<Hash> getPrimaryHashes()
      All the primary hashes for all the clients as a set.
      Specified by:
      getPrimaryHashes in class ClientManagerFacade
      Returns:
      all the hashes or an empty set, non-null
    • getWriterQueueSize

      public static int getWriterQueueSize()
      Gets the cap on the client writer's outgoing message queue.
      Returns:
      the current client writer queue limit, in messages
    • setWriterQueueSize

      public static void setWriterQueueSize(int val)
      Sets the cap on the client writer's outgoing message queue.
      Parameters:
      val - the requested queue limit in messages, clamped to 32..2048