forward.client
Class DefaultClientProtocolHandler

java.lang.Object
  extended by forward.client.DefaultClientProtocolHandler

public class DefaultClientProtocolHandler
extends java.lang.Object

This is the implementation of the client side for the first version of the JAP routing protocol.


Field Summary
private  IStreamConnection m_connection
          This stores the forwarded connection.
private  int m_minDummyTrafficInterval
          This stores the minimal dummy traffic interval (in ms) for the forwarder.
private  MixCascade m_selectedMixCascade
          This stores the selected MixCascade.
private  int m_state
          This stores the internal protocol state.
private static int MAXIMUM_PROTOCOLMESSAGE_SIZE
          This is the maximum net size of a protocol message in bytes.
private static byte[] MESSAGE_END_SIGNATURE
          This is the end signature of every protocol message.
private static byte[] MESSAGE_START_SIGNATURE
          This is the start signature of every protocol message.
private static int PROTOCOL_VERSION
          This is the version of the current protocol implementation.
private static int STATE_CASCADE_SELECTED
          This is the state after we have sent our selected MixCascade to the forwarder.
private static int STATE_CLOSED_AFTER_ERROR
          This is the state after we have got an error and closed the connection.
private static int STATE_FORWARDING
          This is the state while forwarding is active.
private static int STATE_INITIALIZE
          This is the state after the physical connection to the forwarder is established and the protocol is initialized.
private static int STATE_OFFER_RECEIVED
          This is the state after receiving the forward connection offer from the forwarder.
 
Constructor Summary
DefaultClientProtocolHandler(IStreamConnection a_connection)
          Creates a new instance of DefaultClientProtocol handler.
 
Method Summary
private  boolean checkSignature(byte[] a_signature1, byte[] a_signature2)
          This method checks, whether to byte arrays have identical content or not.
private  byte[] createProtocolPacket(byte[] a_data)
          Creates a protocol packet from byte array with data.
private  org.w3c.dom.Document generateConnectionRequest()
          Creates the connection request message.
 ForwardConnectionDescriptor getConnectionDescriptor()
          Returns the connection descriptor with the offer from the forwarder.
private  byte[] readProtocolMessage()
          Reads a message from the associated network connection.
 void selectMixCascade(MixCascade a_mixCascade)
          This method must be called exactly once, after we have received the the connection offer from the forwarder.
private  void sendProtocolMessage(byte[] a_message)
          Sends a message to the associated network connection.
private  byte[] xmlToProtocolPacket(org.w3c.dom.Document a_doc)
          Creates a protocol packet from an XML structure.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROTOCOL_VERSION

private static final int PROTOCOL_VERSION
This is the version of the current protocol implementation. Interaction is only possible with forwarders, which use the same protocol version.

See Also:
Constant Field Values

MAXIMUM_PROTOCOLMESSAGE_SIZE

private static final int MAXIMUM_PROTOCOLMESSAGE_SIZE
This is the maximum net size of a protocol message in bytes. Bigger messages are not accepted and causes an exception.

See Also:
Constant Field Values

STATE_INITIALIZE

private static final int STATE_INITIALIZE
This is the state after the physical connection to the forwarder is established and the protocol is initialized.

See Also:
Constant Field Values

STATE_OFFER_RECEIVED

private static final int STATE_OFFER_RECEIVED
This is the state after receiving the forward connection offer from the forwarder.

See Also:
Constant Field Values

STATE_CASCADE_SELECTED

private static final int STATE_CASCADE_SELECTED
This is the state after we have sent our selected MixCascade to the forwarder.

See Also:
Constant Field Values

STATE_FORWARDING

private static final int STATE_FORWARDING
This is the state while forwarding is active.

See Also:
Constant Field Values

STATE_CLOSED_AFTER_ERROR

private static final int STATE_CLOSED_AFTER_ERROR
This is the state after we have got an error and closed the connection.

See Also:
Constant Field Values

