TorProcess (SelekTOR Java Documentation)
Date: 2017-04-14

client

## Class TorProcess

- java.lang.Object
- - lib.ClientProcess
  - - client.TorProcess

- Direct Known Subclasses:
    TorController

      public class TorProcess
      extends ClientProcess

  Author:
    Alistair Neil

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `EMPTYSTRING`
    `static int` | `LOG_DEBUG`
    `static int` | `LOG_INFO`
    `static int` | `LOG_NOTICE`
    `static int` | `TOR_BOOT_ERROR`
    `static int` | `TOR_BOOT_FATAL`
    `static int` | `TOR_BOOT_TIMEOUT`
    `static int` | `TOR_BOOTED`
    `static int` | `TOR_BRIDGE`
    `static int` | `TOR_CLOCK_ERROR`
    `static int` | `TOR_DIRINFO_STALE`
    `static int` | `TOR_MESSAGE`
    `static int` | `TOR_NEWCIRC`
    `static int` | `TOR_NOEXITS`
    `static int` | `TOR_NOHOP0`
    `static int` | `TOR_NONET_ACTIVITY`
    `static int` | `TOR_NOROUTE`
    `static int` | `TOR_RESTARTED`
    `static int` | `TOR_STOPPED`

    - ### Fields inherited from class lib.ClientProcess

      `CLIENT_RUNNING, CLIENT_STOPPED, CLIENT_TIMEDOUT`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TorProcess(java.lang.String clientpath, java.lang.String configfolder)` Constructor

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clearCLIOption(java.lang.String option)` Remove previously add tor option
    `void` | `clearStdout()` Clear the Stdout text area
    `void` | `clearTorrcOption(java.lang.String option)` Remove previously add torrc option
    `void` | `clientProcessEventFired(java.lang.String data)` Client event handler, can be overriden by parent class
    `void` | `createDataFolder()` Creates a data folder for the Tor client to put its cache data
    `void` | `createDefaultConfig()` Creates the default Tor config file
    `void` | `deleteCacheData()` Delete Tor cache data
    `void` | `deleteConfigFile()` Delete the configuration file
    `java.lang.String` | `getBridges()` Get bridges
    `float` | `getCacheAge()` Get the age of the file cache in minutes
    `java.lang.String` | `getCachedDataFolder()` Get the currently set cached data folder
    `java.lang.String` | `getClientLocation()` Get Tor client location as a filepath
    `boolean` | `getCLIOptionBool(java.lang.String option)` Get a previously added tor option boolean value
    `java.lang.String` | `getCLIOptions(java.lang.String option)` Get a previously added tor option string
    `java.lang.String` | `getCLIOptionsAsString()` Gets all the currently set tor options as single String for use as arguments passed to tor client
    `java.lang.String` | `getConfigFilePath()` Get the path to the configuration file
    `int` | `getControlPort()` Get the control port
    `java.lang.String` | `getDataFolder()` Get the datafolder being used by tor client
    `java.lang.String` | `getEventMessage(int event)` Get textual representation on an event
    `int` | `getListenPort()` Get the listening port
    `java.lang.String` | `getOwnershipID()` Return the currently set process ownership ID
    `java.lang.String` | `getSecret()` Get the currently set authentification secret
    `java.lang.String` | `getTorrcOption(java.lang.String option)` Get a previously added tor option string
    `java.lang.String` | `getTorrcOptionsAsString()` Gets all the currently set torrc options as single String
    `float` | `getVersion()` Get Tor version as float
    `void` | `setBoolTorOption(java.lang.String option, boolean value)` Add a tor option boolean value
    `void` | `setBridges(java.lang.String bridges)` Set Tor bridges, supports multiple addresses
    `void` | `setCachedDataFolder(int port)` This populates the the current folder whose name is derived from the listening port with data from the given source folder derived by the given port number.
    `void` | `setCLIOption(java.lang.String option, java.lang.String value)` Add a tor option string which is passed to the tor client on startup.
    `void` | `setControlPassword(java.lang.String secret, java.lang.String hashpass)`
    `void` | `setExternalArgs(java.lang.String torargs)` Set external user provided startup arguments
    `void` | `setGeoIP4(java.lang.String filepath)` Set the path to the geoip file
    `void` | `setGeoIP6(java.lang.String filepath)` Set the path to the geoip file
    `void` | `setInitialBootEvent(int event)` Set the event that is issued on process boot completion
    `void` | `setListenPort(int port)` Set the listening port
    `void` | `setLogLevel(int lev)` Set the Tor stdout log level
    `void` | `setMaxHistory(int lines)` Set the maximum no of lines to display in the Stdout output
    `void` | `setOwnershipID(java.lang.String processid)` Set Ownership process id, useful for proper process termination in event of a crash
    `void` | `setSilentBootEnabled(boolean enabled)` Enable/Disable bootstrap message events on startup
    `void` | `setStdoutTextArea(javax.swing.JTextArea jta)` Set the text area that will receive Stdout output
    `void` | `setTorrcOption(java.lang.String option, java.lang.String value)` Add a torrc option string See Tor documentation for valid options.
    `void` | `startProcess()` Starts Tor process, and issues booted event on completion
    `void` | `torProcessEventFired(int event, java.lang.String data)` Called if an event was fired, will be overidden by sub class
    `boolean` | `validateBridges(java.lang.String bridges)` Validate bridge addresses
    `boolean` | `validateHostPort(java.lang.String hostport)` Validate a host:port ipv4 address

    - ### Methods inherited from class lib.ClientProcess

      `getClientStatus, getProcess, sendMessage, setStartupDelay, setStartupTimeout, start, stopProcess`

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

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

