All Implemented Interfaces:
Sink, Source, EventDispatcher
Direct Known Subclasses:
StreamrProducer

public class I2PTunnelUDPServerBaseextends I2PTunnelTask implements Source, Sink
Base client class that sets up an I2P Datagram server destination. The UDP side is not implemented here, as there are at least two possibilities:

1) UDP side is a "client" Example: Streamr Producer - configure an inbound port - External application receives no data - Extending class must have a constructor with a port argument

2) UDP side is a client/server Example: DNS - 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

    • _log

      private final Log _log
      The log this server writes to, distinct from the console-bound l.
    • lock

      private final Object lock
      Held while shutting down and reconfiguring, so those cannot overlap.
    • slock

      protected Object slock
      Held while a read or write is in flight on the client's socket.
    • l

      protected Logging l
      The logging facility the owning tunnel reports through.
    • DEFAULT_READ_TIMEOUT

      private static final long DEFAULT_READ_TIMEOUT
      Reads wait forever unless the config says otherwise.
      See Also:
    • readTimeout

      protected long readTimeout
      Default timeout to 3 minutes - override if desired.
    • _session

      private I2PSession _session
      The session carrying the datagrams.
    • _i2pSource

      private Source _i2pSource
      Reads datagrams arriving from I2P.
    • _i2pSink

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

    • I2PTunnelUDPServerBase

      public I2PTunnelUDPServerBase(File privkey, String privkeyname, Logging l, EventDispatcher notifyThis, I2PTunnel tunnel)
      Creates a UDP server tunnel using the private key in the given file.
      Parameters:
      privkey - file containing the private key for the destination
      privkeyname - name of the private key file
      l - the logging facility reporting to the console and logs
      notifyThis - event dispatcher for notifications
      tunnel - the owning I2PTunnel, which supplies the client options and context
      Throws:
      IllegalArgumentException - if the I2CP configuration is b0rked so badly that we cant create a socketManager
  • Method Details

    • init

      private void init(InputStream privData, Logging l)
      Opens the session and wires up the source and sink.
      Parameters:
      privData - the private key data to open with
      l - where to log
    • startRunning

      public void startRunning()
      Starts the tunnel and begins processing datagrams. Classes should override to start UDP side as well.
    • setReadTimeout

      public void setReadTimeout(long ms)
      Sets the read idle timeout for newly-created connections (in milliseconds). After this time expires without data being received from the I2P network, the connection itself will be closed.
      Parameters:
      ms - the timeout in milliseconds, or -1 for no timeout
    • getReadTimeout

      public long getReadTimeout()
      Read idle timeout for newly-created connections (in milliseconds).
      Returns:
      the read timeout used for connections, or -1 for no timeout
    • 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.
      Specified by:
      send in interface Sink
      Parameters:
      to - the destination to send to
      fromPort - I2CP source port, 0-65535
      toPort - I2CP destination port, 0-65535
      data - the data to send
      Throws:
      RuntimeException - if the session is closed