java.lang.Object
net.i2p.client.streaming.impl.PacketHandler

class PacketHandlerextends Object
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 Details

    • PROP_RECEIVE_WORKERS

      static final String 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_WORKERS
      Upper bound on inbound receive workers per manager.
      See Also:
    • RECEIVE_QUEUE_CAPACITY

      static final int RECEIVE_QUEUE_CAPACITY
      Per-shard inbound queue capacity. A full queue back-pressures the session notifier thread rather than dropping or reordering packets.
      See Also:
  • Constructor Details

    • PacketHandler

      public PacketHandler(I2PAppContext ctx, ConnectionManager mgr)
      Stores the context and manager, and opens the logger for the class.
      Parameters:
      ctx - the app context used for logging, properties and packet verification
      mgr - the connection manager whose connections dispatch inbound packets
  • Method Details

    • receivePacket

      void receivePacket(Packet packet)
      Receives a packet and dispatches it to the appropriate handler.
      Parameters:
      packet - the packet to process
    • receivePacketDirect

      void receivePacketDirect(Packet packet, boolean queueIfNoConn)
      Processes the packet immediately, optionally queuing if no connection is found.
      Parameters:
      packet - the packet to process
      queueIfNoConn - queue the packet if no matching connection exists
    • shutdownDispatcher

      void shutdownDispatcher()
      Shut down the receive workers, if any were created, releasing queued packets. Called from ConnectionManager.shutdown(); idempotent.
    • workerCountFor

      static int workerCountFor(int cores, String configured, int override)
      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 startup
      configured - raw property value, may be null
      override - Tuner global default, 0 = not armed
      Returns:
      the worker count, in 1..MAX_RECEIVE_WORKERS
    • displayPacket

      void displayPacket(Packet packet, String prefix, String suffix)
      Logs the provided packet at debug level with a timestamp.
      Parameters:
      packet - the packet to log
      prefix - text prefix (e.g., "RECV" or "UNKN")
      suffix - additional info appended after the packet string, may be null
    • sendResetUnverified

      public void sendResetUnverified(Packet packet)
      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