net.i2p.router.client

## Class ClientConnectionRunner

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

- Direct Known Subclasses:
    QueuedClientConnectionRunner

       class ClientConnectionRunner
      extends Object

  Bridge the router and the client - managing state for a client.
  Author:
    jrandom

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected RouterContext` | `_context`
    `protected I2CPMessageReader` | `_reader` thingy that does stuff

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ClientConnectionRunner(RouterContext context, ClientManager manager, Socket socket)` Create a new runner against the given socket

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `(package private) void` | `ackSendMessage(MessageId id, long nonce)` Send a notification to the client that their message (id specified) was accepted for delivery (but not necessarily delivered) Doesn't do anything if i2cp.messageReliability = "none"
    `(package private) void` | `disconnectClient(String reason)` Send a DisconnectMessage and log with level Log.CRIT.
    `(package private) void` | `disconnectClient(String reason, int logLevel)`
    `(package private) void` | `disconnected()`
    `(package private) MessageId` | `distributeMessage(SendMessageMessage message)` Distribute the message.
    `(package private) void` | `doSend(I2CPMessage msg)` Actually send the I2CPMessage to the peer through the socket
    `SessionConfig` | `getConfig()` current client's config
    `Hash` | `getDestHash()`
    `(package private) boolean` | `getIsDead()`
    `(package private) LeaseRequestState` | `getLeaseRequest()` data for the current leaseRequest, or null if there is no active leaseSet request
    `LeaseSet` | `getLeaseSet()` currently allocated leaseSet
    `(package private) static int` | `getNextMessageId()`
    `(package private) Payload` | `getPayload(MessageId id)` message body
    `(package private) SessionId` | `getSessionId()` current client's sessionId
    `SessionKeyManager` | `getSessionKeyManager()` current client's sessionkeymanager
    `(package private) boolean` | `isDead()` already closed?
    `(package private) void` | `leaseSetCreated(LeaseSet ls)` called after a new leaseSet is granted by the client, the NetworkDb has been updated.
    `(package private) void` | `receiveMessage(Destination toDest, Destination fromDest, Payload payload)` Asynchronously deliver the message to the current runner
    `(package private) void` | `removePayload(MessageId id)`
    `void` | `reportAbuse(String reason, int severity)` Send async abuse message to the client
    `(package private) void` | `requestLeaseSet(LeaseSet set, long expirationTime, Job onCreateJob, Job onFailedJob)` Request that a particular client authorize the Leases contained in the LeaseSet, after which the onCreateJob is queued up.
    `(package private) void` | `sessionEstablished(SessionConfig config)`
    `(package private) void` | `setLeaseRequest(LeaseRequestState req)`
    `(package private) void` | `setLeaseSet(LeaseSet ls)`
    `(package private) void` | `setPayload(MessageId id, Payload payload)`
    `(package private) void` | `setSessionId(SessionId id)`
    `void` | `startRunning()` Actually run the connection - listen for I2CP messages and respond.
    `(package private) void` | `stopRunning()` die a horrible death
    `(package private) void` | `updateMessageDeliveryStatus(MessageId id, boolean delivered)` Send a notification to the client that their message (id specified) was delivered (or failed delivery) Note that this sends the Guaranteed status codes, even though we only support best effort.
    `(package private) void` | `writeMessage(I2CPMessage msg)`

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

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

- - ### Field Detail

    - #### _context

          protected final RouterContext _context

    - #### _reader

          protected I2CPMessageReader _reader

      thingy that does stuff

  - ### Constructor Detail

    - #### ClientConnectionRunner

          public ClientConnectionRunner(RouterContext context,
                                ClientManager manager,
                                Socket socket)

      Create a new runner against the given socket

  - ### Method Detail

    - #### startRunning

          public void startRunning()

      Actually run the connection - listen for I2CP messages and respond. This is the main driver for this class, though it gets all its meat from the `I2CPMessageReader`

    - #### stopRunning

          void stopRunning()

      die a horrible death

    - #### getConfig

          public SessionConfig getConfig()

      current client's config

    - #### getSessionKeyManager

          public SessionKeyManager getSessionKeyManager()

      current client's sessionkeymanager

    - #### getLeaseSet

          public LeaseSet getLeaseSet()

      currently allocated leaseSet

    - #### setLeaseSet

          void setLeaseSet(LeaseSet ls)

    - #### getDestHash

          public Hash getDestHash()

    - #### getSessionId

          SessionId getSessionId()

      current client's sessionId

    - #### setSessionId

          void setSessionId(SessionId id)

    - #### getLeaseRequest

          LeaseRequestState getLeaseRequest()

      data for the current leaseRequest, or null if there is no active leaseSet request

    - #### setLeaseRequest

          void setLeaseRequest(LeaseRequestState req)

    - #### isDead

          boolean isDead()

      already closed?

    - #### getPayload

          Payload getPayload(MessageId id)

      message body

    - #### setPayload

          void setPayload(MessageId id,
                        Payload payload)

    - #### removePayload

          void removePayload(MessageId id)

    - #### sessionEstablished

          void sessionEstablished(SessionConfig config)

    - #### updateMessageDeliveryStatus

          void updateMessageDeliveryStatus(MessageId id,
                                         boolean delivered)

      Send a notification to the client that their message (id specified) was delivered (or failed delivery) Note that this sends the Guaranteed status codes, even though we only support best effort. Doesn't do anything if i2cp.messageReliability = "none"

    - #### leaseSetCreated

          void leaseSetCreated(LeaseSet ls)

      called after a new leaseSet is granted by the client, the NetworkDb has been updated. This takes care of all the LeaseRequestState stuff (including firing any jobs)

    - #### disconnectClient

          void disconnectClient(String reason)

      Send a DisconnectMessage and log with level Log.CRIT. This is always bad. See ClientMessageEventListener.handleCreateSession() for why we don't send a SessionStatusMessage when we do this.

    - #### disconnectClient

          void disconnectClient(String reason,
                              int logLevel)

      Parameters:
        `logLevel` - e.g. Log.WARN
      Since:
        0.8.2

    - #### distributeMessage

          MessageId distributeMessage(SendMessageMessage message)

      Distribute the message. If the dest is local, it blocks until its passed to the target ClientConnectionRunner (which then fires it into a MessageReceivedJob). If the dest is remote, it blocks until it is added into the ClientMessagePool

    - #### ackSendMessage

          void ackSendMessage(MessageId id,
                            long nonce)

      Send a notification to the client that their message (id specified) was accepted for delivery (but not necessarily delivered) Doesn't do anything if i2cp.messageReliability = "none"

    - #### receiveMessage

          void receiveMessage(Destination toDest,
                            Destination fromDest,
                            Payload payload)

      Asynchronously deliver the message to the current runner

    - #### reportAbuse

          public void reportAbuse(String reason,
                         int severity)

      Send async abuse message to the client

    - #### requestLeaseSet

          void requestLeaseSet(LeaseSet set,
                             long expirationTime,
                             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.
      Parameters:
        `set` - LeaseSet with requested leases - this object must be updated to contain the signed version (as well as any changed/added/removed Leases)
        `expirationTime` - 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

    - #### disconnected

          void disconnected()

    - #### getIsDead

          boolean getIsDead()

    - #### writeMessage

          void writeMessage(I2CPMessage msg)

    - #### doSend

          void doSend(I2CPMessage msg)
                throws I2CPMessageException

      Actually send the I2CPMessage to the peer through the socket
      Throws:
        `I2CPMessageException`

    - #### getNextMessageId

          static int getNextMessageId()