MESSAGE_START_SIGNATURE

private static final byte[] MESSAGE_START_SIGNATURE
This is the start signature of every protocol message.


MESSAGE_END_SIGNATURE

private static final byte[] MESSAGE_END_SIGNATURE
This is the end signature of every protocol message.


m_connection

private IStreamConnection m_connection
This stores the forwarded connection.


m_state

private int m_state
This stores the internal protocol state. See the constants in this class.


m_minDummyTrafficInterval

private int m_minDummyTrafficInterval
This stores the minimal dummy traffic interval (in ms) for the forwarder. We have to create dummy traffic with at least that rate. If this value is -1, the forwarder doesn't need dummy traffic.


m_selectedMixCascade

private MixCascade m_selectedMixCascade
This stores the selected MixCascade.

Constructor Detail

DefaultClientProtocolHandler

public DefaultClientProtocolHandler(IStreamConnection a_connection)
Creates a new instance of DefaultClientProtocol handler.

Parameters:
a_connection - A active ProxyConnection to a forwarder.
Method Detail

getConnectionDescriptor

public ForwardConnectionDescriptor getConnectionDescriptor()
                                                    throws ClientForwardException
Returns the connection descriptor with the offer from the forwarder. This method must be called once after creating this protocol handler. If there is an error on the connection while receiving the connection offer, an ClientForwardException is thrown with detailed information.

Returns:
The connection descriptor with the connection offer from the forwarder.
Throws:
ClientForwardException

selectMixCascade

public void selectMixCascade(MixCascade a_mixCascade)
                      throws ClientForwardException
This method must be called exactly once, after we have received the the connection offer from the forwarder. If the call of this method doesn't throw an exception, everything is ready for starting the anonymous connection. This method throws an exception, if there is something wrong while sending our decision to the forwarder. At the moment this method must be called within the forwarder dummy traffic interval, because dummy traffic is not implemented within this protocol -> dummy traffic is available after starting the JAP AnonProxy on the forwarded connection.

Parameters:
a_mixCascade - The mixcascade from the connection offer we want to use.
Throws:
ClientForwardException

generateConnectionRequest

private org.w3c.dom.Document generateConnectionRequest()
                                                throws ClientForwardException
Creates the connection request message. It is sent directly after connecting the forwarding server to request the connection offer structure.

Returns:
The connection request XML structure.
Throws:
ClientForwardException

readProtocolMessage

private byte[] readProtocolMessage()
                            throws ClientForwardException
Reads a message from the associated network connection. Header and trailer of the protocol message are removed. If there is a connection or protocol error, an exception is thrown.

Returns:
The message read from the connection.
Throws:
ClientForwardException

sendProtocolMessage

private void sendProtocolMessage(byte[] a_message)
                          throws ClientForwardException
Sends a message to the associated network connection. The message must be in the protocol message format (with header and trailer).

Parameters:
a_message - The message to send.
Throws:
ClientForwardException

checkSignature

private boolean checkSignature(byte[] a_signature1,
                               byte[] a_signature2)
This method checks, whether to byte arrays have identical content or not.

Parameters:
a_signature1 - The first byte array.
a_signature2 - The second byte array.
Returns:
True, if both byte arrays are not null and have the same content, else the result is false.

xmlToProtocolPacket

private byte[] xmlToProtocolPacket(org.w3c.dom.Document a_doc)
                            throws java.lang.Exception
Creates a protocol packet from an XML structure.

Parameters:
doc - The XML structure which shall be transformed in a protocol packet.
Returns:
The protocol packet with the XML structure inside.
Throws:
java.lang.Exception

createProtocolPacket

private byte[] createProtocolPacket(byte[] a_data)
Creates a protocol packet from byte array with data. This method adds header and trailer to the data and returns the whole packet.

Parameters:
a_data - The bytes to put in the protocol packet.
Returns:
The protocol packet with data, header and trailer.