net.i2p.router.transport.udp

## Class PacketPusher

- java.lang.Object
- - net.i2p.router.transport.udp.PacketPusher

- All Implemented Interfaces:
    Runnable

      class PacketPusher
      extends Object
      implements Runnable

  Blocking thread to grab new packets off the outbound fragment pool and toss them onto the outbound packet queues. 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.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `PacketPusher(RouterContext ctx, OutboundMessageFragments fragments, List<UDPEndpoint> endpoints)` Constructs a PacketPusher instance.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `run()` The main loop for the packet pusher thread.
    `void` | `send(UDPPacket packet)` Sends a single UDP packet directly out by selecting an appropriate UDPEndpoint.
    `void` | `shutdown()` Stops the packet pusher thread.
    `void` | `startup()` Starts the packet pusher thread.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### PacketPusher

          public PacketPusher(RouterContext ctx,
                              OutboundMessageFragments fragments,
                              List<UDPEndpoint> endpoints)

      Constructs a PacketPusher instance.
      Parameters:
        `ctx` - the router context used to get the logger
        `fragments` - the outbound message fragment pool to pull packets from
        `endpoints` - a thread-safe or effectively immutable list of UDPEndpoints

  - ### Method Detail

    - #### run

          public void run()

      The main loop for the packet pusher thread. Continuously pulls packets from the fragment pool and sends them out via endpoints. Includes a blocking wait if no packets are currently available.
      Specified by:
        `run` in interface `Runnable`

    - #### send

          public void send(UDPPacket packet)

      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. TODO: Improve to track peer-specific endpoint and ensure consistent sending.
      Parameters:
        `packet` - the non-null UDPPacket to send

    - #### shutdown

          public void shutdown()

      Stops the packet pusher thread. This method is synchronized to prevent concurrent shutdown/startup races.

    - #### startup

          public void startup()

      Starts the packet pusher thread. This method is synchronized to prevent concurrent startups/shutdowns.