Class I2PTunnelServer

All Implemented Interfaces:
Runnable, EventDispatcher
Direct Known Subclasses:
I2PTunnelDCCServer, I2PTunnelHTTPServer, I2PTunnelIRCServer

public class I2PTunnelServer
extends I2PTunnelTask
implements Runnable
  • Field Details

  • Constructor Details

  • Method Details

    • startRunning

      public void startRunning()
      Start running the I2PTunnelServer. Warning, blocks while connecting to router and building tunnels;
      Throws:
      IllegalArgumentException - if the I2CP configuration is b0rked so badly that we cant create a socketManager
    • setReadTimeout

      public void setReadTimeout​(long ms)
      Set the read idle timeout for newly-created connections (in milliseconds). After this time expires without data being reached from the I2P network, the connection itself will be closed. Less than or equal to 0 means forever. Default -1 (forever) as of 0.9.36 for standard tunnels, but extending classes may override. Prior to that, default was 5 minutes, but did not work due to streaming bugs. Applies only to future connections; calling this does not affect existing connections.
      Parameters:
      ms - in ms
    • getReadTimeout

      public long getReadTimeout()
      Get the read idle timeout for newly-created connections (in milliseconds). Less than or equal to 0 means forever. Default -1 (forever) as of 0.9.36 for standard tunnels, but extending classes may override. Prior to that, default was 5 minutes, but did not work due to streaming bugs.
      Returns:
      The read timeout used for connections
    • close

      public boolean close​(boolean forced)
      Note that the tunnel can be reopened after this by calling startRunning(). This does not release all resources. In particular, the I2PSocketManager remains and it may have timer threads that continue running. To release all resources permanently, call destroy().
      Specified by:
      close in class I2PTunnelTask
      Returns:
      success
    • destroy

      public boolean destroy()
      Note that the tunnel cannot be reopened after this by calling startRunning(), as it will destroy the underlying socket manager. This releases all resources.
      Overrides:
      destroy in class I2PTunnelTask
      Returns:
      success
      Since:
      0.9.17
    • optionsUpdated

      public void optionsUpdated​(I2PTunnel tunnel)
      Update the I2PSocketManager. And since 0.9.15, the target host and port.
      Overrides:
      optionsUpdated in class I2PTunnelTask
      Since:
      0.9.1
    • getHandlerCount

      protected int getHandlerCount()
    • run

      public void run()
      If usePool is set, this starts the executor pool. Then, do the accept() loop, and either hands each I2P socket to the executor or runs it in-line.
      Specified by:
      run in interface Runnable
    • shouldUsePool

      public boolean shouldUsePool()
    • blockingHandle

      protected void blockingHandle​(I2PSocket socket)
      This is run in a thread from a limited-size thread pool via Handler.run(), except for a standard server (this class, no extension, as determined in getUsePool()), it is run directly in the acceptor thread (see run()). In either case, this method and any overrides must spawn a thread and return quickly. If blocking while reading the headers (as in HTTP and IRC), the thread pool may be exhausted. See PROP_USE_POOL, DEFAULT_USE_POOL, PROP_HANDLER_COUNT, DEFAULT_HANDLER_COUNT
    • getSocket

      protected Socket getSocket​(Hash from, int incomingPort) throws IOException
      Get a regular or SSL socket depending on config and the incoming port. To configure a specific host:port as the server for incoming port xx, set option targetForPort.xx=host:port
      Parameters:
      from - may be used to construct local address since 0.9.13
      Throws:
      IOException
      Since:
      0.9.9
    • getSocket

      protected Socket getSocket​(Hash from, InetAddress remoteHost, int remotePort) throws IOException
      Get a regular or SSL socket depending on config. The SSL config applies to all hosts/ports.
      Parameters:
      from - may be used to construct local address since 0.9.13
      Throws:
      IOException
      Since:
      0.9.9