java.lang.Object
net.i2p.router.transport.udp.PacketHandler
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 Summary
ConstructorsConstructorDescriptionPacketHandler(RouterContext ctx, UDPTransport transport, EstablishmentManager establisher, InboundMessageFragments inbound, PeerTestManager testManager, IntroductionManager introManager) Create a new packet handler.Method Summary
Modifier and TypeMethodDescription(package private) voidDynamically adjust handler thread count to match the target.intReturns the current number of active handler threads.(package private) StringThe handler status string.static intReturns the current max packet handler threads.intReturns the number of handlers actively processing packets (not parked on take()).doublePacket handler pool utilization as a ratio (0.0-1.0).voidqueueReceived(UDPPacket packet) Queue a received packet for processing.Blocking call to retrieve the next inbound packet, or null if we have shut down.static voidsetMaxHandlers(int handlers) The target max packet handler threads.voidshutdown()Shut down the packet handler.voidstartup()Start the packet handler.
Constructor Details
PacketHandler
PacketHandler(RouterContext ctx, UDPTransport transport, EstablishmentManager establisher, InboundMessageFragments inbound, PeerTestManager testManager, IntroductionManager introManager) Create a new packet handler.- Parameters:
ctx- the router contexttransport- the UDP transportestablisher- the establishment managerinbound- the inbound message fragmentstestManager- the peer test managerintroManager- the introduction manager
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 viaadjustThreads().- 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
Queue a received packet for processing.- Parameters:
packet- the received packet to hand to the inbound thread- Throws:
InterruptedException- if interrupted while waiting
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