net.i2p.i2ptunnel.udpTunnel

## Class I2PTunnelUDPClientBase

- java.lang.Object
- - net.i2p.util.EventDispatcherImpl
  - - net.i2p.i2ptunnel.I2PTunnelTask
    - - net.i2p.i2ptunnel.udpTunnel.I2PTunnelUDPClientBase

- All Implemented Interfaces:
    Sink, Source, EventDispatcher
  Direct Known Subclasses:
    SOCKSUDPTunnel, StreamrConsumer

      public abstract class I2PTunnelUDPClientBase
      extends I2PTunnelTask
      implements Source, Sink

  Base client class that sets up an I2P Datagram client destination. The UDP side is not implemented here, as there are at least two possibilities: 1) UDP side is a "server" Example: Streamr Consumer - Configure a destination host and port - External application sends no data - Extending class must have a constructor with host and port arguments 2) UDP side is a client/server Example: SOCKS UDP (DNS requests?) - configure an inbound port and a destination host and port - External application sends and receives data - Extending class must have a constructor with host and 2 port arguments So the implementing class must create a UDPSource and/or UDPSink, and must call setSink().

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected long` | `_clientId`
    `protected I2PAppContext` | `_context`
    `(package private) static long` | `DEFAULT_CONNECT_TIMEOUT`
    `protected Logging` | `l`

    - ### Fields inherited from class net.i2p.i2ptunnel.I2PTunnelTask

      `open, tunnel`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `I2PTunnelUDPClientBase(String destination, Logging l, EventDispatcher notifyThis, I2PTunnel tunnel)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `close(boolean forced)` Closes the tunnel and destroys the session.
    `void` | `send(Destination to, int fromPort, int toPort, byte[] data)` Sink Methods
    `void` | `setSink(Sink s)` Sets the receiver of the UDP datagrams from I2P.
    `void` | `start()` Starts the I2P source to begin receiving datagrams.
    `void` | `startRunning()` Starts the tunnel and begins processing datagrams.

    - ### Methods inherited from class net.i2p.i2ptunnel.I2PTunnelTask

      `connected, destroy, disconnected, errorOccurred, getBooleanOption, getId, getTunnel, isOpen, optionsUpdated, reportAbuse, routerDisconnected, setId, setName, setTunnel, toString`

    - ### Methods inherited from class net.i2p.util.EventDispatcherImpl

      `attachEventDispatcher, detachEventDispatcher, getEventDispatcher, getEvents, getEventValue, ignoreEvents, notifyEvent, unIgnoreEvents, waitEventValue`

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

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

- - ### Field Detail

    - #### _clientId

          protected long _clientId

    - #### _context

          protected I2PAppContext _context

    - #### DEFAULT_CONNECT_TIMEOUT

          static final long DEFAULT_CONNECT_TIMEOUT

      See Also:
        Constant Field Values

    - #### l

          protected Logging l

  - ### Constructor Detail

    - #### I2PTunnelUDPClientBase

          public I2PTunnelUDPClientBase(String destination,
                                        Logging l,
                                        EventDispatcher notifyThis,
                                        I2PTunnel tunnel)
                                 throws IllegalArgumentException

      Throws:
        `IllegalArgumentException` - if the I2CP configuration is b0rked so badly that we cant create a socketManager

  - ### Method Detail

    - #### close

          public boolean close(boolean forced)

      Closes the tunnel and destroys the session.
      Specified by:
        `close` in class `I2PTunnelTask`
      Parameters:
        `forced` - if true, force immediate close without graceful shutdown
      Returns:
        true if closed successfully

    - #### send

          public void send(Destination to,
                           int fromPort,
                           int toPort,
                           byte[] data)

      Sink Methods
      Specified by:
        `send` in interface `Sink`
      Parameters:
        `to` - - ignored if configured for a single destination (we use the dest specified in the constructor)
        `fromPort` - I2CP source port, 0-65535
        `toPort` - I2CP destination port, 0-65535
      Throws:
        `RuntimeException` - if session is closed

    - #### setSink

          public void setSink(Sink s)

      Sets the receiver of the UDP datagrams from I2P. Subclass must call this after constructor and before start().
      Specified by:
        `setSink` in interface `Source`
      Parameters:
        `s` - the sink to receive incoming datagrams

    - #### start

          public void start()

      Starts the I2P source to begin receiving datagrams.
      Specified by:
        `start` in interface `Source`

    - #### startRunning

          public void startRunning()

      Starts the tunnel and begins processing datagrams. Classes should override to start UDP side as well.