Class TunnelControllerGroup

  • All Implemented Interfaces:
    ClientApp

    public class TunnelControllerGroup
    extends Object
    implements ClientApp
    Coordinate a set of tunnels within the JVM, loading and storing their config to disk, and building new ones as requested. This is the entry point from clients.config.
    • Constructor Detail

      • TunnelControllerGroup

        public TunnelControllerGroup​(I2PAppContext context,
                                     ClientAppManager mgr,
                                     String[] args)
        Instantiation only. Caller must call startup(). Config file problems will not throw exception until startup().
        Parameters:
        mgr - may be null
        args - zero or one args, which may be one config file or one config directory. If not absolute will be relative to the context's config dir, if empty or null, the default is i2ptunnel.config for a config file and i2ptunnel.config.d for a config directory
        Throws:
        IllegalArgumentException - if too many args
        Since:
        0.9.4
    • Method Detail

      • getInstance

        public static TunnelControllerGroup getInstance()
        In I2PAppContext will instantiate if necessary and always return non-null. As of 0.9.4, when in RouterContext, will return null if the TCG has not yet been started by the router. As of 0.9.41, that's true for Android as well. In Android, this should be used for all calls except from LoadClientsJob, as we do not want to instantiate TCG too early. Android must do null checks on the return value.
        Throws:
        IllegalArgumentException - if unable to load from i2ptunnel.config
      • getInstance

        public static TunnelControllerGroup getInstance​(I2PAppContext ctx)
        In I2PAppContext will instantiate if necessary and always return non-null. When in RouterContext, will return null (except in Android) if the TCG has not yet been started by the router. In Android, if the old instance uses a stale context, it will replace it. In Android, this should only be called from LoadClientsJob, as we do not want to instantiate TCG too early.
        Throws:
        IllegalArgumentException - if unable to load from i2ptunnel.config
        Since:
        0.9.41
      • main

        public static void main​(String[] args)
        Parameters:
        args - one arg, the config file, if not absolute will be relative to the context's config dir, if no args, the default is i2ptunnel.config
        Throws:
        IllegalArgumentException - if unable to load from config from file
      • getContext

        public I2PAppContext getContext()
        Helper
        Since:
        0.9.49
      • getName

        public String getName()
        ClientApp interface
        Specified by:
        getName in interface ClientApp
        Returns:
        non-null
        Since:
        0.9.4
      • getDisplayName

        public String getDisplayName()
        ClientApp interface
        Specified by:
        getDisplayName in interface ClientApp
        Returns:
        non-null
        Since:
        0.9.4
      • shutdown

        public void shutdown​(String[] args)
        ClientApp interface
        Specified by:
        shutdown in interface ClientApp
        Parameters:
        args - generally null but could be stopArgs from clients.config
        Since:
        0.9.4
      • shutdown

        public void shutdown()
        Warning - destroys the singleton! Caller must root a new context before calling instance() or main() again. Agressively kill and null everything to reduce memory usage in the JVM after stopping, and to recognize what must be reinitialized on restart (Android)
        Since:
        0.8.8
      • loadControllers

        public void loadControllers​(File cfgFile)
        Load up all of the tunnels configured in the given file. Prior to 0.9.20, also started the tunnels. As of 0.9.20, does not start the tunnels, you must call startup() or getInstance() instead of loadControllers(). DEPRECATED for use outside this class. Use startup() or getInstance().
        Throws:
        IllegalArgumentException - if unable to load from file
      • reloadControllers

        public void reloadControllers()
        Stop all tunnels, reload config, and restart those configured to do so. WARNING - Does NOT simply reload the configuration!!! This is probably not what you want. This does not return or clear the controller messages.
        Throws:
        IllegalArgumentException - if unable to reload config file
      • unloadControllers

        public void unloadControllers()
        Stop and remove reference to all known tunnels (but dont delete any config file or do other silly things)
      • addController

        public void addController​(TunnelController controller)
        Add the given tunnel to the set of known controllers (but dont add it to a config file or start it or anything)
      • removeController

        public List<String> removeController​(TunnelController controller)
        Stop and remove the given tunnel. Side effect - clears all messages the controller. Does NOT delete the configuration - must call saveConfig() or removeConfig() also.
        Returns:
        list of messages from the controller as it is stopped
      • stopAllControllers

        public List<String> stopAllControllers()
        Stop all tunnels. May be restarted. Side effect - clears all messages from all controllers.
        Returns:
        list of messages the tunnels generate when stopped
      • startAllControllers

        public List<String> startAllControllers()
        Start all tunnels. Side effect - clears all messages from all controllers.
        Returns:
        list of messages the tunnels generate when started
      • restartAllControllers

        public List<String> restartAllControllers()
        Restart all tunnels. Side effect - clears all messages from all controllers.
        Returns:
        list of messages the tunnels generate when restarted
      • clearAllMessages

        public List<String> clearAllMessages()
        Fetch and clear all outstanding messages from any of the known tunnels.
        Returns:
        list of messages the tunnels have generated
      • saveConfig

        @Deprecated
        public void saveConfig()
                        throws IOException
        Deprecated.
        use saveConfig(TunnelController) or removeConfig(TunnelController)
        Save the configuration of all known tunnels to the default config file
        Throws:
        IOException
      • saveConfig

        public void saveConfig​(TunnelController tc)
                        throws IOException
        Save the configuration of this tunnel only, may be new. Side effect: for split config, sets "confFile" property to absolute path.
        Throws:
        IOException
        Since:
        0.9.42
      • getControllers

        public List<TunnelController> getControllers()
        Retrieve a list of tunnels known. Side effect: if the tunnels have not been loaded from config yet, they will be.
        Returns:
        list of TunnelController objects
        Throws:
        IllegalArgumentException - if unable to load config from file
      • acquire

        void acquire​(TunnelController controller,
                     I2PSession session)
        Note the fact that the controller is using the session so that it isn't destroyed prematurely.
      • release

        void release​(TunnelController controller,
                     I2PSession session)
        Note the fact that the controller is no longer using the session, and if no other controllers are using it, destroy the session.
      • getClientExecutor

        ThreadPoolExecutor getClientExecutor()
        Returns:
        non-null
        Since:
        0.8.8 Moved from I2PTunnelClientBase in 0.9.18