Class TorController

java.lang.Object
org.eblocker.server.common.network.TorController

public class TorController extends Object
This class is opening a Telnet connection to the Tor Control-Port, which should be activated in the 'torrc'-config file by including:

ControlPort 9051 CookieAuthentication 0

See https://gitweb.torproject.org/torspec.git/tree/control-spec.txt for the usage of the control port. It can be used to control and query information of the running Tor instance.

NOTE: To be able to specifiy certain exit nodes for tor to use we need the TOR-GEOIPDB debian package!!! For the BananaPi M2 it can be found in this repository (mirror) : deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi

  • Field Details

  • Constructor Details

  • Method Details

    • init

      public void init()
    • startCheckingConnection

      public void startCheckingConnection(ScheduledExecutorService executor, long milliseconds)
      Start checking the Tor connection with a delay in between the checks. This will provide the buffer with the connection state (torNetworkConnection) for other objects It automatically handles tries to reconnect to the Tor Control port, if the connection is not established (anymore).
      Parameters:
      milliseconds - delay in milliseconds between checks
    • isConnectedToTorNetwork

      public boolean isConnectedToTorNetwork()
      Use this method to get the latest connection state of the Tor client.
      Returns:
    • getCountryList

      public Set<ExitNodeCountry> getCountryList()
      Get a set of all exit nodes countries
      Returns:
    • setAllowedExitNodesCountries

      public void setAllowedExitNodesCountries(Set<String> selectedCountries)
      Reconfigures the Tor instance to use only exit nodes in the given set of countries
      Parameters:
      selectedCountries - Set of country names that should be used as exit nodes
    • getCurrentExitNodeCountries

      public Set<String> getCurrentExitNodeCountries()
      Return the current defined countries that the Tor instance should choose exit nodes in
      Returns:
    • getNewIdentity

      public boolean getNewIdentity()
      This tells Tor to create a new circuit, and therefore we will also get another IP-address (exit node)
    • closeTorTelnetConnection

      public void closeTorTelnetConnection()
      Close the telnet connection properly.
    • addDeviceUsingTor

      public void addDeviceUsingTor(Device device)
    • removeDeviceNotUsingTor

      public void removeDeviceNotUsingTor(Device device)