anon.tor
Class Circuit

java.lang.Object
  extended by anon.tor.Circuit
All Implemented Interfaces:
java.lang.Runnable

public final class Circuit
extends java.lang.Object
implements java.lang.Runnable

Author:
stefan

Field Summary
private  boolean m_bReceivedCreatedOrExtendedCell
           
private  CellQueue m_cellqueueSend
           
private  int m_circID
           
private  int m_circuitLength
           
private  boolean m_destroyed
           
private  OnionRouter m_FirstOR
           
private  FirstOnionRouterConnection m_FirstORConnection
           
private  int m_iRelayErrors
           
private  ORDescriptor m_lastORDescription
           
private  int m_MaxStreamsPerCircuit
           
private  java.lang.Object m_oDestroyedByPeerSync
           
private  java.util.Vector m_onionRouters
           
private  java.lang.Object m_oNotifySync
           
private  java.lang.Object m_oResolveSync
           
private  java.lang.Object m_oSendCellCounterSync
           
private  java.lang.Object m_oSendSync
           
private  MyRandom m_rand
           
private  int m_recvCellCounter
           
private  byte[] m_resolvedData
           
private  int m_sendCellCounter
           
private  int m_State
           
private  int m_streamCounter
           
private  java.util.Hashtable m_streams
           
private  java.lang.Thread m_threadSendCellLoop
           
static int MAX_STREAMS_OVER_CIRCUIT
           
private static int STATE_CLOSED
           
private static int STATE_CREATING
           
private static int STATE_READY
           
private static int STATE_SHUTDOWN
           
 
Constructor Summary
Circuit(int circID, FirstOnionRouterConnection onionProxy, java.util.Vector orList)
          constructor
 
Method Summary
private  void addToSendCellCounter(int value)
           
 void close()
          closes the circuit immediately.
protected  void close(int streamID)
          closes a stream
protected  int connectChannel(TorChannel channel, java.lang.String addr, int port)
          creates a channel through the tor-network
protected  void create()
          creates a circuit and connects to all onionrouters
 TorChannel createChannel(java.lang.String addr, int port)
          creates a channel through the tor-network
 void destroyedByPeer()
          circuit was destroyed by peer.
 void dispatchCell(Cell cell)
          dispatches cells to the opended channels
 int getCircID()
          returns the ID of this circuit
 boolean isAllowed(java.lang.String adr, int port)
          Checks if it is possible to connect to given host on a given port via this circuit
 boolean isClosed()
          check if the circuit is already destroyed
 boolean isShutdown()
          check if the circuit is already shutdown
 java.lang.String resolveDNS(java.lang.String name)
          Returns a address to a given name
 void run()
           
 void send(Cell cell)
          sends a cell through the circuit - the cells are placed in a queue for sending
 void sendUrgent(Cell cell)
          urgently sends a cell through the circuit (send it directly without placing it in the send queue)
 void setMaxNrOfStreams(int i)
          Sets the maximum number of possible streams over this circuit
 void shutdown()
          shutdown this circuit so that it cannot be used for new connections but leaves the circuit opened for all currently used channels to close the circuit immediately use close()
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_STREAMS_OVER_CIRCUIT

public static final int MAX_STREAMS_OVER_CIRCUIT
See Also:
Constant Field Values

m_FirstOR

private OnionRouter m_FirstOR

m_lastORDescription

private ORDescriptor m_lastORDescription

m_FirstORConnection

private FirstOnionRouterConnection m_FirstORConnection

m_onionRouters

private java.util.Vector m_onionRouters

m_circID

private int m_circID

m_streams

private java.util.Hashtable m_streams

m_State

private volatile int m_State

m_iRelayErrors

private volatile int m_iRelayErrors

STATE_CLOSED

private static final int STATE_CLOSED
See Also:
Constant Field Values

STATE_SHUTDOWN

private static final int STATE_SHUTDOWN
See Also:
Constant Field Values

STATE_READY

private static final int STATE_READY
See Also:
Constant Field Values

STATE_CREATING

private static final int STATE_CREATING
See Also:
Constant Field Values

m_streamCounter

private int m_streamCounter

m_circuitLength

private int m_circuitLength

m_MaxStreamsPerCircuit

private int m_MaxStreamsPerCircuit

m_recvCellCounter

private volatile int m_recvCellCounter

m_sendCellCounter

