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)
          gets a circuit for the given host and port
 java.util.Vector getFirstOnionRouterList()
          returns a list of all onion routers that are allowed at the moment as first onion routers
static Tor getInstance()
          Returns a Instance of Tor
 java.util.Vector getOnionRouterList()
          returns a list of all onionrouters
 IMutableProxyInterface getProxy()
           
 int initialize(AnonServerDescription torDirServer, IServiceContainer a_serviceContainer)
          Initializes this AnonService.
 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 an IP to a given hostname
 void run()
          creates new circuits
private  void setCircuitLength(int min, int max)
          sets a circuit length
private  void setConnectionsPerRoute(int i)
          Set the total number of allowed different connections per route
 void setExitNodes(java.util.Vector listOfORNames)
          sets a List of allowed exit nodes.
 void setFirstOnionRouterList(java.util.Vector listOfORNames)
          sets a List of allowed Onion Routers that are used as entry point to the Tor Network
 void setOnionRouterList(java.util.Vector listOfORNames)
          sets a List of allowed middle Onion Routers
private  void setORListServer(boolean bUseInfoService, java.lang.String name, int port)
          sets the server where the onionrouterlist is fetched
 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 use of the DNS-Cache
 void shutdown()
          shutdown tor
private  void start(boolean startCircuits)
          starts the Tor-Service
private  void stop()
          stops the Tor-Service and all opened connections
 void testDNS()
          test the DNS-resolve mechanism
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)
gets a circuit for the given host and port

Parameters:
addr - host address
port - host port
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. No internal state is changed.


getInstance

public static Tor getInstance()
Returns a Instance of Tor

Returns:
a Instance of Tor

run

public void run()
creates 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 all opened connections


setOnionRouterList

public void setOnionRouterList(java.util.Vector listOfORNames)
sets a List of allowed middle Onion Routers

Parameters:
ORList - List of the names of allowed Onion Routers if ORList is null, then all OR's are used

setFirstOnionRouterList

public void setFirstOnionRouterList(java.util.Vector listOfORNames)
sets a List of allowed Onion Routers that are used as entry point to the Tor Network

Parameters:
FORList - List of Onion Routers, if null all are allowed

setExitNodes

public void setExitNodes(java.util.Vector listOfORNames)
sets a List of allowed exit nodes. these nodes are exit points of the Tor Network

Parameters:
exitNodes - List of exit nodes

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)
Set the total number of allowed different connections per route


setORListServer

private void setORListServer(boolean bUseInfoService,
                             java.lang.String name,
                             int port)
sets the server where the onionrouterlist is fetched

Parameters:
name - address
port - port

setUseDNSCache

public void setUseDNSCache(boolean usecache)
active/deactivate the use of the DNS-Cache

Parameters:
usecache -

getOnionRouterList

public java.util.Vector getOnionRouterList()
returns a list of all onionrouters

Returns:
returns a list with the Description of all onion routers

getFirstOnionRouterList

public java.util.Vector getFirstOnionRouterList()
returns a list of all onion routers that are allowed at the moment as first onion routers

Returns:
first onion router list

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.io.IOException
java.net.ConnectException

initialize

public int initialize(AnonServerDescription torDirServer,
                      IServiceContainer a_serviceContainer)
Description copied from interface: AnonService
Initializes this AnonService. Depending on the AnonService, this may establish a connection to an AnonServer, which is described through the anonService parameter. This method must be called before any Channels could be created.

Specified by:
initialize in interface AnonService
Parameters:
torDirServer - AnonServer to use
Returns:
E_SUCCESS, if the connection could be estblished

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()
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 an IP to a given hostname

Parameters:
name - hostname
Returns:
IP address

testDNS

public void testDNS()
             throws java.lang.Exception
test the DNS-resolve mechanism

Throws:
java.lang.Exception

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