userDatabase
Class User

java.lang.Object
  extended by userDatabase.User

public final class User
extends java.lang.Object

Data structure used to store user-specific data (for example identifiers, session keys or buffers).

Author:
Karl-Peter Fuchs

Field Summary
private  java.nio.ByteBuffer clientReadBuffer
          ByteBuffer used to cache fragments of a message received from the User's Client.
private  java.nio.ByteBuffer clientWriteBuffer
          ByteBuffer used to cache messages that shall be sent to this User's Client.Needed for non-blocking I/O.
private static NetworkClockController clock
          Reference on component NetworkClock.
private  javax.crypto.Cipher decryptCipher
          Cipher used to decrypt this User's Requests (ChannelMessages and symmetric part of ChannelEstablishMessages).
private  javax.crypto.Cipher encryptCipher
          Cipher used to encrypt this User's Replyies.
private  boolean hasMessageInCurrentBatch
          Indicates whether a Request of this User is already in batch or not (used to prevent flooding attacks).
private  boolean hasMessageInCurrentReplyBatch
          Indicates whether a Reply for this User is already in batch or not (used to prevent flooding attacks).
private  java.lang.Integer IDENTIFIER
          A (local) identifier for this User.
private  java.lang.Integer IDENTIFIER_FOR_NEXT_MIX
          An identifier for this User, used by the next mix of the cascade.
private static InternalInformationPortController internalInformationPort
          Reference on component InternalInformationPort.
private  boolean isChannelEstablished
          Indicates whether a channel (used to transmit ChannelMessages) has been establish for/by this User or not.
private  boolean isPutInProxyReadBufferWaiting
          Indicates whether putInProxyReadBuffer(byte[]) is waiting for free space in proxyReadBuffer or not (used for synchronization).
private  long lastActivity
          Timestamp of this User's last activity.
private static java.util.logging.Logger LOGGER
          Logger used to log and display information.
private  javax.crypto.SecretKey macKey
          SecretKey used for message authentication codes.
private static int MAX_REPLY_LENGTH
          Maximum size of a Reply in byte (used to initialize buffers).
private static int MAX_REQUEST_LENGTH
          Maximum size of a Request in byte (used to initialize buffers).
private  java.nio.ByteBuffer proxyReadBuffer
          ByteBuffer used to cache data received from proxy server.
private  java.nio.ByteBuffer proxyWriteBuffer
          ByteBuffer used to cache messages that shall be sent to this User's Client.
private static java.security.SecureRandom secureRandom
          Random number generator used to generate IDENTIFIER_FOR_NEXT_MIX.
private  java.nio.channels.SocketChannel socketChannel
          Reference on User's SocketChannel.
 
Constructor Summary
User(int identifier)
          Creates a new User using the bypassed identifier.
 
