net.i2p.router.tunnel

## Class TunnelGateway

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

- Direct Known Subclasses:
    PumpedTunnelGateway, TunnelGatewayZeroHop

      abstract class TunnelGateway
      extends Object

  Serve as the gatekeeper for a tunnel, accepting messages, coalescing and/or fragmenting them before wrapping them up for tunnel delivery. The flow here is:
  1. add an I2NPMessage (and a target tunnel/router, if necessary)
  2. that message is queued up into a TunnelGateway.Pending and offered to the assigned QueuePreprocessor.
  3. that QueuePreprocessor may then take off any of the TunnelGateway.Pending messages or instruct the TunnelGateway to offer it the messages again in a short while (in an attempt to coalesce them).
  4. when the QueueProcessor accepts a TunnelGateway.Pending, it preprocesses it into fragments, forwarding each preprocessed fragment group through the Sender.
  5. the Sender then encrypts the preprocessed data and delivers it to the Receiver.
  6. the Receiver now has the encrypted message and may do with it as it pleases (e.g. wrap it as necessary and enqueue it onto the OutNetMessagePool, or if debugging, verify that it can be decrypted properly)
  Unused directly - see PumpedTunnelGateway, ThrottledPumpedTunnelGateway, and TunnelGatewayZeroHop overrides.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected class` | `TunnelGateway.DelayedFlush`
    `static interface` | `TunnelGateway.QueuePreprocessor` Interface for preprocessing queued tunnel messages.
    `static interface` | `TunnelGateway.Receiver` Interface for receiving encrypted tunnel data.
    `static interface` | `TunnelGateway.Sender` Interface for sending preprocessed tunnel data.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected RouterContext` | `_context`
    `protected TunnelGateway.DelayedFlush` | `_delayedFlush`
    `protected long` | `_lastFlush`
    `protected Log` | `_log`
    `protected int` | `_messagesSent`
    `protected TunnelGateway.QueuePreprocessor` | `_preprocessor`
    `protected List<PendingGatewayMessage>` | `_queue`
    `protected TunnelGateway.Receiver` | `_receiver`
    `protected TunnelGateway.Sender` | `_sender`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `TunnelGateway(RouterContext context, TunnelGateway.QueuePreprocessor preprocessor, TunnelGateway.Sender sender, TunnelGateway.Receiver receiver)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(I2NPMessage msg, Hash toRouter, TunnelId toTunnel)` Add a message to be sent down the tunnel, either sending it now (perhaps coalesced with other pending messages) or after a brief pause (_flushFrequency).
    `void` | `add(TunnelGatewayMessage msg)` Add a message to be sent down the tunnel, where we are the inbound gateway.
    `int` | `getMessagesSent()`

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

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

- - ### Field Detail

    - #### _context

          protected final RouterContext _context

    - #### _delayedFlush

          protected final TunnelGateway.DelayedFlush _delayedFlush

    - #### _lastFlush

          protected long _lastFlush

    - #### _log

          protected final Log _log

    - #### _messagesSent

          protected int _messagesSent

    - #### _preprocessor

          protected final TunnelGateway.QueuePreprocessor _preprocessor

    - #### _queue

          protected final List<PendingGatewayMessage> _queue

    - #### _receiver

          protected final TunnelGateway.Receiver _receiver

    - #### _sender

          protected final TunnelGateway.Sender _sender

  - ### Constructor Detail

    - #### TunnelGateway

          protected TunnelGateway(RouterContext context,
                                  TunnelGateway.QueuePreprocessor preprocessor,
                                  TunnelGateway.Sender sender,
                                  TunnelGateway.Receiver receiver)

      Parameters:
        `preprocessor` - this pulls Pending messages off a list, builds some full preprocessed messages, and pumps those into the sender
        `sender` - this takes a preprocessed message, encrypts it, and sends it to the receiver
        `receiver` - this receives the encrypted message and forwards it off to the first hop

  - ### Method Detail

    - #### add

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

      Add a message to be sent down the tunnel, either sending it now (perhaps coalesced with other pending messages) or after a brief pause (_flushFrequency). If it is queued up past its expiration, it is silently dropped UNUSED - see overrides
      Parameters:
        `msg` - message to be sent through the tunnel
        `toRouter` - router to send to after the endpoint (or null for endpoint processing)
        `toTunnel` - tunnel to send to after the endpoint (or null for endpoint or router processing)

    - #### add

          public void add(TunnelGatewayMessage msg)

      Add a message to be sent down the tunnel, where we are the inbound gateway.
      Parameters:
        `msg` - message received to be sent through the tunnel

    - #### getMessagesSent

          public int getMessagesSent()