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

public abstract class I2PTunnelUDPClientBaseextends 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(Sink).

  • Field Details

    • _context

      protected I2PAppContext _context
      The I2P app context.
    • l

      protected Logging l
      Logging instance.
    • DEFAULT_CONNECT_TIMEOUT

      static final long DEFAULT_CONNECT_TIMEOUT
      Default connect timeout.
      See Also:
    • __clientId

      private static final AtomicLong __clientId
      Counts the client ids handed out.
    • _clientId

      protected long _clientId
      Unique client identifier.
    • startLock

      private final Object startLock
      Guards starting the destination's sockets.
    • _session

      private final I2PSession _session
      The session carrying the datagrams.
    • _i2pSource

      private final Source _i2pSource
      Reads datagrams arriving from I2P.
    • _i2pSink

      private final Sink _i2pSink
      Sends datagrams out over I2P.
  • Constructor Details

    • I2PTunnelUDPClientBase

      public I2PTunnelUDPClientBase(String destination, Logging l, EventDispatcher notifyThis, I2PTunnel tunnel) throws IllegalArgumentException
      Set up the I2P client, destination keypair, and I2CP session for this tunnel.
      Parameters:
      destination - I2P destination to send to; null for send-to-anyone
      l - the logging facility used for this tunnel's output
      notifyThis - event dispatcher for notifications
      tunnel - the parent tunnel, supplying the context and I2CP options
      Throws:
      IllegalArgumentException - if the I2CP configuration is so broken that we can't create a socketManager
  • Method Details

    • startRunning

      public void startRunning()
      Starts the tunnel and begins processing datagrams. Classes should override to start UDP side as well.
    • 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
    • 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
    • send

      public void send(Destination to, int fromPort, int toPort, byte[] data)
      Sends data through the I2P sink to the configured destination.
      Specified by:
      send in interface Sink
      Parameters:
      to - the destination to send to, ignored if configured for a single destination
      fromPort - I2CP source port, 0-65535
      toPort - I2CP destination port, 0-65535
      data - the data to send
      Throws:
      RuntimeException - if the session is closed