anon.server.impl
Class MuxSocket

java.lang.Object
  extended byanon.server.impl.MuxSocket
All Implemented Interfaces:
IReplayCtrlChannelMsgListener, java.lang.Runnable

public final class MuxSocket
extends java.lang.Object
implements java.lang.Runnable, IReplayCtrlChannelMsgListener


Field Summary
private static short CHANNEL_CLOSE
           
private static short CHANNEL_DATA
           
private static short CHANNEL_DUMMY
           
private static short CHANNEL_OPEN
           
private static int CHANNEL_TYPE_HTTP
           
private static int CHANNEL_TYPE_SOCKS
           
static int DATA_SIZE
           
static int KEY_SIZE
           
private static int LOGIN_TIMEOUT
           
private  java.util.Vector m_anonServiceListener
           
private  byte[] m_arEmpty
           
private  MixParameters[] m_arMixParameters
           
private  byte[] m_arOutBuff
           
private  byte[] m_arOutBuff2
           
private  boolean m_bConnectionStoppedManually
           
private  boolean m_bIsConnected
           
private  boolean m_bisCrypted
           
private  boolean m_bMixProtocolWithTimestamp
           
private  boolean m_bNewFlowControl
           
private  boolean m_bPaymentRequired
           
private  boolean m_bRunFlag
           
private  java.util.Dictionary m_ChannelList
           
private  SymCipher m_cipherFirstMix
           
private  SymCipher m_cipherIn
           
private  SymCipher m_cipherInAI
           
private  SymCipher m_cipherOut
           
private  SymCipher m_cipherOutAI
           
private  ControlChannelDispatcher m_ControlChannelDispatcher
           
private  DummyTraffic m_DummyTraffic
           
private  int m_iChainLen
           
private  int m_iMixProtocolVersion
           
private  java.io.DataInputStream m_inDataStream
           
private  ProxyConnection m_ioSocket
           
private  KeyPool m_KeyPool
           
private  int m_mixCascadeCertificateLock
          Stores the lock on the certificate used by the mixcascade to sign all cascade related messages, like the MixCascade or MixCascadeStatus structures.
private  byte[] m_MixPacketRecv
           
private  byte[] m_MixPacketSend
           
private  long m_numReceivedPackets
           
private  long m_numSentPackets
           
private  java.io.BufferedOutputStream m_outStream
           
private  Pay m_Pay
           
private  ReplayControlChannel m_replayControlChannel
           
private  java.security.SecureRandom m_SecureRandom
           
private  long m_transferredBytes
           
private  int m_waitingChannels
           
private static int MAX_CHANNELS_PER_CONNECTION
           
private static int MIX_PROTOCOL_VERSION_0_2
           
private static int MIX_PROTOCOL_VERSION_0_4
           
private static int MIX_PROTOCOL_VERSION_0_5
           
private static int MIX_PROTOCOL_VERSION_0_7
           
private static int MIX_PROTOCOL_VERSION_0_8
           
private static int MIX_PROTOCOL_VERSION_0_9
           
private static short NEW_FLOW_CONTROL_FLAG
           
private static int PACKET_SIZE
           
private static short PAYLOAD_LEN_MASK
           
static int PAYLOAD_SIZE
           
private static int RSA_SIZE
           
private static int SECONDS_PER_INTERVAL
           
private  java.lang.Thread threadRunLoop
           
 
Constructor Summary
private MuxSocket()
           
 
Method Summary
 void addEventListener(AnonServiceEventListener l)
           
private  int close()
           
 int close(int channel_id)
           
 int connectViaFirewall(MixCascade mixCascade, ImmutableProxyInterface a_proxyInterface)
          Try to connect to a given MixCascade.
static MuxSocket create()
           
private  void fireConnectionError()
           
private  void fireConnectionEstablished()
           
private  void firePacketMixed()
           
 long getAndResetTransferredBytes()
          Resets the payload counter to 0 and returns the value as it was before the reset.
 ControlChannelDispatcher getControlChannelDispatcher()
           
 int getNumberOfMixes()
          Returns how many Mixes are in the cascade
 Pay getPay()
           
private  int getTimestampForTime(long refTime)
          Returns the number of 'intervalls' gone since start of refTime.
 void gotTimestamps(ReplayTimestamp[] theTimestamps)
          We got some replay timestamps from mixes of the current cascade.
 int initialize(ProxyConnection a_proxyConnection)
          This method does some initialization and the initial key exchange.
 boolean isConnected()
           
 Channel newChannel(int type)
           
private  int processXmlKeys(byte[] buff)
          Reads the public key from the Mixes and try to initialize the key array
private  void removeCascadeCertificateFromCertificateStore()
          Releases the lock on the certificate used by the mixcascade to sign all cascade related messages, like the MixCascade or MixCascadeStatus structures.
 void removeEventListener(AnonServiceEventListener l)
           
 void run()
           
