All Implemented Interfaces:
EventDispatcher
Direct Known Subclasses:
I2PTunnelClientBase, I2PTunnelServer, I2PTunnelUDPClientBase, I2PTunnelUDPServerBase

public abstract class I2PTunnelTaskextends EventDispatcherImpl
Base class for I2P tunnel servers and clients.

Use caution when extending externally. Should be maintained as stable API, but confirm before use. No startRunning() method; all extending classes implement one.

  • Field Details

    • open

      protected volatile boolean open
      True while the tunnel is running and accepting connections.
    • tunnel

      public I2PTunnel tunnel
      The I2PTunnel this task runs inside.
  • Constructor Details

    • I2PTunnelTask

      protected I2PTunnelTask(String name, EventDispatcher notifyThis, I2PTunnel tunnel)
      Create a task bound to a tunnel.
      Parameters:
      name - display name for this task, used in logs and console output
      notifyThis - dispatcher to which this task sends its events
      tunnel - the I2PTunnel this task runs inside
  • Method Details

    • setTunnel

      public void setTunnel(I2PTunnel pTunnel)
      Rebind this task to a different tunnel.
      Parameters:
      pTunnel - the tunnel to run inside, for apps using several instances
    • getTunnel

      public I2PTunnel getTunnel()
      The I2PTunnel this task runs inside.
      Returns:
      the tunnel this task runs inside, as set by the constructor or setTunnel(I2PTunnel)
    • getId

      public int getId()
      The id of the client list entry for this task.
      Returns:
      the client list entry id, -1 until setId(int) is called
    • isOpen

      public boolean isOpen()
      Whether the tunnel is running and accepting connections.
      Returns:
      true if the tunnel is running and accepting connections
    • setId

      public void setId(int id)
      Record the client list entry id for this task.
      Parameters:
      id - the client list entry id to record for this task
    • setName

      protected void setName(String name)
      Record the display name for this task.
      Parameters:
      name - display name to record for this task
    • routerDisconnected

      protected void routerDisconnected()
      Tell the tunnel that the router connection has dropped.
    • close

      public abstract boolean close(boolean forced)
      Note that the tunnel can be reopened after this by calling startRunning(). This may 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().

      Parameters:
      forced - true to interrupt an in-progress build, false to close gracefully
      Returns:
      true if the tunnel was closed and can be reopened by startRunning()
    • destroy

      public boolean destroy()
      Note that the tunnel cannot be reopened after this by calling startRunning(), as it may destroy the underlying socket manager, depending on implementation. This should release all resources.

      The implementation here simply calls close(true). Extending classes should override to release all resources.

      Returns:
      true if every resource was released
    • optionsUpdated

      public void optionsUpdated(I2PTunnel tunnel)
      Notify the task that I2PTunnel's options have been updated. Extending classes should override and call I2PTunnel.getClientOptions(), then update the I2PSocketManager. Does nothing here.
      Parameters:
      tunnel - the tunnel whose client options were updated
    • connected

      public void connected(I2PSession session)
      For tasks that don't call I2PTunnel.addSession(I2PSession) directly.
      Parameters:
      session - the newly connected session to register with the tunnel
    • disconnected

      public void disconnected(I2PSession session)
      Called when a session is disconnected.

      This method removes the session from the tunnel and notifies the router that disconnection occurred.

      Parameters:
      session - the session that dropped, removed from the tunnel here
    • getBooleanOption

      protected boolean getBooleanOption(String opt, boolean dflt)
      Read a boolean client option from the tunnel's properties.
      Parameters:
      opt - the property name to read
      dflt - the value to return when the property is not set
      Returns:
      the boolean option
    • errorOccurred

      public void errorOccurred(I2PSession session, String message, Throwable error)
      Does nothing here. Extending classes may override.
      Parameters:
      session - the session that reported the error
      message - a human-readable description of the error
      error - the error that was thrown, or null if none was reported
    • reportAbuse

      public void reportAbuse(I2PSession session, int severity)
      Does nothing here. Extending classes may override.
      Parameters:
      session - the session reported for abusive behaviour
      severity - the abuse severity, from the I2PClient status codes
    • getSocketManager

      public I2PSocketManager getSocketManager()
      Returns the I2PSocketManager for this task, or null if not applicable. Extending classes may override to return their socket manager.
      Returns:
      the socket manager
    • toString

      public String toString()
      The display name given to this task when it was constructed.
      Overrides:
      toString in class Object
      Returns:
      the task name