java.lang.Object
net.i2p.client.streaming.impl.PacketHandler
Handles incoming packets by dispatching them to the appropriate connection, server socket, or responding with a reset (RST) packet if no valid connection is found.
Packet flow: I2PSession -> MessageHandler -> PacketHandler -> ConnectionPacketHandler -> MessageInputStream.
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final intUpper bound on inbound receive workers per manager.(package private) static final StringProperty limiting the number of inbound packet receive workers per connection manager.(package private) static final intPer-shard inbound queue capacity.Constructor Summary
ConstructorsConstructorDescriptionPacketHandler(I2PAppContext ctx, ConnectionManager mgr) Stores the context and manager, and opens the logger for the class.Method Summary
Modifier and TypeMethodDescription(package private) voiddisplayPacket(Packet packet, String prefix, String suffix) Logs the provided packet at debug level with a timestamp.(package private) voidreceivePacket(Packet packet) Receives a packet and dispatches it to the appropriate handler.(package private) voidreceivePacketDirect(Packet packet, boolean queueIfNoConn) Processes the packet immediately, optionally queuing if no connection is found.voidsendResetUnverified(Packet packet) Sends a reset packet back to the sender without verifying the packet signature.(package private) voidShut down the receive workers, if any were created, releasing queued packets.(package private) static intworkerCountFor(int cores, String configured, int override) Clamped inbound receive worker count for a manager.
Field Details
PROP_RECEIVE_WORKERS
Property limiting the number of inbound packet receive workers per connection manager. Unset or invalid values fall back to the platform core count.- See Also:
MAX_RECEIVE_WORKERS
static final int MAX_RECEIVE_WORKERSUpper bound on inbound receive workers per manager.- See Also:
RECEIVE_QUEUE_CAPACITY
static final int RECEIVE_QUEUE_CAPACITYPer-shard inbound queue capacity. A full queue back-pressures the session notifier thread rather than dropping or reordering packets.- See Also:
Constructor Details
PacketHandler
Stores the context and manager, and opens the logger for the class.- Parameters:
ctx- the app context used for logging, properties and packet verificationmgr- the connection manager whose connections dispatch inbound packets
Method Details
receivePacket
Receives a packet and dispatches it to the appropriate handler.- Parameters:
packet- the packet to process
receivePacketDirect
Processes the packet immediately, optionally queuing if no connection is found.- Parameters:
packet- the packet to processqueueIfNoConn- queue the packet if no matching connection exists
shutdownDispatcher
void shutdownDispatcher()Shut down the receive workers, if any were created, releasing queued packets. Called fromConnectionManager.shutdown(); idempotent.workerCountFor
Clamped inbound receive worker count for a manager.The Tuner's live default wins when positive, so runtime tuning applies to managers created after the adjustment; otherwise a positive configured property value wins (capped at
MAX_RECEIVE_WORKERS); otherwise the platform core count is used, floored at 2 for low-core hosts. Package-visible for unit tests.- Parameters:
cores- available processors at startupconfigured- raw property value, may be nulloverride- Tuner global default, 0 = not armed- Returns:
- the worker count, in 1..MAX_RECEIVE_WORKERS
displayPacket
sendResetUnverified
Sends a reset packet back to the sender without verifying the packet signature. Packet MUST have a FROM option.- Parameters:
packet- the received packet to answer; must carry a FROM option