anon.tor
Class Circuit

java.lang.Object
  extended by anon.tor.Circuit

public class Circuit
extends java.lang.Object

Author:
stefan

Field Summary
private  boolean m_bReceivedCreatedOrExtendedCell
           
private  CellQueue m_cellQueue
           
private  int m_circID
           
private  int m_circuitLength
           
private  boolean m_destroyed
           
private  java.util.Date m_destroyTime
           
private  OnionRouter m_FirstOR
           
private  FirstOnionRouterConnection m_FirstORConnection
           
private  ORDescription m_lastORDescription
           
private  int m_MaxStreamsPerCircuit
           
private static long m_minCircuitLifetime
           
private  java.lang.Object m_oDeliverSync
           
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_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
           
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
 void close()
          closes the circuit immediately.
protected  void close(int streamID)
          closes a stream
protected  void 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
private  void deliverCells()
          delivers the cells if the FOR accept more cells
 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 send(Cell cell)
          sends a cell through the circuit
 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 ORDescription 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

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 int m_recvCellCounter

m_sendCellCounter

private int m_sendCellCounter

m_destroyed

private boolean m_destroyed

m_cellQueue

private CellQueue m_cellQueue

m_resolvedData

private byte[] m_resolvedData

m_oResolveSync

private java.lang.Object m_oResolveSync

m_oDeliverSync

private java.lang.Object m_oDeliverSync

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_destroyTime

private java.util.Date m_destroyTime

m_minCircuitLifetime

private static long m_minCircuitLifetime
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

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

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

deliverCells

private void deliverCells()
                   throws java.io.IOException
delivers the cells if the FOR accept more cells

Throws:
java.lang.Exception
java.io.IOException

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 void connectChannel(TorChannel channel,
                              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
Throws:
java.io.IOException

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