anon.tor
Class Tor

java.lang.Object
  extended by anon.tor.Tor
All Implemented Interfaces:
AnonService, java.lang.Runnable

public class Tor
extends java.lang.Object
implements java.lang.Runnable, AnonService

Author:
stefan

Field Summary
static java.lang.String DEFAULT_DIR_SERVER_ADDR
           
static int DEFAULT_DIR_SERVER_PORT
           
static int DNS_TIME_OUT
           
private  Circuit[] m_activeCircuits
           
private  java.util.Vector m_allowedExitNodeNames
           
private  java.util.Vector m_allowedFirstORNames
           
private  java.util.Vector m_allowedORNames
           
private  boolean m_bCloseCreator
           
private  boolean m_bIsCreatingCircuit
           
private  boolean m_bIsStarted
           
private  java.lang.Thread m_circuitCreator
           
private  java.util.Hashtable m_CircuitForDestination
           
private  int m_circuitLengthMax
           
private  int m_circuitLengthMin
           
private  int m_ConnectionsPerCircuit
           
private  Database m_DNSCache
           
private  FirstOnionRouterConnectionFactory m_firstORFactory
           
private  java.util.Vector[] m_KeysForCircuit
           
private  int m_MaxNrOfActiveCircuits
           
private  java.lang.Object m_oActiveCircuitSync
           
private  ORList m_orList
           
private  java.lang.Object m_oStartStopSync
           
private  IMutableProxyInterface m_proxyInterface
           
private  MyRandom m_rand
           
private  boolean m_useDNSCache
           
static int MAX_ROUTE_LEN
           
static int MIN_ROUTE_LEN
           
private static Tor ms_theTorInstance
           
 
Fields inherited from interface anon.AnonService
ANONLIB_VERSION
 
Constructor Summary
private Tor()
          Constructor initialize variables
 
Method Summary
 void addEventListener(AnonServiceEventListener l)
          Adds an AnonServiceEventListener.
 AnonChannel createChannel(int type)
          creates a channel through the tor network
 AnonChannel createChannel(java.lang.String addr, int port)
          creates a channel through the Tor network
private  Circuit createNewCircuit(java.lang.String addr, int port)
          creates a new random circuit for the given destination
protected  Circuit getCircuitForDestination(java.lang.String addr, int port, java.util.Hashtable exludeCircuits)
          gets a circuit for the given host and port
static Tor getInstance()
          returns an instance of Tor
 IMutableProxyInterface getProxy()
           
 int initialize(AnonServerDescription torDirServer, IServiceContainer a_serviceContainer, TermsAndConditionConfirmation termsConfirmation)
          initializes Tor service
 boolean isConnected()
          Returns true if this Anon Service is connected, e.g.
 void removeEventListener(AnonServiceEventListener l)
          Removes an AnonServiceEventListener.
 void removeEventListeners()
           
 java.lang.String resolveDNS(java.lang.String name)
          resolves a given hostname to an IP
 void run()
          thread creating new circuits
private  void setCircuitLength(int min, int max)
          sets a circuit length
private  void setConnectionsPerRoute(int i)
          sets the total number of allowed different connections per route
private  void setORListServer(boolean bUseInfoService, java.lang.String name, int port)
          sets the server the list of onionrouters is fetched from
 int setProxy(IMutableProxyInterface a_Proxy)
          Sets the settings ofr the proxy, which should be used to establish network connections
 void setUseDNSCache(boolean usecache)
          active/deactivate the DNS cache
 void shutdown(boolean a_bResetTransferredBytes)
          shutdown tor
private  void start(boolean startCircuits)
          starts the Tor service
private  void stop()
          stops the Tor service and closes all connections
private  void updateORList()
          updates the ORList
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_ROUTE_LEN

public static final int MAX_ROUTE_LEN
See Also:
Constant Field Values

MIN_ROUTE_LEN

public static final int MIN_ROUTE_LEN
See Also:
Constant Field Values

DNS_TIME_OUT

public static final int DNS_TIME_OUT
See Also:
Constant Field Values

ms_theTorInstance

private static Tor ms_theTorInstance

m_orList

private ORList m_orList

m_allowedORNames

private java.util.Vector m_allowedORNames

m_allowedFirstORNames

private java.util.Vector m_allowedFirstORNames

m_allowedExitNodeNames

private java.util.Vector m_allowedExitNodeNames

m_activeCircuits

private Circuit[] m_activeCircuits

m_MaxNrOfActiveCircuits

private int m_MaxNrOfActiveCircuits

m_oActiveCircuitSync

private java.lang.Object m_oActiveCircuitSync

m_oStartStopSync

private java.lang.Object m_oStartStopSync

m_firstORFactory

private FirstOnionRouterConnectionFactory m_firstORFactory

m_DNSCache

private Database m_DNSCache

m_CircuitForDestination

private java.util.Hashtable m_CircuitForDestination

m_KeysForCircuit

private java.util.Vector[] m_KeysForCircuit

m_bIsStarted