private  void runStopped()
           
 void send(int channel, int type, byte[] buff, short len_and_flags)
           
protected  void sendDummy()
           
private  void sendMixPacket()
           
protected  void sendRawMixPacket(int channel, short flags, byte[] data, int off, int data_len)
          Sends a 'raw' MixPacket.
 void setDummyTraffic(int intervall)
          Enables or Disables DummyTraffic.
private  void setEnableEncryption(boolean b)
           
private  void setEncryptionKeys(byte[] keys, int len)
           
 int startService(ImmutableProxyInterface a_proxy)
           
 void stopService()
           
private  void updateBytesForAccounting()
          Updates the transferred bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_SecureRandom

private java.security.SecureRandom m_SecureRandom

m_ChannelList

private java.util.Dictionary m_ChannelList

m_waitingChannels

private int m_waitingChannels

m_outStream

private java.io.BufferedOutputStream m_outStream

m_inDataStream

private java.io.DataInputStream m_inDataStream

m_MixPacketSend

private byte[] m_MixPacketSend

m_MixPacketRecv

private byte[] m_MixPacketRecv

m_ioSocket

private ProxyConnection m_ioSocket

m_arOutBuff

private byte[] m_arOutBuff

m_arOutBuff2

private byte[] m_arOutBuff2

m_arEmpty

private byte[] m_arEmpty

m_arMixParameters

private MixParameters[] m_arMixParameters

m_KeyPool

private KeyPool m_KeyPool

m_iChainLen

private int m_iChainLen

m_iMixProtocolVersion

private int m_iMixProtocolVersion

m_bRunFlag

private volatile boolean m_bRunFlag

m_bIsConnected

private boolean m_bIsConnected

m_cipherIn

private SymCipher m_cipherIn

m_cipherOut

private SymCipher m_cipherOut

m_bisCrypted

private boolean m_bisCrypted

m_cipherFirstMix

private SymCipher m_cipherFirstMix

m_cipherInAI

private SymCipher m_cipherInAI

m_cipherOutAI

private SymCipher m_cipherOutAI

m_transferredBytes

private volatile long m_transferredBytes

KEY_SIZE

public static final int KEY_SIZE
See Also:
Constant Field Values

DATA_SIZE

public static final int DATA_SIZE
See Also:
Constant Field Values

PAYLOAD_SIZE

public static final int PAYLOAD_SIZE
See Also:
Constant Field Values

PACKET_SIZE

private static final int PACKET_SIZE
See Also:
Constant Field Values

RSA_SIZE

private static final int RSA_SIZE
See Also:
Constant Field Values

CHANNEL_DATA

private static final short CHANNEL_DATA
See Also:
Constant Field Values

CHANNEL_CLOSE

private static final short CHANNEL_CLOSE
See Also:
Constant Field Values

CHANNEL_OPEN

private static final short CHANNEL_OPEN
See Also:
Constant Field Values

CHANNEL_DUMMY

private static final short CHANNEL_DUMMY
See Also:
Constant Field Values

PAYLOAD_LEN_MASK

private static final short PAYLOAD_LEN_MASK
See Also:
Constant Field Values

NEW_FLOW_CONTROL_FLAG

private static final short NEW_FLOW_CONTROL_FLAG
See Also:
Constant Field Values

CHANNEL_TYPE_HTTP

private static final int CHANNEL_TYPE_HTTP
See Also:
Constant Field Values

CHANNEL_TYPE_SOCKS

private static final int CHANNEL_TYPE_SOCKS
See Also:
Constant Field Values

MAX_CHANNELS_PER_CONNECTION

private static final int MAX_CHANNELS_PER_CONNECTION
See Also:
Constant Field Values

MIX_PROTOCOL_VERSION_0_9

private static final int MIX_PROTOCOL_VERSION_0_9
See Also:
Constant Field Values

MIX_PROTOCOL_VERSION_0_8

private static final int MIX_PROTOCOL_VERSION_0_8
See Also:
Constant Field Values

MIX_PROTOCOL_VERSION_0_7

private static final int MIX_PROTOCOL_VERSION_0_7
See Also:
Constant Field Values

MIX_PROTOCOL_VERSION_0_5

private static final int MIX_PROTOCOL_VERSION_0_5
See Also:
Constant Field Values

MIX_PROTOCOL_VERSION_0_4

private static final int MIX_PROTOCOL_VERSION_0_4
See Also:
Constant Field Values

MIX_PROTOCOL_VERSION_0_2

private static final int MIX_PROTOCOL_VERSION_0_2
See Also:
Constant Field Values

LOGIN_TIMEOUT

private static final int LOGIN_TIMEOUT
See Also:
Constant Field Values

threadRunLoop

private java.lang.Thread threadRunLoop

m_DummyTraffic

private DummyTraffic m_DummyTraffic

m_bMixProtocolWithTimestamp

