infoservice.dynamic
Class DynamicCommandsExtension

java.lang.Object
  extended by infoservice.dynamic.DynamicCommandsExtension

public class DynamicCommandsExtension
extends java.lang.Object

This class provides the functionality needed by the "dynamic cascade extension". It is essentially an extension to InfoServiceCommands

Author:
LERNGRUPPE

Constructor Summary
DynamicCommandsExtension()
           
 
Method Summary
 HttpResponseStructure cascadePostHelo(byte[] a_postData, int a_encoding)
          This method is called, when we receive data from a mixcascade (first mix) or when we receive data from a remote infoservice, which posts data about a mixcascade.
private  org.w3c.dom.Document constructAnswer(java.lang.String response)
          Constructs the answer for a connectivity request.
private  java.lang.String doPing(java.net.InetAddress a_Address, int port, long echoRequest)
          Actually executes the ping-like connectivity-test.
private  int extractPort(byte[] a_postData)
          Extracts the port from the POST data.
private  java.lang.String getCascadeHtmlTable(java.lang.Class a_clazz)
           
private  MixCascade getCurrentCascade(java.lang.String a_mixId)
          Returns the current cascade for the mix with the given ID.
private  MixCascade getTemporaryCascade(java.lang.String a_mixId)
          Returns a temporary cascade for the mix with the given ID.
private  java.util.Vector getUnusedMixex()
          Returns a vector containing all unused dynamic mixes.
private  boolean haveNewCascadeInformation(java.lang.String a_strMixId)
          Tests if there exists new cascade information for the mix with the given ID.
 HttpResponseStructure isNewCascadeAvailable(java.lang.String a_strMixId)
          Checks if there exists new cascade information for the mix with the given ID.
private  boolean isReachable(java.net.InetAddress a_Address, int port)
          Checks if the given address is reachable on the given port
 HttpResponseStructure lastMixPostDynaCascade(byte[] a_postData)
          This method gets called when a last mix posts its cascade information to the InfoService Such a cascade is not yet established, so it is a temporary cascade an will be treated as such
 HttpResponseStructure mixPostConnectivityTest(java.net.InetAddress a_sourceAddress, byte[] a_postData)
          This method gets called when a mix asks the InfoService to verify its connectivity.
 HttpResponseStructure reconfigureMix(java.lang.String a_strMixId)
           
 HttpResponseStructure virtualCascadeStatus()
          Sends a generated HTML file with all status entrys to the client.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DynamicCommandsExtension

public DynamicCommandsExtension()
Method Detail

cascadePostHelo

public HttpResponseStructure cascadePostHelo(byte[] a_postData,
                                             int a_encoding)
This method is called, when we receive data from a mixcascade (first mix) or when we receive data from a remote infoservice, which posts data about a mixcascade.

Parameters:
a_postData - The data we have received.
Returns:
The HTTP response for the client.

isNewCascadeAvailable

public HttpResponseStructure isNewCascadeAvailable(java.lang.String a_strMixId)
Checks if there exists new cascade information for the mix with the given ID.

Parameters:
a_strMixId -
Returns:
HttpResponseStructure.HTTP_RETURN_INTERNAL_SERVER_ERROR if no new information is available, HttpResponseStructure.HTTP_RETURN_OK otherwise

reconfigureMix

public HttpResponseStructure reconfigureMix(java.lang.String a_strMixId)

haveNewCascadeInformation

private boolean haveNewCascadeInformation(java.lang.String a_strMixId)
Tests if there exists new cascade information for the mix with the given ID. New information should be available if 1) No current cascade is found and a temporary cascade is available 2) Current cascade is not equal to a temporary cascade

Parameters:
a_strMixId - The ID of the mix in question
Returns:
true if a new cascade is available, false otherwise

getTemporaryCascade

private MixCascade getTemporaryCascade(java.lang.String a_mixId)
Returns a temporary cascade for the mix with the given ID. Not the VirtualCascade-object, but the real MixCascade is returned

Parameters:
a_mixId - The ID of the mix in question
Returns:
A temporary MixCascade for the mix or null

getCurrentCascade

private MixCascade getCurrentCascade(java.lang.String a_mixId)
Returns the current cascade for the mix with the given ID.

Parameters:
a_mixId - The ID of the mix in question
Returns:
The current MixCascade for the mix or null

lastMixPostDynaCascade

public HttpResponseStructure lastMixPostDynaCascade(byte[] a_postData)
This method gets called when a last mix posts its cascade information to the InfoService Such a cascade is not yet established, so it is a temporary cascade an will be treated as such

Parameters:
a_postData - The data of the POST request
Returns:
HttpResponseStructure HTTP_RETURN_OK (no payload) or HTTP_RETURN_INTERNAL_SERVER_ERROR

mixPostConnectivityTest

public HttpResponseStructure mixPostConnectivityTest(java.net.InetAddress a_sourceAddress,
                                                     byte[] a_postData)
This method gets called when a mix asks the InfoService to verify its connectivity. Connectivity verification works as follows

Parameters:
a_sourceAddress - The source address of the request
a_postData - The POST data containing a XML structure with the port
Returns:
HttpResponseStructure HTTP_RETURN_OK (containing the answer XML structure) or HTTP_RETURN_INTERNAL_SERVER_ERROR

constructAnswer

private org.w3c.dom.Document constructAnswer(java.lang.String response)
Constructs the answer for a connectivity request.

Parameters:
response - Either "True" or "False"
Returns:
The XML Document containing the answer

isReachable

private boolean isReachable(java.net.InetAddress a_Address,
                            int port)
Checks if the given address is reachable on the given port

Parameters:
a_Address - The address to be tested
port - The port to be tested
Returns:
true if the address is reachable on the given port, false otherwise

doPing

private java.lang.String doPing(java.net.InetAddress a_Address,
                                int port,
                                long echoRequest)
Actually executes the ping-like connectivity-test. Sends a echoRequest to the querying mix and waits for the same token to come back from the mix

Parameters:
a_Address - The target address
port - The target port
echoRequest - The echoRequest to send
Returns:
The echoResponse from the mix

extractPort

private int extractPort(byte[] a_postData)
Extracts the port from the POST data. Creates a XML-Document and returns the value of the Port element.

Parameters:
a_postData - The POST data to parse
Returns:
The port or -1 if there was an error

virtualCascadeStatus

public HttpResponseStructure virtualCascadeStatus()
Sends a generated HTML file with all status entrys to the client. This function is not used by the JAP client. It's intended to use with a webbrowser to see the status of all cascades.

Returns:
The HTTP response for the client.

getUnusedMixex

private java.util.Vector getUnusedMixex()
Returns a vector containing all unused dynamic mixes. A dynamic mix is considered unused if it is in no cascade at all or if it is used in a cascade only containing itself

Returns:

getCascadeHtmlTable

private java.lang.String getCascadeHtmlTable(java.lang.Class a_clazz)
                                      throws java.lang.Exception
Throws:
java.lang.Exception