message
Class Message

java.lang.Object
  extended by message.Message
All Implemented Interfaces:
java.lang.Comparable<Message>, BasicMessage
Direct Known Subclasses:
BatchSizeMessage, ChannelEstablishMessage, ChannelMessage, ChannelReleaseMessage, ReplyMessage

public abstract class Message
extends java.lang.Object
implements BasicMessage, java.lang.Comparable<Message>

Basic abstract class for all types of messages the InputOutputHandler is capable of transmitting.

Provides a byte array containing the message itself in an exchangeable form (see byteMessage) and several manipulable properties for internal usage only (e. g. by a mix or client).

Author:
Karl-Peter Fuchs

Field Summary
private  byte[] byteMessage
          Byte representation of this message.
private  User channel
          Reference on the user/channel. this message belongs to.
private  int CHANNEL_ID
          Identifier of the channel/user this message belongs to.
private static NetworkClockController clock
          Reference on component NetworkClock (used to set variable timeOfReceival).
private  int messageID
          Identifier for this message.
private  int NEXT_MIX_CHANNEL_ID
          Identifier of the channel/user this message belongs to for the next mix of the cascade.
private  int payloadLength
          Only a certain part of byteMessage must be transmitted to the cascade's next mix (Some parts (e. g. the session key for the corresponding mix) are not supposed to be sent).
private  int startIndexOfPayload
          Only a certain part of byteMessage must be transmitted to the cascade's next mix (Some parts (e. g. the session key for the corresponding mix) are not supposed to be sent).
private  long timeOfReceival
          Point of time (timestamp), this message was received by the corresponding mix.
 
Constructor Summary
Message(byte[] byteMesssage)
          Message constructor used by client.
Message(byte[] byteMesssage, User channel, int startIndexOfPayload, int payloadLength)
          Message constructor used by mix.
 
Method Summary
 int compareTo(Message message)
          Implements the Comparable interface's compareTo() method.
 byte[] getByteMessage()
          Returns the byte representation of this message (byteMessage).
 User getChannel()
          Returns a reference on the channel/user this message belongs to.
 int getChannelID()
          Returns an identifier for the channel/user this message belongs to.
 int getMessageID()
          Returns an identifier for this message.
 int getNextMixChannelID()
          Returns an identifier for the channel/user this message belongs to, used by the next mix of the cascade.
 long getTimeOfReceival()
          Returns the point of time (timestamp), this message was received.
 void setByteMessage(byte[] byteMessage)
          Sets the byte representation of this message (byteMessage) to the bypassed array.
 void setMessageID(int newIdentifier)
          Sets this message's identifier to the bypassed value.
 void setPayloadRange(int startIndexOfPayload, int payloadLength)
          Only a certain part of the message array must be transmitted to the cascade's next mix (Some parts (e. g. the session key for the corresponding mix) are not supposed to be sent).
 void setTimeOfReceival(long newTimeOfReceival)
          Sets the point of time (timestamp), this message was received to the bypassed value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHANNEL_ID

private final int CHANNEL_ID
Identifier of the channel/user this message belongs to.


NEXT_MIX_CHANNEL_ID

private final int NEXT_MIX_CHANNEL_ID
Identifier of the channel/user this message belongs to for the next mix of the cascade.


messageID

private int messageID
Identifier for this message.


clock

private static NetworkClockController clock
Reference on component NetworkClock (used to set variable timeOfReceival).

See Also:
timeOfReceival

timeOfReceival

private long timeOfReceival
Point of time (timestamp), this message was received by the corresponding mix.


startIndexOfPayload

private int startIndexOfPayload
Only a certain part of byteMessage must be transmitted to the cascade's next mix (Some parts (e. g. the session key for the corresponding mix) are not supposed to be sent). Which part is relevant depends on the type of message.

This variable defines the offset for the part to be transmitted.

This variable must/can be set automatically in the constructor of any subclass.

See Also:
payloadLength

payloadLength

private int payloadLength
Only a certain part of byteMessage must be transmitted to the cascade's next mix (Some parts (e. g. the session key for the corresponding mix) are not supposed to be sent). Which part is relevant depends on the type of message.

