net.i2p.router.tunnel

## Class ThrottledPumpedTunnelGateway

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

-     class ThrottledPumpedTunnelGateway
      extends PumpedTunnelGateway

  Specialized pumped tunnel gateway for inbound gateways (IBGWs) that throttles messages by checking bandwidth usage before queuing them. This class drops messages early based on bandwidth heuristics to more efficiently preserve network and system resources compared to processing fragments. The drop decision is made here instead of deeper in the tunnel to allow dropping whole I2NP messages, where message type and size are known accurately. Thread safety and behavior otherwise follows PumpedTunnelGateway.

- - ### 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 inherited from class net.i2p.router.tunnel.PumpedTunnelGateway

      `_isInbound, PROP_INITIAL_OB_QUEUE, PROP_MAX_IB_MSGS_PER_PUMP, PROP_MAX_IB_QUEUE, 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
    `ThrottledPumpedTunnelGateway(RouterContext context, TunnelGateway.QueuePreprocessor preprocessor, TunnelGateway.Sender sender, TunnelGateway.Receiver receiver, TunnelGatewayPumper pumper, HopConfig config)` Constructs a ThrottledPumpedTunnelGateway with bandwidth throttling.

  - ### 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 the inbound gateway after a bandwidth-based drop check.
    `String` | `toString()` Human-readable description differentiating inbound gateway and including tunnel ID.

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

      `add, pump`

    - ### 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, wait, wait, wait`

- - ### Constructor Detail

    - #### ThrottledPumpedTunnelGateway

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

      Constructs a ThrottledPumpedTunnelGateway with bandwidth throttling. Allocated bandwidth value is retrieved from config or set to reasonable default.
      Parameters:
        `context` - RouterContext
        `preprocessor` - QueuePreprocessor for the gateway
        `sender` - Encrypting Sender for fragments
        `receiver` - Receiving entity consuming encrypted messages
        `pumper` - TunnelGatewayPumper managing pumping threads
        `config` - HopConfig containing bandwidth and message statistics

  - ### Method Detail

    - #### add

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

      Adds a message to the inbound gateway after a bandwidth-based drop check. Drops messages early based on estimated size and bandwidth usage, tracking statistics. We do this here instead of in the InboundGatewayReceiver because it is much smarter to drop whole I2NP messages, where we know the message type and length, rather than tunnel messages containing I2NP fragments. Hard to do this exactly, but we'll assume 2:1 batching for the purpose of estimating outgoing size. We assume that it's the outbound bandwidth that is the issue...
      Overrides:
        `add` in class `PumpedTunnelGateway`
      Parameters:
        `msg` - the I2NP message to add
        `toRouter` - optional target router after the endpoint
        `toTunnel` - optional target tunnel after the endpoint

    - #### toString

          public String toString()

      Human-readable description differentiating inbound gateway and including tunnel ID.
      Overrides:
        `toString` in class `Object`
      Returns:
        String description of this inbound pumped tunnel gateway