java.lang.Object
net.i2p.router.client.ClientMessageEventListener
All Implemented Interfaces:
I2CPMessageReader.I2CPMessageEventListener

class ClientMessageEventListenerextends Object implements I2CPMessageReader.I2CPMessageEventListener
Receive events from the client and handle them accordingly (updating the runner when necessary).
  • Field Details

  • Constructor Details

    • ClientMessageEventListener

      public ClientMessageEventListener(RouterContext context, ClientConnectionRunner runner, boolean enforceAuth)
      Create a new event listener for the given client connection.
      Parameters:
      context - the router context
      runner - the client connection runner
      enforceAuth - set false for in-JVM, true for socket access
  • Method Details

    • messageReceived

      public void messageReceived(I2CPMessageReader reader, I2CPMessage message)
      Handle an incoming message and dispatch it to the appropriate handler.
      Specified by:
      messageReceived in interface I2CPMessageReader.I2CPMessageEventListener
      Parameters:
      reader - I2CPMessageReader to notify
      message - the I2CPMessage
    • readError

      public void readError(I2CPMessageReader reader, Exception error)
      Handle notification that there was an error.
      Specified by:
      readError in interface I2CPMessageReader.I2CPMessageEventListener
      Parameters:
      reader - I2CPMessageReader to notify
      error - Exception that was thrown, non-null
    • disconnected

      public void disconnected(I2CPMessageReader reader)
      Description copied from interface: I2CPMessageReader.I2CPMessageEventListener
      Notify the listener that the stream this reader was reading was closed. For most errors, readError() will be called first, as of 0.9.41.
      Specified by:
      disconnected in interface I2CPMessageReader.I2CPMessageEventListener
      Parameters:
      reader - I2CPMessageReader to notify
    • startCreateSessionJob

      protected void startCreateSessionJob(SessionConfig config)
      Override for testing.
      Parameters:
      config - the session config
    • classifyReceiveBegin

      static ClientMessageEventListener.ReceiveRequest classifyReceiveBegin(SessionConfig cfg, Payload payload)
      Validate a ReceiveMessageBeginMessage before any retained payload is read.

      The router keeps a single payload map per connection, not per session, so a message that names a message id alone is not enough to authorize access. The message must also name a live session on this connection. Session-level validation is the right granularity because every session on a connection must already share one keypair, so sessions of one connection are not mutually untrusted.

      Parameters:
      cfg - the session named by the message, or null if there is no such session
      payload - the retained payload for the message id, or null if none is retained
      Returns:
      the request outcome, never null
    • classifyReceiveEnd

      static ClientMessageEventListener.ReceiveRequest classifyReceiveEnd(SessionConfig cfg, Payload payload)
      Validate a ReceiveMessageEndMessage before the retained payload is released.

      Uses the same rule as classifyReceiveBegin(SessionConfig, Payload): the message must name a live session on this connection, and the payload must actually be retained. A message id that is not retained needs no action, so it is reported separately from a rejected session.

      Parameters:
      cfg - the session named by the message, or null if there is no such session
      payload - the retained payload for the message id, or null if none is retained
      Returns:
      the request outcome, never null
    • handleCreateLeaseSet

      protected void handleCreateLeaseSet(CreateLeaseSetMessage message)
      Handle a CreateLeaseSet message. Override for testing.
      Parameters:
      message - the client request supplying the LeaseSet, its signing keys, and the session it applies to
    • handleDestLookup

      protected void handleDestLookup(DestLookupMessage message)
      Handle a DestLookup message. Override for testing.
      Parameters:
      message - the request naming the RouterInfo hash to resolve
    • handleHostLookup

      protected void handleHostLookup(HostLookupMessage message)
      Handle a HostLookup message. Override for testing.
      Parameters:
      message - the lookup request supplying the session and request ID
    • handleGetBWLimits

      protected void handleGetBWLimits(GetBandwidthLimitsMessage message)
      Divide router limit by 1.5 for overhead. This could someday give a different answer to each client. But it's not enforced anywhere.

      protected for unit test override.

      Parameters:
      message - the client's bandwidth query, which carries no data