private boolean m_bMixProtocolWithTimestamp

m_bNewFlowControl

private boolean m_bNewFlowControl

SECONDS_PER_INTERVAL

private static final int SECONDS_PER_INTERVAL
See Also:
Constant Field Values

m_replayControlChannel

private ReplayControlChannel m_replayControlChannel

m_ControlChannelDispatcher

private ControlChannelDispatcher m_ControlChannelDispatcher

m_mixCascadeCertificateLock

private int m_mixCascadeCertificateLock
Stores the lock on the certificate used by the mixcascade to sign all cascade related messages, like the MixCascade or MixCascadeStatus structures. The certificate will be stored within the signature verification certificate store until the lock is released (done when the connection to the mixcascade is closed).


m_anonServiceListener

private java.util.Vector m_anonServiceListener

m_bConnectionStoppedManually

private volatile boolean m_bConnectionStoppedManually

m_numSentPackets

private long m_numSentPackets

m_numReceivedPackets

private long m_numReceivedPackets

m_Pay

private Pay m_Pay

m_bPaymentRequired

private boolean m_bPaymentRequired
Constructor Detail

MuxSocket

private MuxSocket()
Method Detail

create

public static MuxSocket create()

isConnected

public boolean isConnected()

getNumberOfMixes

public int getNumberOfMixes()
Returns how many Mixes are in the cascade


setDummyTraffic

public void setDummyTraffic(int intervall)
Enables or Disables DummyTraffic.

Parameters:
intervall - milliseconds of inactivity after which a dummy is send. Set to '-1' to disable Dummy Traffic.

initialize

public int initialize(ProxyConnection a_proxyConnection)
This method does some initialization and the initial key exchange.

Parameters:
a_proxyConnection - A ProxyConnection to the first mix of a cascade.
Returns:
The errorcode, see anon.ErrorCodes.

connectViaFirewall

public int connectViaFirewall(MixCascade mixCascade,
                              ImmutableProxyInterface a_proxyInterface)
Try to connect to a given MixCascade.

Parameters:
mixCascade - MixCascade to connect to
a_proxyInterface - ImmutableProxyInterface a proxy to use (or null if no proxy should be used)
Returns:
int E_CONNECT, if a connection error occurs E_SUCCESS if successful E_ALREADY_CONNECTED if allready connected

setEnableEncryption

private void setEnableEncryption(boolean b)

setEncryptionKeys

private void setEncryptionKeys(byte[] keys,
                               int len)

processXmlKeys

private int processXmlKeys(byte[] buff)
Reads the public key from the Mixes and try to initialize the key array

Returns:
E_SUCCESS if all is ok

newChannel

public Channel newChannel(int type)
                   throws java.net.ConnectException
Throws:
java.net.ConnectException

close

public int close(int channel_id)

sendDummy

protected void sendDummy()

sendRawMixPacket

protected void sendRawMixPacket(int channel,
                                short flags,
                                byte[] data,
                                int off,
                                int data_len)
Sends a 'raw' MixPacket.


startService

public int startService(ImmutableProxyInterface a_proxy)

stopService

public void stopService()

close

private int close()

run

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

runStopped

private void runStopped()

sendMixPacket

private void sendMixPacket()
                    throws java.lang.Exception
Throws:
java.lang.Exception

send

public void send(int channel,
                 int type,
                 byte[] buff,
                 short len_and_flags)
          throws java.io.IOException
Throws:
java.io.IOException

getTimestampForTime

private int getTimestampForTime(long refTime)
Returns the number of 'intervalls' gone since start of refTime.


getControlChannelDispatcher

public ControlChannelDispatcher getControlChannelDispatcher()

getAndResetTransferredBytes

public long getAndResetTransferredBytes()
Resets the payload counter to 0 and returns the value as it was before the reset.


updateBytesForAccounting

private void updateBytesForAccounting()
Updates the transferred bytes.


removeCascadeCertificateFromCertificateStore

private void removeCascadeCertificateFromCertificateStore()
Releases the lock on the certificate used by the mixcascade to sign all cascade related messages, like the MixCascade or MixCascadeStatus structures. That certificate is stored within the signature verification certificate store. A call of this method will release our lock on that certificate, so the certificate can be removed from the store, if there is no other lock. If we don't have a lock on any certificate, nothing happens.


addEventListener

public void addEventListener(AnonServiceEventListener l)

removeEventListener

public void removeEventListener(AnonServiceEventListener l)

fireConnectionEstablished

private void fireConnectionEstablished()

fireConnectionError

private void fireConnectionError()

firePacketMixed

private void firePacketMixed()

gotTimestamps

public void gotTimestamps(ReplayTimestamp[] theTimestamps)
We got some replay timestamps from mixes of the current cascade. We will adjust the reference times for this mixes.

Specified by:
gotTimestamps in interface IReplayCtrlChannelMsgListener

getPay

public Pay getPay()