- - ### Field Detail

    - #### LOG_DEBUG

          public static final int LOG_DEBUG

      See Also:
        Constant Field Values

    - #### LOG_INFO

          public static final int LOG_INFO

      See Also:
        Constant Field Values

    - #### LOG_NOTICE

          public static final int LOG_NOTICE

      See Also:
        Constant Field Values

    - #### EMPTYSTRING

          public static final java.lang.String EMPTYSTRING

      See Also:
        Constant Field Values

    - #### TOR_MESSAGE

          public static final int TOR_MESSAGE

      See Also:
        Constant Field Values

    - #### TOR_BOOT_TIMEOUT

          public static final int TOR_BOOT_TIMEOUT

      See Also:
        Constant Field Values

    - #### TOR_BOOT_FATAL

          public static final int TOR_BOOT_FATAL

      See Also:
        Constant Field Values

    - #### TOR_BOOT_ERROR

          public static final int TOR_BOOT_ERROR

      See Also:
        Constant Field Values

    - #### TOR_CLOCK_ERROR

          public static final int TOR_CLOCK_ERROR

      See Also:
        Constant Field Values

    - #### TOR_NOROUTE

          public static final int TOR_NOROUTE

      See Also:
        Constant Field Values

    - #### TOR_BOOTED

          public static final int TOR_BOOTED

      See Also:
        Constant Field Values

    - #### TOR_RESTARTED

          public static final int TOR_RESTARTED

      See Also:
        Constant Field Values

    - #### TOR_NOEXITS

          public static final int TOR_NOEXITS

      See Also:
        Constant Field Values

    - #### TOR_STOPPED

          public static final int TOR_STOPPED

      See Also:
        Constant Field Values

    - #### TOR_BRIDGE

          public static final int TOR_BRIDGE

      See Also:
        Constant Field Values

    - #### TOR_NEWCIRC

          public static final int TOR_NEWCIRC

      See Also:
        Constant Field Values

    - #### TOR_DIRINFO_STALE

          public static final int TOR_DIRINFO_STALE

      See Also:
        Constant Field Values

    - #### TOR_NOHOP0

          public static final int TOR_NOHOP0

      See Also:
        Constant Field Values

    - #### TOR_NONET_ACTIVITY

          public static final int TOR_NONET_ACTIVITY

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### TorProcess

          public TorProcess(java.lang.String clientpath,
                            java.lang.String configfolder)

      Constructor
      Parameters:
        `clientpath` - Path to Tor client
        `configfolder` - Filepath to torrc

  - ### Method Detail

    - #### startProcess

          public final void startProcess()

      Starts Tor process, and issues booted event on completion

    - #### setLogLevel

          public final void setLogLevel(int lev)

      Set the Tor stdout log level
      Parameters:
        `lev` -

    - #### setExternalArgs

          public final void setExternalArgs(java.lang.String torargs)

      Set external user provided startup arguments
      Parameters:
        `torargs` -

    - #### setListenPort

          public final void setListenPort(int port)

      Set the listening port
      Parameters:
        `port` -

    - #### setInitialBootEvent

          public final void setInitialBootEvent(int event)

      Set the event that is issued on process boot completion
      Parameters:
        `event` -

    - #### clientProcessEventFired

          public final void clientProcessEventFired(java.lang.String data)

      Client event handler, can be overriden by parent class
      Overrides:
        `clientProcessEventFired` in class `ClientProcess`
      Parameters:
        `data` - line data from standard output of Tor client

    - #### setSilentBootEnabled

          public final void setSilentBootEnabled(boolean enabled)

      Enable/Disable bootstrap message events on startup
      Parameters:
        `enabled` -

    - #### getEventMessage

          public java.lang.String getEventMessage(int event)

      Get textual representation on an event
      Parameters:
        `event` -
      Returns:
        Event as text

    - #### torProcessEventFired

          public void torProcessEventFired(int event,
                                           java.lang.String data)

      Called if an event was fired, will be overidden by sub class
      Parameters:
        `event` -
        `data` -

    - #### setControlPassword

          public final void setControlPassword(java.lang.String secret,
                                               java.lang.String hashpass)

    - #### getSecret

          public final java.lang.String getSecret()

      Get the currently set authentification secret
      Returns:
        String

    - #### setBridges

          public final void setBridges(java.lang.String bridges)

      Set Tor bridges, supports multiple addresses
      Parameters:
        `bridges` -

    - #### validateBridges

          public boolean validateBridges(java.lang.String bridges)

      Validate bridge addresses
      Parameters:
        `bridges` -
      Returns:
        true if valid

    - #### validateHostPort

          public final boolean validateHostPort(java.lang.String hostport)

      Validate a host:port ipv4 address
      Parameters:
        `hostport` -
      Returns:
        true if valid

    - #### getBridges

          public final java.lang.String getBridges()

      Get bridges
      Returns:
        bridges as csv string

    - #### setOwnershipID

          public void setOwnershipID(java.lang.String processid)

      Set Ownership process id, useful for proper process termination in event of a crash
      Parameters:
        `processid` -

    - #### getOwnershipID

          public java.lang.String getOwnershipID()

      Return the currently set process ownership ID
      Returns:
        String process id

    - #### setGeoIP4

          public final void setGeoIP4(java.lang.String filepath)

      Set the path to the geoip file
      Parameters:
        `filepath` - File location

    - #### setGeoIP6

          public final void setGeoIP6(java.lang.String filepath)

      Set the path to the geoip file
      Parameters:
        `filepath` - File location

    - #### getClientLocation

          public final java.lang.String getClientLocation()

      Get Tor client location as a filepath
      Returns:
        filepath as string

    - #### getConfigFilePath

          public final java.lang.String getConfigFilePath()

      Get the path to the configuration file
      Returns:
        String Path to configuration file

    - #### getCLIOptions

          public final java.lang.String getCLIOptions(java.lang.String option)

      Get a previously added tor option string
      Parameters:
        `option` - Tor option key
      Returns:
        String Tor option value

    - #### setCLIOption

          public final void setCLIOption(java.lang.String option,
                                         java.lang.String value)

      Add a tor option string which is passed to the tor client on startup. See Tor documentation for valid options.
      Parameters:
        `option` -
        `value` -

    - #### setBoolTorOption

          public final void setBoolTorOption(java.lang.String option,
                                             boolean value)

      Add a tor option boolean value
      Parameters:
        `option` -
        `value` -

    - #### getTorrcOption

          public final java.lang.String getTorrcOption(java.lang.String option)

      Get a previously added tor option string
      Parameters:
        `option` - Tor option key
      Returns:
        String Tor option value

    - #### setTorrcOption

          public final void setTorrcOption(java.lang.String option,
                                           java.lang.String value)

      Add a torrc option string See Tor documentation for valid options.
      Parameters:
        `option` -
        `value` -

    - #### getTorrcOptionsAsString

          public final java.lang.String getTorrcOptionsAsString()

      Gets all the currently set torrc options as single String
      Returns:
        String Tor client formatted cli arguments

    - #### clearTorrcOption

          public final void clearTorrcOption(java.lang.String option)

      Remove previously add torrc option
      Parameters:
        `option` -

    - #### getCLIOptionBool

          public final boolean getCLIOptionBool(java.lang.String option)

      Get a previously added tor option boolean value
      Parameters:
        `option` - Tor option key
      Returns:
        Boolean value

    - #### clearCLIOption

          public final void clearCLIOption(java.lang.String option)

      Remove previously add tor option
      Parameters:
        `option` -

    - #### getCLIOptionsAsString

          public final java.lang.String getCLIOptionsAsString()

      Gets all the currently set tor options as single String for use as arguments passed to tor client
      Returns:
        String Tor cleint formatted cli arguments

    - #### getListenPort

          public final int getListenPort()

      Get the listening port
      Returns:
        port

    - #### getControlPort

          public final int getControlPort()

      Get the control port
      Returns:
        port

    - #### createDefaultConfig

          public final void createDefaultConfig()

      Creates the default Tor config file

    - #### deleteConfigFile

          public final void deleteConfigFile()

      Delete the configuration file

    - #### createDataFolder

          public final void createDataFolder()

      Creates a data folder for the Tor client to put its cache data

    - #### getDataFolder

          public final java.lang.String getDataFolder()

      Get the datafolder being used by tor client
      Returns:
        Path to datafolder

    - #### getCacheAge

          public float getCacheAge()

      Get the age of the file cache in minutes
      Returns:
        age of cache in minutes

    - #### deleteCacheData

          public final void deleteCacheData()

      Delete Tor cache data

    - #### setCachedDataFolder

          public final void setCachedDataFolder(int port)

      This populates the the current folder whose name is derived from the listening port with data from the given source folder derived by the given port number. This effectively allows each Tor client spawned to have its Tor cache data copied from the first Tor client launched instead of having to go to the net and fetch it and thus start up is a lot faster. I was actually mildly suprised that this actually works.
      Parameters:
        `port` -

    - #### getCachedDataFolder

          public final java.lang.String getCachedDataFolder()

      Get the currently set cached data folder
      Returns:
        path to cached data folder as String

    - #### setStdoutTextArea

          public void setStdoutTextArea(javax.swing.JTextArea jta)

      Set the text area that will receive Stdout output
      Parameters:
        `jta` -

    - #### setMaxHistory

          public void setMaxHistory(int lines)

      Set the maximum no of lines to display in the Stdout output
      Parameters:
        `lines` -

    - #### clearStdout

          public void clearStdout()

      Clear the Stdout text area

    - #### getVersion

          public final float getVersion()

      Get Tor version as float
      Returns:
        Tor version as String