net.i2p.router.tunnel

## Class PumpedTunnelGateway

- java.lang.Object
- - net.i2p.router.tunnel.TunnelGateway
  - - net.i2p.router.tunnel.PumpedTunnelGateway

- Direct Known Subclasses:
    ThrottledPumpedTunnelGateway

      class PumpedTunnelGateway
      extends TunnelGateway

  This class represents a tunnel gateway with multiple hops that accepts messages, then coalesces and fragments them before sending them down the tunnel. The processing flow is:
  1. add an I2NPMessage (and optionally, the target router or tunnel)
  2. messages queue in this PumpedTunnelGateway's internal _prequeue
  3. QueuePreprocessor pulls PendingGatewayMessages from _prequeue and processes them
  4. Fragments are sent to Sender, encrypted, and delivered to the Receiver
  5. Receiver directs the message to the next tunnel hop or endpoint
  This class uses specialized CoDel queues to manage queue delays and bufferbloat. The outbound gateway uses a priority queue, while inbound uses a bounded non-priority queue. Thread safety:
  - _prequeue is a thread-safe blocking queue managing pending messages
  - _queue is synchronized for modifications and preprocessing
  - Expiration pruning is done outside locks to minimize contention
  - The pump() method is safe for concurrent invocation by pumper threads

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class net.i2p.router.tunnel.TunnelGateway

      `TunnelGateway.DelayedFlush, TunnelGateway.QueuePreprocessor, TunnelGateway.Receiver, TunnelGateway.Sender`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `boolean` | `_isInbound`
    `static String` | `PROP_INITIAL_OB_QUEUE`
    `static String` | `PROP_MAX_IB_MSGS_PER_PUMP`
    `static String` | `PROP_MAX_IB_QUEUE`
    `static String` | `PROP_MAX_OB_MSGS_PER_PUMP`

    - ### Fields inherited from class net.i2p.router.tunnel.TunnelGateway

      `_context, _delayedFlush, _lastFlush, _log, _messagesSent, _preprocessor, _queue, _receiver, _sender`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PumpedTunnelGateway(RouterContext context, TunnelGateway.QueuePreprocessor preprocessor, TunnelGateway.Sender sender, TunnelGateway.Receiver receiver, TunnelGatewayPumper pumper)` Constructs a PumpedTunnelGateway instance.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(I2NPMessage msg, Hash toRouter, TunnelId toTunnel)` Adds a message to be sent down the tunnel.
    `protected void` | `add(PendingGatewayMessage cur)` Adds a PendingGatewayMessage to the prequeue and notifies the pumper to process it.
    `boolean` | `pump(List<PendingGatewayMessage> queueBuf)` Pumps messages from the internal prequeue into the processing queue.

    - ### Methods inherited from class net.i2p.router.tunnel.TunnelGateway

      `add, getMessagesSent`

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

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

- - ### Field Detail

    - #### _isInbound

          public final boolean _isInbound

    - #### PROP_INITIAL_OB_QUEUE

          public static final String PROP_INITIAL_OB_QUEUE

      See Also:
        Constant Field Values

    - #### PROP_MAX_IB_MSGS_PER_PUMP

          public static final String PROP_MAX_IB_MSGS_PER_PUMP

      See Also:
        Constant Field Values

    - #### PROP_MAX_IB_QUEUE

          public static final String PROP_MAX_IB_QUEUE

      See Also:
        Constant Field Values

    - #### PROP_MAX_OB_MSGS_PER_PUMP

          public static final String PROP_MAX_OB_MSGS_PER_PUMP

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### PumpedTunnelGateway

          public PumpedTunnelGateway(RouterContext context,
                                     TunnelGateway.QueuePreprocessor preprocessor,
                                     TunnelGateway.Sender sender,
                                     TunnelGateway.Receiver receiver,
                                     TunnelGatewayPumper pumper)

      Constructs a PumpedTunnelGateway instance. Outbound gateways use an unbounded priority queue; inbound gateways use a bounded blocking queue.
      Parameters:
        `context` - RouterContext
        `preprocessor` - QueuePreprocessor responsible for preprocessing messages
        `sender` - Sender responsible for encrypting and delivering messages
        `receiver` - Receiver that consumes encrypted messages for forwarding
        `pumper` - TunnelGatewayPumper managing pumping threads

  - ### Method Detail

    - #### add

          public void add(I2NPMessage msg,
                          Hash toRouter,
                          TunnelId toTunnel)

      Adds a message to be sent down the tunnel. If the prequeue is full, the message is dropped silently and a statistic is updated. This method is optimized for outbound gateways and called by TPTG for inbound.
      Overrides:
        `add` in class `TunnelGateway`
      Parameters:
        `msg` - the message to send
        `toRouter` - optional target router
        `toTunnel` - optional target tunnel

    - #### add

          protected void add(PendingGatewayMessage cur)

      Adds a PendingGatewayMessage to the prequeue and notifies the pumper to process it.
      Parameters:
        `cur` - the PendingGatewayMessage to add

    - #### pump

          public boolean pump(List<PendingGatewayMessage> queueBuf)

      Pumps messages from the internal prequeue into the processing queue. This method tries to drain a bounded number of messages from _prequeue into the provided queueBuf, then adds them to the internal _queue for preprocessing and fragmentation. Expired messages are removed after preprocessing, outside the synchronization block, to reduce contention.
      Parameters:
        `queueBuf` - an empty list used as a temporary buffer for messages (will be cleared before return)
      Returns:
        true if there are still messages remaining in _prequeue and the caller should requeue this gateway