Method Summary
 int availableDataInProxyReadBuffer()
          Returns the number of bytes currently available in proxyReadBuffer, which contains data received from proxy server for this User.
 int availableDataInProxyWriteBuffer()
          Returns the number of bytes currently available in proxyWriteBuffer, which contains data that shall be sent to the proxy server.
 java.nio.ByteBuffer getClientReadBuffer()
          Returns this User's ByteBuffer used for caching fragments of a message received from the corresponding Client.
 java.nio.ByteBuffer getClientWriteBuffer()
          Returns this User's ByteBuffer used for caching messages that shall be sent to the corresponding Client.
 javax.crypto.Cipher getDecryptCipher()
          Returns this User's decryptCipher, used to decrypt Requests.
 javax.crypto.Cipher getEncryptCipher()
          Returns this User's encryptCipher, used to encrypt Replyies.
 byte[] getFromProxyReadBuffer(int limit)
          Used to read data from proxyReadBuffer, which contains data received from proxy server for this User.
 byte[] getFromProxyWriteBuffer(int limit)
          Used to read data from proxyWriteBuffer, which contains data that shall be sent to the proxy server.
 boolean getHasMessageInCurrentBatch()
          Returns whether a Request of this User is already in batch or not (used to prevent flooding attacks).
 boolean getHasMessageInCurrentReplyBatch()
          Returns whether a Reply of this User is already in batch or not (used to prevent flooding attacks).
 java.lang.Integer getIdentifier()
          Returns this Users (local) identifier (used to distinguish between Users).
 java.lang.Integer getIdentifierForNextMix()
          Returns this User's identifier, used by the next mix of the cascade (used to distinguish between Users).
 boolean getIsChannelEstablished()
          Returns whether a channel (used to transmit ChannelMessages) has been establish for/by this User or not.
 javax.crypto.SecretKey getMacKey()
          Returns the SecretKey, used for validating message authentication codes by this User.
 java.nio.channels.SocketChannel getSocketChannel()
          Returns this User's SocketChannel.
 long getTimestampOfLastActivity()
          Returns a timestamp of this User's last activity.
 void initializeClientBuffers(java.nio.channels.SocketChannel socketChannel)
          Allocates space for the buffers used to communicate with this User's corresponding Client (needed for non-blocking I/O).
 void initializeProxyBuffers()
          Allocates space for the buffers used to communicate with this User's corresponding proxy server (needed for non-blocking I/O).
 boolean isStillValid(long timeout)
          Indicates whether this User's last activity took place during the last timeout ms or not (used to detect outdated Users).
 void putInProxyReadBuffer(byte[] data)
          Used to add data received from proxy server for this User.
 void putInProxyWriteBuffer(byte[] data)
          Used to add data, that shall be sent to proxy server.
 void setDecryptCipher(javax.crypto.Cipher decryptCipher)
          Makes this User use the bypassed Cipher for decrypting Requests
 void setEncryptCipher(javax.crypto.Cipher encryptCipher)
          Makes this User use the bypassed Cipher for encrypting Replyies.
 void setHasMessageInCurrentBatch(boolean newValue)
          Used to indicate, whether a Request of this User is already in batch or not (used to prevent flooding attacks).
 void setHasMessageInCurrentReplyBatch(boolean newValue)
          Used to indicate, whether a Reply for this User is already in batch or not (used to prevent flooding attacks).
 void setIsChannelEstablished(boolean newValue)
          Sets variable isChannelEstablished to the bypassed value (indicates whether a channel (used to transmit ChannelMessages) has been establish for/by this User or not).
 void setMacKey(javax.crypto.SecretKey newMacKey)
          Makes this User use the bypassed SecretKey for validating message authentication codes.
 void setTimestampOfLastActivity()
          Must be called when User sends a Message (Used to detect inactive Users).
 java.lang.String toString()
          Returns a simple String representation of this class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

internalInformationPort

private static InternalInformationPortController internalInformationPort
Reference on component InternalInformationPort. Used to display and/or log data and read general settings.


LOGGER

private static final java.util.logging.Logger LOGGER
Logger used to log and display information.


MAX_REQUEST_LENGTH

private static int MAX_REQUEST_LENGTH
Maximum size of a Request in byte (used to initialize buffers).


MAX_REPLY_LENGTH

private static int MAX_REPLY_LENGTH
Maximum size of a Reply in byte (used to initialize buffers).


secureRandom

private static java.security.SecureRandom secureRandom
Random number generator used to generate IDENTIFIER_FOR_NEXT_MIX.

See Also:
IDENTIFIER_FOR_NEXT_MIX

clock

private static NetworkClockController clock
Reference on component NetworkClock.


IDENTIFIER

private final java.lang.Integer IDENTIFIER
A (local) identifier for this User.


IDENTIFIER_FOR_NEXT_MIX

private final java.lang.Integer IDENTIFIER_FOR_NEXT_MIX
An identifier for this User, used by the next mix of the cascade. Note: Different identifiers must be used to prevent linkability.


lastActivity

private long lastActivity
Timestamp of this User's last activity.


isChannelEstablished

private boolean isChannelEstablished
Indicates whether a channel (used to transmit ChannelMessages) has been establish for/by this User or not.


clientReadBuffer

private java.nio.ByteBuffer clientReadBuffer
ByteBuffer used to cache fragments of a message received from the User's Client. Needed for non-blocking I/O.

See Also:
ClientConnectionHandler

clientWriteBuffer

private java.nio.ByteBuffer clientWriteBuffer
ByteBuffer used to cache messages that shall be sent to this User's Client.Needed for non-blocking I/O.

See Also:
ClientConnectionHandler

proxyReadBuffer

private java.nio.ByteBuffer proxyReadBuffer
ByteBuffer used to cache data received from proxy server. Needed for non-blocking I/O.


proxyWriteBuffer

private java.nio.ByteBuffer proxyWriteBuffer
ByteBuffer used to cache messages that shall be sent to this User's Client. Needed for non-blocking I/O.