private volatile boolean m_bIsStarted

m_bIsCreatingCircuit

private boolean m_bIsCreatingCircuit

m_useDNSCache

private boolean m_useDNSCache

m_circuitLengthMin

private int m_circuitLengthMin

m_circuitLengthMax

private int m_circuitLengthMax

m_ConnectionsPerCircuit

private int m_ConnectionsPerCircuit

m_rand

private MyRandom m_rand

DEFAULT_DIR_SERVER_ADDR

public static final java.lang.String DEFAULT_DIR_SERVER_ADDR
See Also:
Constant Field Values

DEFAULT_DIR_SERVER_PORT

public static final int DEFAULT_DIR_SERVER_PORT
See Also:
Constant Field Values

m_circuitCreator

private java.lang.Thread m_circuitCreator

m_bCloseCreator

private volatile boolean m_bCloseCreator

m_proxyInterface

private IMutableProxyInterface m_proxyInterface
Constructor Detail

Tor

private Tor()
Constructor initialize variables

Method Detail

updateORList

private void updateORList()
updates the ORList


getCircuitForDestination

protected Circuit getCircuitForDestination(java.lang.String addr,
                                           int port,
                                           java.util.Hashtable exludeCircuits)
gets a circuit for the given host and port

Parameters:
addr - host address
port - host port
exludeCircuits - Contains circuits, which should not be considered when finding an appropirated circuit for the given destination. Can be NULL or empty
Returns:
a circuit that can connect to the destination

createNewCircuit

private Circuit createNewCircuit(java.lang.String addr,
                                 int port)
creates a new random circuit for the given destination

Parameters:
addr - address
port - port

getInstance

public static Tor getInstance()
returns an instance of Tor

Returns:
an instance of Tor

run

public void run()
thread creating new circuits

Specified by:
run in interface java.lang.Runnable

start

private void start(boolean startCircuits)
            throws java.io.IOException
starts the Tor service

Parameters:
startCircuits - create all circuits at startup
Throws:
java.io.IOException

stop

private void stop()
stops the Tor service and closes all connections


setCircuitLength

private void setCircuitLength(int min,
                              int max)
sets a circuit length

Parameters:
min - minimum circuit length
max - maximum circuit length

setConnectionsPerRoute

private void setConnectionsPerRoute(int i)
sets the total number of allowed different connections per route


setORListServer

private void setORListServer(boolean bUseInfoService,
                             java.lang.String name,
                             int port)
sets the server the list of onionrouters is fetched from

Parameters:
name - address
port - port

setUseDNSCache

public void setUseDNSCache(boolean usecache)
active/deactivate the DNS cache

Parameters:
usecache -

createChannel

public AnonChannel createChannel(int type)
                          throws java.net.ConnectException
creates a channel through the tor network

Specified by:
createChannel in interface AnonService
Parameters:
type - channeltype (only AnonChannel.SOCKS is supported at the moment)
Returns:
a channel
Throws:
java.io.IOException
java.net.ConnectException

createChannel

public AnonChannel createChannel(java.lang.String addr,
                                 int port)
                          throws java.net.ConnectException
creates a channel through the Tor network

Parameters:
addr - address
port - port
Returns:
a channel
Throws:
java.net.ConnectException

initialize

public int initialize(AnonServerDescription torDirServer,
                      IServiceContainer a_serviceContainer,
                      TermsAndConditionConfirmation termsConfirmation)
initializes Tor service

Specified by:
initialize in interface AnonService
Parameters:
torDirServer - AnonServer to use
Returns:
error code

setProxy

public int setProxy(IMutableProxyInterface a_Proxy)
Description copied from interface: AnonService
Sets the settings ofr the proxy, which should be used to establish network connections

Specified by:
setProxy in interface AnonService
Returns:
E_SUCCESS, if ok

getProxy

public IMutableProxyInterface getProxy()

shutdown

public void shutdown(boolean a_bResetTransferredBytes)
shutdown tor

Specified by:
shutdown in interface AnonService

addEventListener

public void addEventListener(AnonServiceEventListener l)
Description copied from interface: AnonService
Adds an AnonServiceEventListener. This listener will receive events like: ... For more information see AnonServiceEventListener.

Specified by:
addEventListener in interface AnonService
Parameters:
l - Listener to add

removeEventListeners

public void removeEventListeners()
Specified by:
removeEventListeners in interface AnonService

removeEventListener

public void removeEventListener(AnonServiceEventListener l)
Description copied from interface: AnonService
Removes an AnonServiceEventListener. This Listener will not receive any Events anymore.

Specified by:
removeEventListener in interface AnonService
Parameters:
l - Listener, which will be removed

resolveDNS

public java.lang.String resolveDNS(java.lang.String name)
resolves a given hostname to an IP

Parameters:
name - hostname
Returns:
IP address

isConnected

public boolean isConnected()
Description copied from interface: AnonService
Returns true if this Anon Service is connected, e.g. initialized and useable

Specified by:
isConnected in interface AnonService