This variable defines the length for the part to be transmitted.

This variable must/can be set automatically in the constructor of any subclass.

See Also:
payloadLength

channel

private User channel
Reference on the user/channel. this message belongs to.


byteMessage

private byte[] byteMessage
Byte representation of this message. Contains all data that was received or shall be sent via network.

Constructor Detail

Message

public Message(byte[] byteMesssage,
               User channel,
               int startIndexOfPayload,
               int payloadLength)
Message constructor used by mix.

Constructs a new Message with the submitted content ( byteMesssage) for the bypassed user/channel.

Parameters:
byteMesssage - Byte representation of the message (as received from the client/previous mix).
channel - Reference on the user/channel this message belongs to.
startIndexOfPayload - See instance variable startIndexOfPayload.
payloadLength - See instance variable payloadLength.

Message

public Message(byte[] byteMesssage)
Message constructor used by client.

Constructs a new Message with the submitted content ( byteMesssage).

Parameters:
byteMesssage - Byte representation of the message (can be empty).
Method Detail

getNextMixChannelID

public int getNextMixChannelID()
Returns an identifier for the channel/user this message belongs to, used by the next mix of the cascade.

Specified by:
getNextMixChannelID in interface BasicMessage
Returns:
Identifier for the channel/user this message belongs to, used by the next mix of the cascade.

getChannelID

public int getChannelID()
Returns an identifier for the channel/user this message belongs to.

Specified by:
getChannelID in interface BasicMessage
Returns:
Identifier for the channel/user this message belongs to.

getMessageID

public int getMessageID()
Returns an identifier for this message.

Specified by:
getMessageID in interface BasicMessage
Returns:
Identifier for this message.

setMessageID

public void setMessageID(int newIdentifier)
Sets this message's identifier to the bypassed value.

Specified by:
setMessageID in interface BasicMessage
Parameters:
newIdentifier - Value this message's identifier shall be set to.

setPayloadRange

public void setPayloadRange(int startIndexOfPayload,
                            int payloadLength)
Only a certain part of the message array must be transmitted to the cascade's next mix (Some parts (e. g. the session key for the corresponding mix) are not supposed to be sent). Which part is relevant depends on the type of message.

This method defines the offset and length of the part to be transmitted.

Specified by:
setPayloadRange in interface BasicMessage
Parameters:
startIndexOfPayload - Offset of the part to be transmitted.
payloadLength - Length of the part to be transmitted.

getChannel

public User getChannel()
Returns a reference on the channel/user this message belongs to.

Specified by:
getChannel in interface BasicMessage
Returns:
Reference on the channel/user this message belongs to.

getTimeOfReceival

public long getTimeOfReceival()
Returns the point of time (timestamp), this message was received.

Specified by:
getTimeOfReceival in interface BasicMessage
Returns:
Point of time (timestamp), this message was received.

setTimeOfReceival

public void setTimeOfReceival(long newTimeOfReceival)
Sets the point of time (timestamp), this message was received to the bypassed value.

Specified by:
setTimeOfReceival in interface BasicMessage
Parameters:
newTimeOfReceival - Point of time (timestamp), this message was received.

getByteMessage

public byte[] getByteMessage()
Returns the byte representation of this message (byteMessage).

Specified by:
getByteMessage in interface BasicMessage
Returns:
Byte representation of this message.

setByteMessage

public void setByteMessage(byte[] byteMessage)
Sets the byte representation of this message (byteMessage) to the bypassed array.

Specified by:
setByteMessage in interface BasicMessage
Parameters:
byteMessage - New content for this message.

compareTo

public int compareTo(Message message)
Implements the Comparable interface's compareTo() method. Compares this Message with the specified Message for order (criterion: alphabetic order of this Message's payload. Returns a negative integer, zero, or a positive integer as this Message is less than, equal to, or greater than the specified Message.

Specified by:
compareTo in interface java.lang.Comparable<Message>
Parameters:
message - The Message to be compared.
Returns:
-1, 0, or 1 as this Message is less than, equal to, or greater than the specified Message .
See Also:
setPayloadRange(int, int)