net.i2p.i2ptunnel.ui

## Class GeneralHelper

- java.lang.Object
- - net.i2p.i2ptunnel.ui.GeneralHelper

-     public class GeneralHelper
      extends Object

  General helper functions used by all UIs. This class is also used by Android. Maintain as a stable API and take care not to break Android.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected TunnelControllerGroup` | `_group`
    `static int` | `NOT_RUNNING`
    `protected static String` | `PROP_ENABLE_ACCESS_LIST`
    `protected static String` | `PROP_ENABLE_BLACKLIST`
    `static int` | `RUNNING`
    `static int` | `STANDBY`
    `static int` | `STARTING`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `GeneralHelper(I2PAppContext context, TunnelControllerGroup tcg)`
    `GeneralHelper(TunnelControllerGroup tcg)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected static String` | `_t(String key, I2PAppContext context)`
    `static List<String>` | `deleteTunnel(I2PAppContext context, TunnelControllerGroup tcg, int tunnel, String privKeyFile)` Stop the tunnel, delete from config, rename the private key file if in the default directory
    `List<String>` | `deleteTunnel(int tunnel, String privKeyFile)`
    `String` | `getAccessList(int tunnel)`
    `int` | `getAccessMode(int tunnel)`
    `boolean` | `getAllowAccept(int tunnel)`
    `boolean` | `getAllowInternalSSL(int tunnel)` As of 0.9.35, default true, and overridden to true unless PROP_SSL_SET is set
    `boolean` | `getAllowReferer(int tunnel)`
    `boolean` | `getAllowUserAgent(int tunnel)`
    `Destination` | `getAltDestination(int tunnel)` Works even if tunnel is not running.
    `String` | `getAltPrivateKeyFile(int tunnel)`
    `String` | `getAltPrivateKeyFile(TunnelControllerGroup tcg, int tunnel)`
    `String` | `getBlindedPassword(int tunnel)`
    `int` | `getCert(int tunnel)`
    `List<String>` | `getClientAuths(int tunnel, boolean isDH)` List of b64 name : b64key Pubkeys for DH, privkeys for PSK
    `String` | `getClientDestination(int tunnel)`
    `String` | `getClientInterface(int tunnel)`
    `int` | `getClientPort(int tunnel)`
    `boolean` | `getCloseOnIdle(int tunnel, boolean def)`
    `int` | `getCloseTime(int tunnel, int def)`
    `TunnelController` | `getController(int tunnel)`
    `static TunnelController` | `getController(TunnelControllerGroup tcg, int tunnel)`
    `String` | `getCustomOptionsString(int tunnel)`
    `boolean` | `getDCC(int tunnel)`
    `boolean` | `getDelayOpen(int tunnel)`
    `Destination` | `getDestination(int tunnel)` Works even if tunnel is not running.
    `int` | `getEffort(int tunnel)`
    `boolean` | `getEncrypt(int tunnel)`
    `String` | `getEncryptKey(int tunnel)`
    `int` | `getEncryptMode(int tunnel)`
    `String` | `getFilterDefinition(int tunnel)`
    `String` | `getInboundRandomKey(int tunnel)` Random keys
    `String` | `getJumpList(int tunnel)`
    `String` | `getLeaseSetPrivateKey(int tunnel)`
    `String` | `getLeaseSetSigningPrivateKey(int tunnel)`
    `int` | `getLimitDay(int tunnel)`
    `int` | `getLimitHour(int tunnel)`
    `int` | `getLimitMinute(int tunnel)` all of these are @since 0.8.3
    `int` | `getMaxStreams(int tunnel)`
    `boolean` | `getMultihome(int tunnel)`
    `boolean` | `getNewDest(int tunnel)`
    `String` | `getOutboundRandomKey(int tunnel)`
    `boolean` | `getOutproxyAuth(int tunnel)`
    `String` | `getOutproxyPassword(int tunnel)`
    `String` | `getOutproxyType(int tunnel)`
    `String` | `getOutproxyUsername(int tunnel)`
    `boolean` | `getPersistentClientKey(int tunnel)`
    `int` | `getPostBanTime(int tunnel)`
    `int` | `getPostCheckTime(int tunnel)`
    `int` | `getPostMax(int tunnel)` POST limits
    `int` | `getPostTotalBanTime(int tunnel)`
    `int` | `getPostTotalMax(int tunnel)`
    `String` | `getPrivateKeyFile(int tunnel)`
    `String` | `getPrivateKeyFile(TunnelControllerGroup tcg, int tunnel)`
    `String` | `getProxyAuth(int tunnel)`
    `int` | `getReduceCount(int tunnel, int def)`
    `boolean` | `getReduceOnIdle(int tunnel, boolean def)`
    `int` | `getReduceTime(int tunnel, int def)`
    `boolean` | `getRejectInproxy(int tunnel)`
    `boolean` | `getRejectReferer(int tunnel)`
    `boolean` | `getRejectUserAgents(int tunnel)`
    `int` | `getRemainingStartupDelay(int tunnel)` Get the remaining startup delay time for tunnels with delayed startup.
    `String` | `getSigner(int tunnel)`
    `int` | `getSigType(int tunnel, String newTunnelType)`
    `String` | `getSpoofedHost(int tunnel)`
    `String` | `getSslProxies(int tunnel)`
    `String` | `getTargetHost(int tunnel)`
    `int` | `getTargetPort(int tunnel)`
    `int` | `getTotalDay(int tunnel)`
    `int` | `getTotalHour(int tunnel)`
    `int` | `getTotalMinute(int tunnel)`
    `int` | `getTunnelBackupQuantity(int tunnel, int defaultBackupQuantity)` Inbound or both in/out
    `int` | `getTunnelBackupQuantityOut(int tunnel, int defaultBackupQuantity)`
    `int` | `getTunnelDepth(int tunnel, int defaultLength)` Inbound or both in/out
    `int` | `getTunnelDepthOut(int tunnel, int defaultLength)`
    `String` | `getTunnelDescription(int tunnel)`
    `String` | `getTunnelName(int tunnel)`
    `static String` | `getTunnelName(TunnelControllerGroup tcg, int tunnel)`
    `int` | `getTunnelQuantity(int tunnel, int defaultQuantity)` Inbound or both in/out
    `int` | `getTunnelQuantityOut(int tunnel, int defaultQuantity)`
    `int` | `getTunnelStatus(int tunnel)`
    `String` | `getTunnelType(int tunnel)`
    `int` | `getTunnelVariance(int tunnel, int defaultVariance)` Inbound or both in/out
    `int` | `getTunnelVarianceOut(int tunnel, int defaultVariance)`
    `boolean` | `getUniqueLocal(int tunnel)`
    `boolean` | `getUseOutproxyPlugin(int tunnel)` Default true
    `String` | `getUserAgents(int tunnel)`
    `boolean` | `hasEncType(int tunnel, int encType)`
    `boolean` | `isInteractive(int tunnel)`
    `boolean` | `isOfflineKeys(int tunnel)` Works even if tunnel is not running.
    `boolean` | `isSharedClient(int tunnel)`
    `boolean` | `isSSLEnabled(int tunnel)`
    `protected static List<String>` | `saveConfig(I2PAppContext context, TunnelControllerGroup tcg, int tunnel)` Save the configuration for an existing tunnel to disk.
    `static List<String>` | `saveTunnel(I2PAppContext context, TunnelControllerGroup tcg, int tunnel, TunnelConfig config)` Save the configuration for a new or existing tunnel to disk.
    `List<String>` | `saveTunnel(int tunnel, TunnelConfig config)` Save the configuration for a new or existing tunnel to disk.
    `boolean` | `shouldDelayConnect(int tunnel)`
    `boolean` | `shouldStartAutomatically(int tunnel)`
    `protected static List<String>` | `updateTunnelConfig(TunnelControllerGroup tcg, int tunnel, TunnelConfig config)` Update the config and if shared, adjust and save the config of other shared clients.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### _group

          protected final TunnelControllerGroup _group

    - #### NOT_RUNNING

          public static final int NOT_RUNNING

      See Also:
        Constant Field Values

    - #### PROP_ENABLE_ACCESS_LIST

          protected static final String PROP_ENABLE_ACCESS_LIST

      See Also:
        Constant Field Values

    - #### PROP_ENABLE_BLACKLIST

          protected static final String PROP_ENABLE_BLACKLIST

      See Also:
        Constant Field Values

    - #### RUNNING

          public static final int RUNNING

      See Also:
        Constant Field Values

    - #### STANDBY

          public static final int STANDBY

      See Also:
        Constant Field Values

    - #### STARTING

          public static final int STARTING

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### GeneralHelper

          public GeneralHelper(I2PAppContext context,
                               TunnelControllerGroup tcg)

      Parameters:
        `tcg` - may be null ???

    - #### GeneralHelper

          public GeneralHelper(TunnelControllerGroup tcg)

      Parameters:
        `tcg` - may be null ???

  - ### Method Detail

    - #### _t

          protected static String _t(String key,
                                     I2PAppContext context)

    - #### deleteTunnel

          public static List<String> deleteTunnel(I2PAppContext context,
                                                  TunnelControllerGroup tcg,
                                                  int tunnel,
                                                  String privKeyFile)

      Stop the tunnel, delete from config, rename the private key file if in the default directory
      Parameters:
        `privKeyFile` - The priv key file name from the tunnel edit form. Can be null if not known.

    - #### deleteTunnel

          public List<String> deleteTunnel(int tunnel,
                                           String privKeyFile)

    - #### getAccessList

          public String getAccessList(int tunnel)

    - #### getAccessMode

          public int getAccessMode(int tunnel)

    - #### getAllowAccept

          public boolean getAllowAccept(int tunnel)

    - #### getAllowInternalSSL

          public boolean getAllowInternalSSL(int tunnel)

      As of 0.9.35, default true, and overridden to true unless PROP_SSL_SET is set

    - #### getAllowReferer

          public boolean getAllowReferer(int tunnel)

    - #### getAllowUserAgent

          public boolean getAllowUserAgent(int tunnel)

    - #### getAltDestination

          public Destination getAltDestination(int tunnel)

      Works even if tunnel is not running.
      Returns:
        Destination or null

    - #### getAltPrivateKeyFile

          public String getAltPrivateKeyFile(int tunnel)

      Returns:
        path or ""

    - #### getAltPrivateKeyFile

          public String getAltPrivateKeyFile(TunnelControllerGroup tcg,
                                             int tunnel)

      Returns:
        path or ""

    - #### getBlindedPassword

          public String getBlindedPassword(int tunnel)

    - #### getCert

          public int getCert(int tunnel)

    - #### getClientAuths

          public List<String> getClientAuths(int tunnel,
                                             boolean isDH)

      List of b64 name : b64key Pubkeys for DH, privkeys for PSK
      Parameters:
        `isDH` - true for DH, false for PSK
      Returns:
        non-null

    - #### getClientDestination

          public String getClientDestination(int tunnel)

    - #### getClientInterface

          public String getClientInterface(int tunnel)

    - #### getClientPort

          public int getClientPort(int tunnel)

    - #### getCloseOnIdle

          public boolean getCloseOnIdle(int tunnel,
                                        boolean def)

    - #### getCloseTime

          public int getCloseTime(int tunnel,
                                  int def)

    - #### getController

          public TunnelController getController(int tunnel)

    - #### getController

          public static TunnelController getController(TunnelControllerGroup tcg,
                                                       int tunnel)

      Parameters:
        `tcg` - may be null
      Returns:
        null if not found or tcg is null

    - #### getCustomOptionsString

          public String getCustomOptionsString(int tunnel)

    - #### getDCC

          public boolean getDCC(int tunnel)

    - #### getDelayOpen

          public boolean getDelayOpen(int tunnel)

    - #### getDestination

          public Destination getDestination(int tunnel)

      Works even if tunnel is not running.
      Returns:
        Destination or null

    - #### getEffort

          public int getEffort(int tunnel)

    - #### getEncrypt

          public boolean getEncrypt(int tunnel)

    - #### getEncryptKey

          public String getEncryptKey(int tunnel)

    - #### getEncryptMode

          public int getEncryptMode(int tunnel)

    - #### getFilterDefinition

          public String getFilterDefinition(int tunnel)

    - #### getInboundRandomKey

          public String getInboundRandomKey(int tunnel)

      Random keys

    - #### getJumpList

          public String getJumpList(int tunnel)

    - #### getLeaseSetPrivateKey

          public String getLeaseSetPrivateKey(int tunnel)

    - #### getLeaseSetSigningPrivateKey

          public String getLeaseSetSigningPrivateKey(int tunnel)

    - #### getLimitDay

          public int getLimitDay(int tunnel)

    - #### getLimitHour

          public int getLimitHour(int tunnel)

    - #### getLimitMinute

          public int getLimitMinute(int tunnel)

      all of these are @since 0.8.3

    - #### getMaxStreams

          public int getMaxStreams(int tunnel)

    - #### getMultihome

          public boolean getMultihome(int tunnel)

    - #### getNewDest

          public boolean getNewDest(int tunnel)

    - #### getOutboundRandomKey

          public String getOutboundRandomKey(int tunnel)

    - #### getOutproxyAuth

          public boolean getOutproxyAuth(int tunnel)

    - #### getOutproxyPassword

          public String getOutproxyPassword(int tunnel)

    - #### getOutproxyType

          public String getOutproxyType(int tunnel)

      Returns:
        "connect" or "socks", default depends on tunnel type

    - #### getOutproxyUsername

          public String getOutproxyUsername(int tunnel)

    - #### getPersistentClientKey

          public boolean getPersistentClientKey(int tunnel)

    - #### getPostBanTime

          public int getPostBanTime(int tunnel)

    - #### getPostCheckTime

          public int getPostCheckTime(int tunnel)

    - #### getPostMax

          public int getPostMax(int tunnel)

      POST limits

    - #### getPostTotalBanTime

          public int getPostTotalBanTime(int tunnel)

    - #### getPostTotalMax

          public int getPostTotalMax(int tunnel)

    - #### getPrivateKeyFile

          public String getPrivateKeyFile(int tunnel)

      Returns:
        path, non-null, non-empty

    - #### getPrivateKeyFile

          public String getPrivateKeyFile(TunnelControllerGroup tcg,
                                          int tunnel)

      Returns:
        path, non-null, non-empty

    - #### getProxyAuth

          public String getProxyAuth(int tunnel)

    - #### getReduceCount

          public int getReduceCount(int tunnel,
                                    int def)

    - #### getReduceOnIdle

          public boolean getReduceOnIdle(int tunnel,
                                         boolean def)

    - #### getReduceTime

          public int getReduceTime(int tunnel,
                                   int def)

      Parameters:
        `tunnel` -
        `def` - in minutes
      Returns:
        time in minutes

    - #### getRejectInproxy

          public boolean getRejectInproxy(int tunnel)

    - #### getRejectReferer

          public boolean getRejectReferer(int tunnel)

    - #### getRejectUserAgents

          public boolean getRejectUserAgents(int tunnel)

    - #### getRemainingStartupDelay

          public int getRemainingStartupDelay(int tunnel)

      Get the remaining startup delay time for tunnels with delayed startup.
      Parameters:
        `tunnel` - the tunnel index
      Returns:
        remaining delay in seconds, or 0 if not applicable

    - #### getSigner

          public String getSigner(int tunnel)

    - #### getSigType

          public int getSigType(int tunnel,
                                String newTunnelType)

      Parameters:
        `newTunnelType` - used if tunnel < 0
      Returns:
        the current type if we have a destination already, else the default for that type of tunnel

    - #### getSpoofedHost

          public String getSpoofedHost(int tunnel)

    - #### getSslProxies

          public String getSslProxies(int tunnel)

    - #### getTargetHost

          public String getTargetHost(int tunnel)

    - #### getTargetPort

          public int getTargetPort(int tunnel)

      Parameters:
        `tunnel` -
      Returns:
        -1 if unset or invalid

    - #### getTotalDay

          public int getTotalDay(int tunnel)

    - #### getTotalHour

          public int getTotalHour(int tunnel)

    - #### getTotalMinute

          public int getTotalMinute(int tunnel)

    - #### getTunnelBackupQuantity

          public int getTunnelBackupQuantity(int tunnel,
                                             int defaultBackupQuantity)

      Inbound or both in/out

    - #### getTunnelBackupQuantityOut

          public int getTunnelBackupQuantityOut(int tunnel,
                                                int defaultBackupQuantity)

    - #### getTunnelDepth

          public int getTunnelDepth(int tunnel,
                                    int defaultLength)

      Inbound or both in/out

    - #### getTunnelDepthOut

          public int getTunnelDepthOut(int tunnel,
                                       int defaultLength)

    - #### getTunnelDescription

          public String getTunnelDescription(int tunnel)

    - #### getTunnelName

          public String getTunnelName(int tunnel)

      Returns:
        null if unset

    - #### getTunnelName

          public static String getTunnelName(TunnelControllerGroup tcg,
                                             int tunnel)

      Returns:
        null if unset

    - #### getTunnelQuantity

          public int getTunnelQuantity(int tunnel,
                                       int defaultQuantity)

      Inbound or both in/out

    - #### getTunnelQuantityOut

          public int getTunnelQuantityOut(int tunnel,
                                          int defaultQuantity)

    - #### getTunnelStatus

          public int getTunnelStatus(int tunnel)

    - #### getTunnelType

          public String getTunnelType(int tunnel)

    - #### getTunnelVariance

          public int getTunnelVariance(int tunnel,
                                       int defaultVariance)

      Inbound or both in/out

    - #### getTunnelVarianceOut

          public int getTunnelVarianceOut(int tunnel,
                                          int defaultVariance)

    - #### getUniqueLocal

          public boolean getUniqueLocal(int tunnel)

    - #### getUseOutproxyPlugin

          public boolean getUseOutproxyPlugin(int tunnel)

      Default true

    - #### getUserAgents

          public String getUserAgents(int tunnel)

    - #### hasEncType

          public boolean hasEncType(int tunnel,
                                    int encType)

      Parameters:
        `encType` - code

    - #### isInteractive

          public boolean isInteractive(int tunnel)

    - #### isOfflineKeys

          public boolean isOfflineKeys(int tunnel)

      Works even if tunnel is not running.
      Returns:
        true if offline keys

    - #### isSharedClient

          public boolean isSharedClient(int tunnel)

    - #### isSSLEnabled

          public boolean isSSLEnabled(int tunnel)

    - #### saveConfig

          protected static List<String> saveConfig(I2PAppContext context,
                                                   TunnelControllerGroup tcg,
                                                   int tunnel)

      Save the configuration for an existing tunnel to disk. New tunnels must use saveConfig(..., TunnelController).
      Parameters:
        `context` - unused, taken from tcg
        `tunnel` - must already exist

    - #### saveTunnel

          public static List<String> saveTunnel(I2PAppContext context,
                                                TunnelControllerGroup tcg,
                                                int tunnel,
                                                TunnelConfig config)

      Save the configuration for a new or existing tunnel to disk. For new tunnels, adds to controller and (if configured) starts it.
      Parameters:
        `context` - unused, taken from tcg

    - #### saveTunnel

          public List<String> saveTunnel(int tunnel,
                                         TunnelConfig config)

      Save the configuration for a new or existing tunnel to disk. For new tunnels, adds to controller and (if configured) starts it.

    - #### shouldDelayConnect

          public boolean shouldDelayConnect(int tunnel)

    - #### shouldStartAutomatically

          public boolean shouldStartAutomatically(int tunnel)

    - #### updateTunnelConfig

          protected static List<String> updateTunnelConfig(TunnelControllerGroup tcg,
                                                           int tunnel,
                                                           TunnelConfig config)

      Update the config and if shared, adjust and save the config of other shared clients. If a new tunnel, this will call tcg.addController(), and start it if so configured. This does NOT save this tunnel's config. Caller must call saveConfig() also.