public class DefaultProtocolHandler extends java.lang.Object implements IProtocolHandler
Modifier and Type | Field and Description |
---|---|
private int |
m_currentState
This stores the current protocol state.
|
private boolean |
m_doCompress
This stores if we should send compressed message or not
|
private java.io.ByteArrayOutputStream |
m_incomingMessageBuffer
This buffer stores the parts of a incoming protocol message until we
received the full message.
|
private int |
m_incomingMessageLength
This stores the net length of a incoming message in the incoming message
buffer.
|
private java.io.ByteArrayInputStream |
m_outgoingMessageBuffer
This is the for outgoing protocol messages to the client.
|
private ForwardConnection |
m_parentConnection
This stores the client connection this protocol handler belongs to.
|
private java.net.Socket |
m_serverConnection
This stores the connection to the selected mixcascade.
|
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_COMPRESS_SIGNATURE
This is the start signature for a compressed protocol message.
|
private static byte[] |
MESSAGE_START_SIGNATURE
This is the start signature of every no compressed protocol message.
|
private static int |
PROTOCOL_VERSION
This is the version of the current protocol implementation.
|
private static int |
STATE_CONNECTED_TO_MIX
This is the state after we received the cascade selection from the client
and built a connection ton the selected cascade.
|
private static int |
STATE_CONNECTION_CLOSED
This is the state after the connection was closed (because of connection
termination by client or an error on the connection).
|
private static int |
STATE_WAIT_FOR_CASCADE_SELECTION
This is the state after we have gotten the connection request from a
forwarding client (not an infoservice) and sent the connection offer back
to the client.
|
private static int |
STATE_WAIT_FOR_CLIENT_REQUEST
This is the state after establishing the connection.
|
private static int |
STATE_WAIT_FOR_INFOSERVICE_CLOSE
This is the state after sending the acknowledgement for the verify
message of the infoservice.
|
Constructor and Description |
---|
DefaultProtocolHandler(ForwardConnection a_parentConnection)
Generates a new DefaultProtocolHandler.
|
Modifier and Type | Method and Description |
---|---|
int |
available()
Returns the number of bytes which are ready for sending to the client
without blocking by the next call of read().
|
private boolean |
checkSignature(byte[] a_signature1,
byte[] a_signature2)
This method checks, whether to byte arrays have identical content or not.
|
void |
close()
Closes the connection to the server and stops handling of protocol
messages.
|
private boolean |
connectTo(MixCascade a_selectedCascade)
This method tries to get a connection to a mixcascade (by probing all
ListenerInterfaces).
|
private byte[] |
createProtocolPacket(byte[] a_data)
Creates a protocol packet from byte array with data.
|
private void |
emptyBuffers()
This method sends all data in our incoming message buffer to the server.
|
private org.w3c.dom.Document |
generateConnectionAcknowledgement()
Creates an acknowledge message for the verify request of the infoservice.
|
private org.w3c.dom.Document |
generateConnectionOfferXml()
Creates the connection offer XML structure.
|
private void |
handleClientCascadeSelectMessage(org.w3c.dom.Element a_japRoutingNode)
This method handles the cascade select message from a forwarding client.
|
private void |
handleInitialRequestMessage(org.w3c.dom.Element a_japRoutingNode)
This method handles the initial request messages from a client or an
infoservice.
|
private void |
handleProtocol(org.w3c.dom.Element a_japRoutingNode)
This method handles the incoming XML messages.
|
private void |
messageHandler(byte[] a_newData)
This method handles all data packets received from the client.
|
private void |
messageReceived(byte[] a_newMessage)
This method handles and evaluates a whole message.
|
int |
read(byte[] a_buffer)
Read a_buffer.length bytes from the server in the buffer a_buffer.
|
private void |
sendProtocolDataToClient(byte[] a_data)
Put the specified data in the buffer for outgoing protocol messages to
the client.
|
void |
write(byte[] a_buffer)
Writes the bytes in a_buffer to the server or the protocol handler.
|
private byte[] |
xmlToProtocolPacket(org.w3c.dom.Document a_doc)
Creates a protocol packet from an XML structure.
|
private static final int PROTOCOL_VERSION
private static final int MAXIMUM_PROTOCOLMESSAGE_SIZE
private static final byte[] MESSAGE_START_SIGNATURE
private static final byte[] MESSAGE_START_COMPRESS_SIGNATURE
private static final byte[] MESSAGE_END_SIGNATURE
private static final int STATE_WAIT_FOR_CLIENT_REQUEST
private static final int STATE_WAIT_FOR_CASCADE_SELECTION
private static final int STATE_CONNECTED_TO_MIX
private static final int STATE_CONNECTION_CLOSED
private static final int STATE_WAIT_FOR_INFOSERVICE_CLOSE
private java.net.Socket m_serverConnection
private java.io.ByteArrayOutputStream m_incomingMessageBuffer
private int m_incomingMessageLength
private java.io.ByteArrayInputStream m_outgoingMessageBuffer
private int m_currentState
private ForwardConnection m_parentConnection
private boolean m_doCompress
public DefaultProtocolHandler(ForwardConnection a_parentConnection) throws java.lang.Exception
a_parentConnection
- This is the client connection for which we are doing the
protocol stuff.java.lang.Exception
public int available() throws java.lang.Exception
available
in interface IProtocolHandler
java.lang.Exception
public int read(byte[] a_buffer) throws java.lang.Exception
read
in interface IProtocolHandler
a_buffer
- A buffer for the read bytes.java.lang.Exception
public void write(byte[] a_buffer) throws java.lang.Exception
write
in interface IProtocolHandler
a_buffer
- A buffer with the bytes to write.java.lang.Exception
public void close()
close
in interface IProtocolHandler
private boolean checkSignature(byte[] a_signature1, byte[] a_signature2)
a_signature1
- The first byte array.a_signature2
- The second byte array.private void messageHandler(byte[] a_newData) throws java.lang.Exception
a_newData
- The data packet received from the client.java.lang.Exception
private void messageReceived(byte[] a_newMessage) throws java.lang.Exception
a_newMessage
- A whole message received from the client.java.lang.Exception
private void handleProtocol(org.w3c.dom.Element a_japRoutingNode) throws java.lang.Exception
a_japRoutingNode
- The JAPRouting node, which is the root node of every protocol
message.java.lang.Exception
private void handleInitialRequestMessage(org.w3c.dom.Element a_japRoutingNode) throws java.lang.Exception
a_japRoutingNode
- The JAPRouting node of the connection request message.java.lang.Exception
private void handleClientCascadeSelectMessage(org.w3c.dom.Element a_japRoutingNode) throws java.lang.Exception
a_japRoutingNode
- The JAPRouting node of the cascade select message.java.lang.Exception
private boolean connectTo(MixCascade a_selectedCascade)
a_selectedCascade
- The mixcascade to build a connection to.private void emptyBuffers() throws java.lang.Exception
java.lang.Exception
private org.w3c.dom.Document generateConnectionOfferXml() throws java.lang.Exception
java.lang.Exception
private org.w3c.dom.Document generateConnectionAcknowledgement() throws java.lang.Exception
java.lang.Exception
private void sendProtocolDataToClient(byte[] a_data)
a_data
- The data to put into the buffer.private byte[] xmlToProtocolPacket(org.w3c.dom.Document a_doc) throws java.lang.Exception
doc
- The XML structure which shall be transformed in a protocol
packet.java.lang.Exception
private byte[] createProtocolPacket(byte[] a_data)
a_data
- The bytes to put in the protocol packet.Copyright © 2023. All rights reserved.