See Also:
ClientConnectionHandler

macKey

private javax.crypto.SecretKey macKey
SecretKey used for message authentication codes.


socketChannel

private java.nio.channels.SocketChannel socketChannel
Reference on User's SocketChannel. Needed for non-blocking I/O.


hasMessageInCurrentBatch

private boolean hasMessageInCurrentBatch
Indicates whether a Request of this User is already in batch or not (used to prevent flooding attacks).


hasMessageInCurrentReplyBatch

private boolean hasMessageInCurrentReplyBatch
Indicates whether a Reply for this User is already in batch or not (used to prevent flooding attacks).


encryptCipher

private javax.crypto.Cipher encryptCipher
Cipher used to encrypt this User's Replyies.


decryptCipher

private javax.crypto.Cipher decryptCipher
Cipher used to decrypt this User's Requests (ChannelMessages and symmetric part of ChannelEstablishMessages).


isPutInProxyReadBufferWaiting

private boolean isPutInProxyReadBufferWaiting
Indicates whether putInProxyReadBuffer(byte[]) is waiting for free space in proxyReadBuffer or not (used for synchronization).

Constructor Detail

User

public User(int identifier)
Creates a new User using the bypassed identifier.

Parameters:
identifier - A (local) identifier for this User used to distinguish between Users.
Method Detail

getIdentifier

public java.lang.Integer getIdentifier()
Returns this Users (local) identifier (used to distinguish between Users).

Returns:
This Users (local) identifier.

getIdentifierForNextMix

public java.lang.Integer getIdentifierForNextMix()
Returns this User's identifier, used by the next mix of the cascade (used to distinguish between Users). Note: Different identifiers must be used to prevent linkability.

Returns:
This Users identifier, used by the next mix of the cascade

getIsChannelEstablished

public boolean getIsChannelEstablished()
Returns whether a channel (used to transmit ChannelMessages) has been establish for/by this User or not.

Returns:
Whether a channel (used to transmit ChannelMessages) has been establish for/by this User or not.

setIsChannelEstablished

public void setIsChannelEstablished(boolean newValue)
Sets variable isChannelEstablished to the bypassed value (indicates whether a channel (used to transmit ChannelMessages) has been establish for/by this User or not).

Parameters:
newValue - Value isChannelEstablished variable shall be set to.

isStillValid

public boolean isStillValid(long timeout)
Indicates whether this User's last activity took place during the last timeout ms or not (used to detect outdated Users).

Parameters:
timeout - Period of time to be taken in account.
Returns:
Whether this User's last activity took place during the last timeout ms or not.

getTimestampOfLastActivity

public long getTimestampOfLastActivity()
Returns a timestamp of this User's last activity.

Returns:
Timestamp for this User's last activity.

setTimestampOfLastActivity

public void setTimestampOfLastActivity()
Must be called when User sends a Message (Used to detect inactive Users).


getEncryptCipher

public javax.crypto.Cipher getEncryptCipher()
Returns this User's encryptCipher, used to encrypt Replyies.

Returns:
This User's encryptCipher, used to encrypt Replyies.

setEncryptCipher

public void setEncryptCipher(javax.crypto.Cipher encryptCipher)
Makes this User use the bypassed Cipher for encrypting Replyies.

Parameters:
encryptCipher - Cipher, that shall be used for encrypting Replyies.

getDecryptCipher

public javax.crypto.Cipher getDecryptCipher()
Returns this User's decryptCipher, used to decrypt Requests.

Returns:
This User's decryptCipher, used to decrypt Requests.

setDecryptCipher

public void setDecryptCipher(javax.crypto.Cipher decryptCipher)
Makes this User use the bypassed Cipher for decrypting Requests

Parameters:
decryptCipher - Cipher, that shall be used for decrypting Requests

getMacKey

public javax.crypto.SecretKey getMacKey()
Returns the SecretKey, used for validating message authentication codes by this User.

Returns:
SecretKey, used for validating message authentication codes by this User.

setMacKey

public void setMacKey(javax.crypto.SecretKey newMacKey)
Makes this User use the bypassed SecretKey for validating message authentication codes.

Parameters:
newMacKey - SecretKey, that shall be used for validating message authentication codes.

getHasMessageInCurrentBatch

public boolean getHasMessageInCurrentBatch()
Returns whether a Request of this User is already in batch or not (used to prevent flooding attacks).

