net.i2p.router.transport.udp

## Class UDPSender

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

-     class UDPSender
      extends Object

  Lowest level UDP packet sender that pushes packets from its queue ASAP.

  Each UDPSender instance corresponds to a UDPEndpoint, owning its own dedicated sending thread and queue. Packets to be sent are enqueued by the PacketPusher.

  This class utilizes a CoDel-based priority blocking queue to limit packet queueing delay and manages bandwidth throttling for sending.

  Supports graceful startup and shutdown signaling using a poison packet.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `PROP_CODEL_INTERVAL`
    `static String` | `PROP_CODEL_TARGET`
    `(package private) static long[]` | `RATES` Time rate intervals for statistics collection.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `UDPSender(RouterContext ctx, DatagramSocket socket, String name, SocketListener lsnr)` Constructs a UDPSender with the given context, socket, name, and endpoint listener.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(UDPPacket packet)` Adds a UDP packet to the send queue.
    `void` | `clear()` Clears the outbound packet queue.
    `boolean` | `fullStats()` Returns whether detailed full statistics gathering is enabled.
    `void` | `shutdown()` Gracefully shuts down the UDP sender thread.
    `void` | `startup()` Starts the UDP sender thread.

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

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

- - ### Field Detail

    - #### PROP_CODEL_INTERVAL

          public static final String PROP_CODEL_INTERVAL

      See Also:
        Constant Field Values

    - #### PROP_CODEL_TARGET

          public static final String PROP_CODEL_TARGET

      See Also:
        Constant Field Values

    - #### RATES

          static final long[] RATES

      Time rate intervals for statistics collection.

  - ### Constructor Detail

    - #### UDPSender

          public UDPSender(RouterContext ctx,
                           DatagramSocket socket,
                           String name,
                           SocketListener lsnr)

      Constructs a UDPSender with the given context, socket, name, and endpoint listener. Initializes the CoDel priority queue and all relevant rate statistics trackers.
      Parameters:
        `ctx` - the router context
        `socket` - the UDP datagram socket to send packets on
        `name` - thread name identifier for this sender
        `lsnr` - the associated socket listener endpoint

  - ### Method Detail

    - #### add

          public void add(UDPPacket packet)

      Adds a UDP packet to the send queue.

      This operation blocks if the queue is full, which may back up the PacketPusher thread. Packets that are too large or too small are dropped or warned respectively. Bandwidth requests for the packet are initiated before queueing.

      Parameters:
        `packet` - the UDP packet to enqueue for sending

    - #### clear

          public void clear()

      Clears the outbound packet queue.

      Typically used in preparation for sending destroy notifications.

    - #### fullStats

          public boolean fullStats()

      Returns whether detailed full statistics gathering is enabled.
      Returns:
        true if full stats are enabled, false otherwise

    - #### shutdown

          public void shutdown()

      Gracefully shuts down the UDP sender thread.

      Clears the outbound queue and signals the runner thread to stop by enqueueing a poison packet. Waits briefly for the queue to drain.

    - #### startup

          public void startup()

      Starts the UDP sender thread.

      This method cannot be called more than once as the socket is final.