private volatile int m_sendCellCounter

m_destroyed

private boolean m_destroyed

m_resolvedData

private byte[] m_resolvedData

m_oResolveSync

private java.lang.Object m_oResolveSync

m_oSendCellCounterSync

private java.lang.Object m_oSendCellCounterSync

m_oSendSync

private java.lang.Object m_oSendSync

m_oDestroyedByPeerSync

private java.lang.Object m_oDestroyedByPeerSync

m_bReceivedCreatedOrExtendedCell

private volatile boolean m_bReceivedCreatedOrExtendedCell

m_oNotifySync

private java.lang.Object m_oNotifySync

m_rand

private MyRandom m_rand

m_threadSendCellLoop

private java.lang.Thread m_threadSendCellLoop

m_cellqueueSend

private CellQueue m_cellqueueSend
Constructor Detail

Circuit

public Circuit(int circID,
               FirstOnionRouterConnection onionProxy,
               java.util.Vector orList)
        throws java.io.IOException
constructor

Parameters:
circID - ID of this circuit
orList - list of onionrouters to use for this circuit
onionProxy - FirstOnionRouter, where all the data will be send. the onionProxy has to be the firstOR in the orList
Throws:
java.io.IOException
Method Detail

addToSendCellCounter

private void addToSendCellCounter(int value)

create

protected void create()
               throws java.io.IOException
creates a circuit and connects to all onionrouters

Throws:
java.io.IOException

shutdown

public void shutdown()
shutdown this circuit so that it cannot be used for new connections but leaves the circuit opened for all currently used channels to close the circuit immediately use close()

Throws:
java.lang.Exception

close

public void close()
closes the circuit immediately.

Throws:
java.lang.Exception

destroyedByPeer

public void destroyedByPeer()
circuit was destroyed by peer.

Throws:
java.lang.Exception

isClosed

public boolean isClosed()
check if the circuit is already destroyed

Returns:
if the channel is closed

isShutdown

public boolean isShutdown()
check if the circuit is already shutdown

Returns:
if the circuit is shutdown

dispatchCell

public void dispatchCell(Cell cell)
                  throws java.io.IOException
dispatches cells to the opended channels

Parameters:
cell - cell
Throws:
java.io.IOException

send

public void send(Cell cell)
          throws java.io.IOException,
                 java.lang.Exception
sends a cell through the circuit - the cells are placed in a queue for sending

Parameters:
cell - cell to send
Throws:
java.io.IOException
java.lang.Exception

sendUrgent

public void sendUrgent(Cell cell)
                throws java.io.IOException,
                       java.lang.Exception
urgently sends a cell through the circuit (send it directly without placing it in the send queue)

Parameters:
cell - cell to send
Throws:
java.io.IOException
java.lang.Exception

resolveDNS

public java.lang.String resolveDNS(java.lang.String name)
Returns a address to a given name

Parameters:
name -
Returns:
Type (1 octet) Length (1 octet) Value (variable-width) "Length" is the length of the Value field. "Type" is one of: 0x04 -- IPv4 address 0x06 -- IPv6 address 0xF0 -- Error, transient 0xF1 -- Error, nontransient

close

protected void close(int streamID)
              throws java.lang.Exception
closes a stream

Parameters:
streamID - streamID
Throws:
java.lang.Exception

getCircID

public int getCircID()
returns the ID of this circuit

Returns:
ID

createChannel

public TorChannel createChannel(java.lang.String addr,
                                int port)
                         throws java.io.IOException
creates a channel through the tor-network

Parameters:
addr - address of the server you want do connect
port - port
Returns:
a channel
Throws:
java.io.IOException

connectChannel

protected int connectChannel(TorChannel channel,
                             java.lang.String addr,
                             int port)
creates a channel through the tor-network

Parameters:
addr - address of the server you want do connect
port - port
Returns:
ErrorCode.E_SUCCESS if channel could be established

isAllowed

public boolean isAllowed(java.lang.String adr,
                         int port)
Checks if it is possible to connect to given host on a given port via this circuit

Parameters:
adr - address
port - port
Returns:
true if a connection is possible, else if it is not

setMaxNrOfStreams

public void setMaxNrOfStreams(int i)
Sets the maximum number of possible streams over this circuit

Parameters:
i - number of streams

run

public void run()
Specified by:
run in interface java.lang.Runnable