public class Tor extends java.lang.Object implements java.lang.Runnable, AnonService
ANONLIB_VERSION
Modifier | Constructor and Description |
---|---|
private |
Tor()
Constructor
initialize variables
|
Modifier and Type | Method and Description |
---|---|
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() |
void |
initialize(AnonServerDescription torDirServer,
IServiceContainer a_serviceContainer,
TermsAndConditionConfirmation termsConfirmation,
boolean a_bIsReconnect)
initializes Tor service
|
boolean |
isConnected()
Returns true if this Anon Service is connected, e.g. initialized and usable
|
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 for the proxy, which should be used to establish network connections
|
void |
setSocketFactory(HTTPClient.HTTPClientSocketFactory socketFactory)
Sets the socket factory to be used in creating sockets to connect to the AnonService.
|
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
|
public static final int MAX_ROUTE_LEN
public static final int MIN_ROUTE_LEN
public static final int DNS_TIME_OUT
private static Tor ms_theTorInstance
private ORList m_orList
private java.util.Vector m_allowedORNames
private java.util.Vector m_allowedFirstORNames
private java.util.Vector m_allowedExitNodeNames
private Circuit[] m_activeCircuits
private int m_MaxNrOfActiveCircuits
private java.lang.Object m_oActiveCircuitSync
private java.lang.Object m_oStartStopSync
private FirstOnionRouterConnectionFactory m_firstORFactory
private Database m_DNSCache
private java.util.Hashtable m_CircuitForDestination
private java.util.Vector[] m_KeysForCircuit
private volatile boolean m_bIsStarted
private boolean m_bIsCreatingCircuit
private boolean m_useDNSCache
private int m_circuitLengthMin
private int m_circuitLengthMax
private int m_ConnectionsPerCircuit
private MyRandom m_rand
public static final java.lang.String DEFAULT_DIR_SERVER_ADDR
public static final int DEFAULT_DIR_SERVER_PORT
private java.lang.Thread m_circuitCreator
private volatile boolean m_bCloseCreator
private IMutableProxyInterface m_proxyInterface
private void updateORList()
protected Circuit getCircuitForDestination(java.lang.String addr, int port, java.util.Hashtable exludeCircuits)
addr
- host addressport
- host portexludeCircuits
- Contains circuits, which should not be considered
when finding an appropirated circuit for the given destination. Can be NULL or emptyprivate Circuit createNewCircuit(java.lang.String addr, int port)
addr
- addressport
- portpublic static Tor getInstance()
public void run()
run
in interface java.lang.Runnable
private void start(boolean startCircuits) throws java.io.IOException
startCircuits
- create all circuits at startupjava.io.IOException
private void stop()
private void setCircuitLength(int min, int max)
min
- minimum circuit lengthmax
- maximum circuit lengthprivate void setConnectionsPerRoute(int i)
private void setORListServer(boolean bUseInfoService, java.lang.String name, int port)
name
- addressport
- portpublic void setUseDNSCache(boolean usecache)
usecache
- public AnonChannel createChannel(int type) throws java.net.ConnectException
createChannel
in interface AnonService
type
- channeltype (only AnonChannel.SOCKS is supported at the moment)java.io.IOException
java.net.ConnectException
public AnonChannel createChannel(java.lang.String addr, int port) throws java.net.ConnectException
addr
- addressport
- portjava.net.ConnectException
public void initialize(AnonServerDescription torDirServer, IServiceContainer a_serviceContainer, TermsAndConditionConfirmation termsConfirmation, boolean a_bIsReconnect) throws AnonServiceException
initialize
in interface AnonService
torDirServer
- Parameters describing the service configuration.AnonServiceException
public int setProxy(IMutableProxyInterface a_Proxy)
AnonService
setProxy
in interface AnonService
public IMutableProxyInterface getProxy()
public void shutdown(boolean a_bResetTransferredBytes)
shutdown
in interface AnonService
public void addEventListener(AnonServiceEventListener l)
AnonService
AnonServiceEventListener
.addEventListener
in interface AnonService
l
- Listener to addpublic void removeEventListeners()
removeEventListeners
in interface AnonService
public void removeEventListener(AnonServiceEventListener l)
AnonService
removeEventListener
in interface AnonService
l
- Listener, which will be removedpublic java.lang.String resolveDNS(java.lang.String name)
name
- hostnamepublic boolean isConnected()
AnonService
isConnected
in interface AnonService
public void setSocketFactory(HTTPClient.HTTPClientSocketFactory socketFactory)
AnonService
setSocketFactory
in interface AnonService
socketFactory
- socket factory used to create sockets, if NULL the default socket factory of the JRE is used.Copyright © 2023. All rights reserved.