- All Implemented Interfaces:
Runnable
This class runs a dedicated thread that continuously pulls batches of UDP packets from the OutboundMessageFragments pool and sends them out through appropriate UDPEndpoints based on the packet IP version.
Thread safety is improved by using concurrent safe collections and volatile flag visibility.
Endpoint selection currently picks the first matching endpoint for IPv4 or IPv6.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanFalse once the job has been cancelled.private final List<UDPEndpoint> Endpoints to push to, in a thread-safe copy-on-write list, for safe concurrent iterations with minimal locking.private final OutboundMessageFragmentsWhere outgoing messages are fragmented.private final LogLogger for this class.private ThreadThe thread running the push loop.private static final longIdle backoff, used only if the fragment pool ever comes back empty while alive.Constructor Summary
ConstructorsConstructorDescriptionPacketPusher(RouterContext ctx, OutboundMessageFragments fragments, List<UDPEndpoint> endpoints) Creates the packet pusher.Method Summary
All Methods
Field Details
_log
Logger for this class._fragments
Where outgoing messages are fragmented._endpoints
Endpoints to push to, in a thread-safe copy-on-write list, for safe concurrent iterations with minimal locking._alive
private volatile boolean _aliveFalse once the job has been cancelled._thread
The thread running the push loop.IDLE_BACKOFF_MS
private static final long IDLE_BACKOFF_MSIdle backoff, used only if the fragment pool ever comes back empty while alive.- See Also:
Constructor Details
PacketPusher
public PacketPusher(RouterContext ctx, OutboundMessageFragments fragments, List<UDPEndpoint> endpoints) Creates the packet pusher.- Parameters:
ctx- the router context used to get the loggerfragments- the outbound message fragment pool to pull packets fromendpoints- a thread-safe or effectively immutable list of UDPEndpoints
Method Details
startup
public void startup()Starts the packet pusher thread. This method is synchronized to prevent concurrent startups/shutdowns.Left at
Thread.NORM_PRIORITY, which is whatI2PThreadsets. This was the only router thread at MAX_PRIORITY, so when the pool had nothing to send its spin preempted every other router thread; a local inefficiency became a router-wide latency problem.shutdown
public void shutdown()Stops the packet pusher thread. This method is synchronized to prevent concurrent shutdown/startup races.run
send
Sends a single UDP packet directly out by selecting an appropriate UDPEndpoint. This bypasses the outbound fragment pool's queue and only blocks if the endpoint queue is full.Endpoint selection tries to match the packet's IP version to an endpoint's IP version.
Tracked limitation: the first endpoint of the matching family wins, so packets to different peers on the same family can leave over different sockets. A per-peer endpoint affinity would keep a session on one socket for its lifetime; nothing here depends on that today, because the reply path keys off the peer's RouterIdentity rather than the local socket.
- Parameters:
packet- the non-null UDPPacket to send