java.lang.Object
net.i2p.router.transport.udp.PacketHandler

class PacketHandlerextends Object
Pull inbound packets from the inbound receiver's queue, figure out what peer session they belong to (if any), authenticate and decrypt them with the appropriate keys, and push them to the appropriate handler. Data and ACK packets go to the InboundMessageFragments, the various establishment packets go to the EstablishmentManager, and, once implemented, relay packets will go to the relay manager. At the moment, this is an actual pool of packet handler threads, each pulling off the inbound receiver's queue and pushing them as necessary.

Supports dynamic thread count adjustment via adjustThreads().

  • Constructor Details

  • Method Details

    • getMaxHandlers

      public static int getMaxHandlers()
      Returns the current max packet handler threads.
      Returns:
      the max handlers
    • setMaxHandlers

      public static void setMaxHandlers(int handlers)
      The target max packet handler threads. Takes effect immediately via adjustThreads().
      Parameters:
      handlers - the new max handlers
    • getActiveHandlers

      public int getActiveHandlers()
      Returns the current number of active handler threads.
      Returns:
      the active handler count
    • getProcessingCount

      public int getProcessingCount()
      Returns the number of handlers actively processing packets (not parked on take()).
      Returns:
      the processing count
    • getUtilization

      public double getUtilization()
      Packet handler pool utilization as a ratio (0.0-1.0). Returns NaN if not started.
      Returns:
      the utilization ratio
    • startup

      public void startup()
      Start the packet handler.
    • shutdown

      public void shutdown()
      Shut down the packet handler.
    • adjustThreads

      void adjustThreads()
      Dynamically adjust handler thread count to match the target. Handlers are added or removed one at a time. Excess handlers receive a poison packet and exit cleanly.
    • getHandlerStatus

      String getHandlerStatus()
      The handler status string.
      Returns:
      a summary listing how many handlers are currently active, followed by one "handler i" entry per handler in the pool
    • queueReceived

      public void queueReceived(UDPPacket packet) throws InterruptedException
      Queue a received packet for processing.
      Parameters:
      packet - the received packet to hand to the inbound thread
      Throws:
      InterruptedException - if interrupted while waiting
    • receiveNext

      public UDPPacket receiveNext()
      Blocking call to retrieve the next inbound packet, or null if we have shut down.
      Returns:
      the next packet, or null if shut down