java.lang.Object
net.i2p.i2pcontrol.SocketController
All Implemented Interfaces:
ClientApp, RouterApp

public class SocketControllerextends Object implements RouterApp
This handles the starting and stopping of a ServerSocket from a single static class so it can be called via clients.config. This class is NOT used for the webapp or the HTTP/HTTPS implementation.
  • Field Details

    • _context

      private final RouterContext _context
      The router context, never null.
    • _mgr

      private final ClientAppManager _mgr
      The manager that starts the app.
    • _log

      private final Log _log
      Logger for the control socket.
    • _pluginDir

      private final String _pluginDir
      Directory of the installed plugins.
    • _conf

      private final ConfigurationManager _conf
      The configuration manager used.
    • _ksp

      private final KeyStoreProvider _ksp
      The key store provider used.
    • _secMan

      private final SecurityManager _secMan
      The security manager used.
    • _server

      private ServerSocket _server
      The listening socket, while running.
    • _listeners

      private final List<Socket> _listeners
      The sockets of the connected clients.
    • _state

      private ClientAppState _state
      Current state of the app.
    • PROP_ALLOWED_HOSTS

      static final String PROP_ALLOWED_HOSTS
      Allowed hosts config property
      See Also:
    • SVC_SKT_I2PCONTROL

      private static final String SVC_SKT_I2PCONTROL
      Service name of the control port.
      See Also:
    • DEFAULT_PORT

      private static final int DEFAULT_PORT
      Default control socket port.
      See Also:
  • Constructor Details

    • SocketController

      public SocketController(RouterContext ctx, ClientAppManager mgr) throws IOException
      RouterApp (new way)
      Parameters:
      ctx - the router context supplying the log manager and config directory
      mgr - the client app manager notified of state changes, or null when run outside the client app framework
      Throws:
      IOException - declared by the client app instantiation contract, though this constructor body performs no failing I/O
  • Method Details

    • startup

      public void startup()
      Start the socket server
      Specified by:
      startup in interface ClientApp
    • shutdown

      public void shutdown(String[] args)
      Stop the socket server
      Specified by:
      shutdown in interface ClientApp
      Parameters:
      args - generally null but could be stopArgs from clients.config
    • getState

      public ClientAppState getState()
      Current state of the managed client app.
      Specified by:
      getState in interface ClientApp
      Returns:
      the state of the app
    • getName

      public String getName()
      Unique name of the client app.
      Specified by:
      getName in interface ClientApp
      Returns:
      "I2PControl-Socket"
    • getDisplayName

      public String getDisplayName()
      Display name of the client app.
      Specified by:
      getDisplayName in interface ClientApp
      Returns:
      "I2PControl-Socket"
    • changeState

      private void changeState(ClientAppState state)
      Changes the app state with no result or error.
      Parameters:
      state - the new state of the client app
    • changeState

      private void changeState(ClientAppState state, String msg, Exception e)
      Changes the app state and notifies listeners.
      Parameters:
      state - the new state
      msg - the message for the listeners
      e - the exception, null if none
    • start

      private void start() throws Exception
      Opens the control socket and accepts clients.
      Throws:
      Exception - if the socket cannot be opened
    • buildServer

      public ServerSocket buildServer() throws IOException
      Builds a new server. Used for changing ports during operation and such. Does NOT start the server. Must call start() on the returned server.
      Returns:
      Server - A new server built from current configuration.
      Throws:
      IOException - if the configured listen address cannot be resolved, the configured port is already bound, or the configuration file cannot be written back
    • stopServer

      private void stopServer()
      Stop it
    • stop

      private void stop()
      Closes the control socket and the clients.