Class ClientManager


  • class ClientManager
    extends Object
    Coordinate connections and various tasks
    Author:
    jrandom
    • Field Detail

      • _port

        protected final int _port
      • _isStarted

        protected volatile boolean _isStarted
      • UNKNOWN_SESSION_ID

        public static final SessionId UNKNOWN_SESSION_ID
        65535
    • Constructor Detail

      • ClientManager

        public ClientManager​(RouterContext context,
                             int port)
        Does not start the listeners. Caller must call start()
    • Method Detail

      • start

        public void start()
        Since:
        0.9.8
      • startListeners

        protected void startListeners()
        Call from synchronized method Todo: Start a 3rd listener for IPV6?
      • restart

        public void restart()
      • shutdown

        public void shutdown​(String msg)
        Parameters:
        msg - message to send to the clients
      • 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
        Since:
        0.8.3
      • isAlive

        public boolean isAlive()
      • unregisterConnection

        public void unregisterConnection​(ClientConnectionRunner runner)
        Remove all sessions for this runner.
      • unregisterSession

        public void unregisterSession​(SessionId id,
                                      Destination dest)
        Remove only the following session. Does not remove the runner if it has more.
        Since:
        0.9.21
      • 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​(Destination fromDest,
                               Destination toDest,
                               Payload payload,
                               MessageId msgId,
                               long messageNonce,
                               long expiration,
                               int flags)
        Distribute message to a local or remote destination.
        Parameters:
        msgId - the router's ID for this message
        messageNonce - the client's ID for this message
        flags - ignored for local
      • 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.
      • isLocal

        public boolean isLocal​(Destination dest)
        Unsynchronized
      • isLocal

        public boolean isLocal​(Hash destHash)
        Unsynchronized
      • shouldPublishLeaseSet

        public boolean shouldPublishLeaseSet​(Hash destHash)
        Returns:
        true if we don't know about this destination at all
      • 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
      • 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
        status - see I2CP MessageStatusMessage for success/failure codes
      • getRunnerDestinations

        Set<Destination> getRunnerDestinations()
        Returns:
        unmodifiable, not a copy
      • reportAbuse

        public void reportAbuse​(Destination dest,
                                String reason,
                                int severity)
        Unused
        Parameters:
        dest - null for all local destinations
      • messageReceived

        public void messageReceived​(ClientMessage msg)