java.lang.Object
net.i2p.router.InNetMessagePool
- All Implemented Interfaces:
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.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classWrapper class to pair tunnel data messages with their sender hash.private classJob to sequentially dispatch all queued tunnel data messages.private classJob to sequentially dispatch all queued tunnel gateway messages.private classDispatcher thread that consumes queued tunnel data messages.private classDispatcher thread that consumes queued tunnel gateway messages.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicBooleanTrue while the pool is running.private final RouterContextThe router context.private final booleanTrue to handle messages on job threads.private final HandlerJobBuilder[]Job builders, indexed by message type.private final LogLogger for the message pool.private final LinkedBlockingQueue<InNetMessagePool.QueuedMessage> Concurrent queue for pending tunnel data messages with their sender hashes.private final LinkedBlockingQueue<I2NPMessage> Messages waiting for a gateway job.Job handling messages on the caller's thread.Gateway job handling messages directly.private static final booleanDefault for direct dispatch.private static final booleanDefault for threaded dispatch.private final booleanTrue to handle some messages without a job.private static final intClock latitude allowed for delivery times.private static final intMaximum valid I2NP message type.private static final StringConfig key for direct dispatch.private static final StringConfig flags for dispatch mode.private static final long[]Rate stat periods for the pool statistics.Constructor Summary
ConstructorsConstructorDescriptionInNetMessagePool(RouterContext context) Message pool for processing inbound I2NP messages.Method Summary
Modifier and TypeMethodDescriptionintadd(I2NPMessage messageBody, RouterIdentity fromRouter, Hash fromRouterHash) Adds a new inbound message to be processed.intadd(I2NPMessage messageBody, RouterIdentity fromRouter, Hash fromRouterHash, long msgIDBloomXor) Adds a new inbound message with optional bloom filter XOR id.private voiddoShortCircuitTunnelData(I2NPMessage messageBody, Hash from) Actual direct dispatch of a tunnel data message.private voiddoShortCircuitTunnelGateway(I2NPMessage messageBody) Actual direct dispatch of a tunnel gateway message.private voidhandleDroppedUnmatchedMessage(I2NPMessage messageBody, RouterIdentity fromRouter, Hash fromRouterHash, boolean doHistory) Handles dropping messages that are not matched or handled.private voidhandleInvalidMessage(I2NPMessage messageBody, String invalidReason, RouterIdentity fromRouter, Hash fromRouterHash, boolean doHistory, long msgIDBloomXor) Handles invalid or duplicate messages by logging, statistics updates, and history recording.inthandleReplies(I2NPMessage messageBody) Handles replies for outbound messages that correspond to this inbound message.private booleanprocessDatabaseStoreMessage(I2NPMessage messageBody, RouterIdentity fromRouter, Hash fromRouterHash, boolean doHistory) Processes DatabaseStoreMessage types by running or queueing corresponding jobs.registerHandlerJobBuilder(int i2npMessageType, HandlerJobBuilder builder) Registers or replaces a HandlerJobBuilder for a given message type.voidrenderStatusHTML(Writer out) Render the status of this message pool as HTML.voidrestart()Restart the message pool by shutting down and then starting up again.private voidshortCircuitTunnelData(I2NPMessage messageBody, Hash from) Shortcut dispatch tunnel data message either directly or queued.private voidshortCircuitTunnelGateway(I2NPMessage messageBody) Shortcut dispatch tunnel gateway message either directly or queued.voidshutdown()Shutdown the message pool, stopping all dispatchers and clearing queued messages.voidstartup()Startup the message pool and, if configured, start dispatcher threads.
Field Details
_log
Logger for the message pool._context
The router context._handlerJobBuilders
Job builders, indexed by message type._pendingDataMessages
Concurrent queue for pending tunnel data messages with their sender hashes. Used only when dispatching is not direct. Uses QueuedMessage wrapper to ensure message/sender pairing is preserved._pendingGatewayMessages
Messages waiting for a gateway job._shortCircuitDataJob
Job handling messages on the caller's thread._shortCircuitGatewayJob
Gateway job handling messages directly._alive
True while the pool is running._dispatchThreaded
private final boolean _dispatchThreadedTrue to handle messages on job threads.PROP_DISPATCH_THREADED
Config flags for dispatch mode.- See Also:
DEFAULT_DISPATCH_THREADED
private static final boolean DEFAULT_DISPATCH_THREADEDDefault for threaded dispatch.- See Also:
PROP_DISPATCH_DIRECT
Config key for direct dispatch.- See Also:
DEFAULT_DISPATCH_DIRECT
private static final boolean DEFAULT_DISPATCH_DIRECTDefault for direct dispatch.- See Also:
DISPATCH_DIRECT
private final boolean DISPATCH_DIRECTTrue to handle some messages without a job.MAX_I2NP_MESSAGE_TYPE
private static final int MAX_I2NP_MESSAGE_TYPEMaximum valid I2NP message type.- See Also:
MAX_DELIVERY_SKEW
private static final int MAX_DELIVERY_SKEWClock latitude allowed for delivery times.- See Also:
RATES
private static final long[] RATESRate stat periods for the pool statistics.
Constructor Details
InNetMessagePool
Message pool for processing inbound I2NP messages. Initializes message queues according to configuration properties.- Parameters:
context- router context for environment access
Method Details
registerHandlerJobBuilder
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
add
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 nullfromRouter- the router identity the message is from, may be nullfromRouterHash- 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
handleInvalidMessage
private void handleInvalidMessage(I2NPMessage messageBody, String invalidReason, RouterIdentity fromRouter, Hash fromRouterHash, boolean doHistory, long msgIDBloomXor) Handles invalid or duplicate messages by logging, statistics updates, and history recording.- Parameters:
messageBody- the message being droppedinvalidReason- lower-case reason, capitalized in the log; containing "expire" counts the drop as expired rather than duplicatefromRouter- the sender's identity, or null if unknownfromRouterHash- the sender's hash, used when fromRouter is nulldoHistory- true to record the drop in the message historymsgIDBloomXor- the XOR applied to the message id for the history entry
processDatabaseStoreMessage
private boolean processDatabaseStoreMessage(I2NPMessage messageBody, RouterIdentity fromRouter, Hash fromRouterHash, boolean doHistory) Processes DatabaseStoreMessage types by running or queueing corresponding jobs.- Parameters:
messageBody- the DatabaseStoreMessage to processfromRouter- the sender's identity, or null if unknownfromRouterHash- the sender's hashdoHistory- whether to record in the message history, currently unused- Returns:
- always true, a job was run or queued
handleDroppedUnmatchedMessage
private void handleDroppedUnmatchedMessage(I2NPMessage messageBody, RouterIdentity fromRouter, Hash fromRouterHash, boolean doHistory) Handles dropping messages that are not matched or handled.- Parameters:
messageBody- the unmatched message being droppedfromRouter- the sender's identity, or null if unknownfromRouterHash- the sender's hash, used when fromRouter is nulldoHistory- true to record the drop in the message history
handleReplies
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
shortCircuitTunnelGateway
Shortcut dispatch tunnel gateway message either directly or queued.- Parameters:
messageBody- the tunnel gateway message
doShortCircuitTunnelGateway
Actual direct dispatch of a tunnel gateway message.- Parameters:
messageBody- the tunnel gateway message
shortCircuitTunnelData
Shortcut dispatch tunnel data message either directly or queued.- Parameters:
messageBody- the tunnel data messagefrom- source router hash
doShortCircuitTunnelData
Actual direct dispatch of a tunnel data message.- Parameters:
messageBody- the tunnel data messagefrom- source router hash
renderStatusHTML
Render the status of this message pool as HTML. Package-private for use by the router console.- Specified by:
renderStatusHTMLin interfaceService- Parameters:
out- the Writer to output HTML to
restart
shutdown
startup