net.i2p.router

## Class InNetMessagePool

- java.lang.Object
- - net.i2p.router.InNetMessagePool

- All Implemented Interfaces:
    Service

      public class InNetMessagePool
      extends Object
      implements Service

  Receives and dispatches inbound network messages with configurable processing modes. Handles message routing, job queuing, and concurrent processing for efficient inbound traffic management.

  Dispatching can operate in different modes configured by transport layer: - Direct dispatch on caller thread (low latency), - Queued dispatch with threaded processing for higher concurrency.

  Thread-safe queues from java.util.concurrent provide efficient, lock-free concurrency, minimizing blocking and wake overhead.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `InNetMessagePool(RouterContext context)` Constructs the message pool with given context.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `add(I2NPMessage messageBody, RouterIdentity fromRouter, Hash fromRouterHash)` Adds a new inbound message to be processed.
    `int` | `add(I2NPMessage messageBody, RouterIdentity fromRouter, Hash fromRouterHash, long msgIDBloomXor)` Adds a new inbound message with optional bloom filter XOR id.
    `int` | `handleReplies(I2NPMessage messageBody)` Handles replies for outbound messages that correspond to this inbound message.
    `HandlerJobBuilder` | `registerHandlerJobBuilder(int i2npMessageType, HandlerJobBuilder builder)` Registers or replaces a HandlerJobBuilder for a given message type.
    `void` | `renderStatusHTML(Writer out)` Render the status of this message pool as HTML.
    `void` | `restart()` Restart the message pool by shutting down and then starting up again.
    `void` | `shutdown()` Shutdown the message pool, stopping all dispatchers and clearing queued messages.
    `void` | `startup()` Startup the message pool and, if configured, start dispatcher threads.

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

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

- - ### Constructor Detail

    - #### InNetMessagePool

          public InNetMessagePool(RouterContext context)

      Constructs the message pool with given context. Initializes message queues according to configuration properties.
      Parameters:
        `context` - router context for environment access

  - ### Method Detail

    - #### add

          public int add(I2NPMessage messageBody,
                         RouterIdentity fromRouter,
                         Hash fromRouterHash)

      Adds a new inbound message to be processed.

      The message is either dispatched directly or queued for processing, depending on configuration. It supports detection of duplicates, expired messages, and dispatches messages to appropriate handlers or jobs.

      Parameters:
        `messageBody` - the inbound message to add, not null
        `fromRouter` - the router identity the message is from, may be null
        `fromRouterHash` - the hash of the router it is from, may be null (will be computed if so)
      Returns:
        -1 if message dropped due to validation or errors, 0 otherwise

    - #### add

          public int add(I2NPMessage messageBody,
                         RouterIdentity fromRouter,
                         Hash fromRouterHash,
                         long msgIDBloomXor)

      Adds a new inbound message with optional bloom filter XOR id.
      Parameters:
        `messageBody` - message to add (non-null)
        `fromRouter` - source router identity (may be null)
        `fromRouterHash` - source router hash (may be null, computed if null)
        `msgIDBloomXor` - XOR value for message unique ID in bloom filter
      Returns:
        -1 if invalid or duplicate message, 0 otherwise

    - #### handleReplies

          public int handleReplies(I2NPMessage messageBody)

      Handles replies for outbound messages that correspond to this inbound message.
      Parameters:
        `messageBody` - inbound message for which replies are handled
      Returns:
        count of original messages replied to

    - #### registerHandlerJobBuilder

          public HandlerJobBuilder registerHandlerJobBuilder(int i2npMessageType,
                                                             HandlerJobBuilder builder)

      Registers or replaces a HandlerJobBuilder for a given message type.
      Parameters:
        `i2npMessageType` - I2NP message type (0 to MAX_I2NP_MESSAGE_TYPE)
        `builder` - handler job builder for this type
      Returns:
        previous builder registered for this type, or null if none
      Throws:
        `ArrayIndexOutOfBoundsException` - if message type out of bounds

    - #### renderStatusHTML

          public void renderStatusHTML(Writer out)

      Render the status of this message pool as HTML. Package-private for use by the router console.
      Specified by:
        `renderStatusHTML` in interface `Service`
      Parameters:
        `out` - the Writer to output HTML to

    - #### restart

          public void restart()

      Restart the message pool by shutting down and then starting up again. Clears all queued messages and reinitializes the dispatcher.
      Specified by:
        `restart` in interface `Service`

    - #### shutdown

          public void shutdown()

      Shutdown the message pool, stopping all dispatchers and clearing queued messages.
      Specified by:
        `shutdown` in interface `Service`

    - #### startup

          public void startup()

      Startup the message pool and, if configured, start dispatcher threads.
      Specified by:
        `startup` in interface `Service`