Returns:
Whether a Request of this User is already in batch or not (used to prevent flooding attacks).

setHasMessageInCurrentBatch

public void setHasMessageInCurrentBatch(boolean newValue)
Used to indicate, whether a Request of this User is already in batch or not (used to prevent flooding attacks).

Parameters:
newValue - Whether a Request of this User is already in batch or not.

getHasMessageInCurrentReplyBatch

public boolean getHasMessageInCurrentReplyBatch()
Returns whether a Reply of this User is already in batch or not (used to prevent flooding attacks).

Returns:
Whether a Reply of this User is already in batch or not (used to prevent flooding attacks).

setHasMessageInCurrentReplyBatch

public void setHasMessageInCurrentReplyBatch(boolean newValue)
Used to indicate, whether a Reply for this User is already in batch or not (used to prevent flooding attacks).

Parameters:
newValue - Whether a Reply for this User is already in batch or not.

getClientReadBuffer

public java.nio.ByteBuffer getClientReadBuffer()
Returns this User's ByteBuffer used for caching fragments of a message received from the corresponding Client. Needed for non-blocking I/O.

Returns:
This User's ByteBuffer used for caching fragments of a message received from the corresponding Client.

getClientWriteBuffer

public java.nio.ByteBuffer getClientWriteBuffer()
Returns this User's ByteBuffer used for caching messages that shall be sent to the corresponding Client. Needed for non-blocking I/O.

Returns:
This User's ByteBuffer used for caching messages that shall be sent to the corresponding Client.

getSocketChannel

public java.nio.channels.SocketChannel getSocketChannel()
Returns this User's SocketChannel. Needed for non-blocking I/O.

Returns:
This User's SocketChannel.

putInProxyReadBuffer

public void putInProxyReadBuffer(byte[] data)
Used to add data received from proxy server for this User. Puts the bypassed data in this User's proxyReadBuffer, from where it will be taken to generate Replyies.

Blocks until all data is written.

Parameters:
data - Data for this User, received from proxy server.

getFromProxyReadBuffer

public byte[] getFromProxyReadBuffer(int limit)
Used to read data from proxyReadBuffer, which contains data received from proxy server for this User.

Reads as much bytes as available (until limit).

Parameters:
limit - Maximum number of bytes to be returned.
Returns:
The requested data.

availableDataInProxyReadBuffer

public int availableDataInProxyReadBuffer()
Returns the number of bytes currently available in proxyReadBuffer, which contains data received from proxy server for this User.

Assures that AT LEAST @return bytes can be read from proxyReadBuffer until next call of getFromProxyReadBuffer(int).

Returns:
Number of bytes currently available in proxyReadBuffer

putInProxyWriteBuffer

public void putInProxyWriteBuffer(byte[] data)
Used to add data, that shall be sent to proxy server. Puts the bypassed data in this User's proxyWriteBuffer, from where it will be sent to the corresponding proxy server.

Blocks until all data is written.

Parameters:
data - Data, that shall be sent to proxy server.

getFromProxyWriteBuffer

public byte[] getFromProxyWriteBuffer(int limit)
Used to read data from proxyWriteBuffer, which contains data that shall be sent to the proxy server.

Reads as much bytes as available (until limit).

Parameters:
limit - Maximum number of bytes to be returned.
Returns:
The requested data.

availableDataInProxyWriteBuffer

public int availableDataInProxyWriteBuffer()
Returns the number of bytes currently available in proxyWriteBuffer, which contains data that shall be sent to the proxy server.

Assures that AT LEAST @return bytes can be read from proxyWriteBuffer until next call of getFromProxyWriteBuffer(int).

Returns:
Number of bytes currently available in proxyWriteBuffer

initializeClientBuffers

public void initializeClientBuffers(java.nio.channels.SocketChannel socketChannel)
Allocates space for the buffers used to communicate with this User's corresponding Client (needed for non-blocking I/O).

Used by first mix of cascade only.

Parameters:
socketChannel - SocketChannel to read/write data from/to.

initializeProxyBuffers

public void initializeProxyBuffers()
Allocates space for the buffers used to communicate with this User's corresponding proxy server (needed for non-blocking I/O).

Used by last mix of cascade only.


toString

public java.lang.String toString()
Returns a simple String representation of this class.

Overrides:
toString in class java.lang.Object
Returns:
A simple String representation of this class.