anon.pay
Class AIControlChannel

java.lang.Object
  extended by anon.client.AbstractChannel
      extended by anon.client.AbstractControlChannel
          extended by anon.client.StreamedControlChannel
              extended by anon.client.XmlControlChannel
                  extended by anon.pay.AIControlChannel

public class AIControlChannel
extends XmlControlChannel

This control channel is used for communication with the AI (AccountingInstance or Abrechnungsinstanz in German) which lives in the first mix. The AI sends a request when it wants a cost confirmation from us. This thread waits for incoming requests and sends the requested confirmations to the AI.

Version:
1.0
Author:
Bastian Voigt, Tobias Bayer, Rolf Wendolsky

Nested Class Summary
private  class AIControlChannel.EmptyAccountPacketObserver
           
 
Field Summary
static long AI_LOGIN_TIMEOUT
           
private static int FIRST_MIX
           
private  java.util.Vector m_aiListeners
           
private  int m_aiLogin_timeout
           
private  java.util.Vector m_aiLoginSyncObject
           
private  boolean m_bEmptyMessageSent
           
private  boolean m_bMultiplexerClosed
           
private  boolean m_bPrepaidReceived
           
private  MixCascade m_connectedCascade
           
private  XMLEasyCC m_initialCC
           
private  java.util.Observer m_packetCountEmptyObserver
           
private  PacketCounter m_packetCounter
           
private  boolean m_prepaidAmountInPayRequest
          indicates that the prepaid Bytes are transmitted by a PayRequest instead of a challenge.
private  long m_prepaidBytes
           
private  boolean m_synchronizedAILogin
          indicates that the login to a mix cascade is synchronized.
private static long m_totalBytes
           
static long MAX_PREPAID_INTERVAL
           
static long MIN_PREPAID_INTERVAL
           
private static java.lang.String PREPAID_AMOUNT_IN_PAY_REQ_MIXVERSION
           
static boolean REVERT_PRE_PREPAID
           
private static java.lang.String SYNCH_AI_LOGIN_MIXVERSION
           
 
Fields inherited from class anon.client.AbstractChannel
m_parentMultiplexer
 
Constructor Summary
AIControlChannel(Multiplexer a_multiplexer, PacketCounter a_packetCounter, IServiceContainer a_serviceContainer, MixCascade a_connectedCascade)
           
 
Method Summary
 void addAIListener(IAIEventListener a_aiListener)
           
static long getBytes()
           
private  void handlePrepaidBytesReceived(int prepaidBytes, PayAccount activeAccount)
           
 boolean isPrepaidAmountInPayRequest()
           
 void multiplexerClosed()
          This method is called on every channel in the channel-table after the multiplexer is closed.
private  void processCcToSign(XMLEasyCC cc)
          processCcToSign: to be called by processPayRequest (only the initial, old CC is sent as a naked XMLEasyCC, new CCs to sign are sent inside a XMLPayRequest)
private  void processChallenge(XMLChallenge chal)
          processChallenge
private  void processErrorMessage(XMLErrorMessage msg)
          processErrorMessage
private  void processInitialCC(XMLEasyCC a_cc)
          processInitialCC: last step of connecting to a pay cascade: take last CC as sent by AI as base value for future CCs Also, send a CC for (bytes in last CC + prepay interval of cascade) to avoid triggering the cascade's hardlimit by starting to transfer bytes without prepaying
private  void processPayRequest(XMLPayRequest request)
          process a XMLPayRequest message, which might request a XMLAccountCertificate, request a XMLBalance, or contain a XMLEasyCC which the AI asks the JAP to sign
 void processXmlMessage(org.w3c.dom.Document docMsg)
          proccessXMLMessage - this is called when a new request is coming in.
 int sendAccountCert()
           
 void setAILoginTimeout(int aiLogin_timeout)
           
 void setPrepaidAmountInPayRequest(boolean prepaidAmountInPayRequest)
           
private  void updateBalance(PayAccount currentAccount, boolean a_bSynchronous)
           
 
Methods inherited from class anon.client.XmlControlChannel
processMessage, sendXmlMessage
 
Methods inherited from class anon.client.StreamedControlChannel
processPacketData, sendByteMessage
 
Methods inherited from class anon.client.AbstractControlChannel
getServiceContainer, processReceivedPacket, sendRawMessage
 
Methods inherited from class anon.client.AbstractChannel
createEmptyMixPacket, deleteChannel, isClosed, sendPacket
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_PREPAID_INTERVAL

public static final long MAX_PREPAID_INTERVAL
See Also:
Constant Field Values

MIN_PREPAID_INTERVAL

public static final long MIN_PREPAID_INTERVAL
See Also:
Constant Field Values

AI_LOGIN_TIMEOUT

public static final long AI_LOGIN_TIMEOUT
See Also:
Constant Field Values

FIRST_MIX

private static final int FIRST_MIX
See Also:
Constant Field Values

SYNCH_AI_LOGIN_MIXVERSION

private static final java.lang.String SYNCH_AI_LOGIN_MIXVERSION
See Also:
Constant Field Values

PREPAID_AMOUNT_IN_PAY_REQ_MIXVERSION

private static final java.lang.String PREPAID_AMOUNT_IN_PAY_REQ_MIXVERSION
See Also:
Constant Field Values

REVERT_PRE_PREPAID

public static final boolean REVERT_PRE_PREPAID
See Also:
Constant Field Values

m_aiLogin_timeout

private int m_aiLogin_timeout

m_totalBytes

private static long m_totalBytes

m_bPrepaidReceived

private boolean m_bPrepaidReceived

m_prepaidBytes

private long m_prepaidBytes

m_bMultiplexerClosed

private boolean m_bMultiplexerClosed

m_aiListeners

private java.util.Vector m_aiListeners

m_packetCounter

private PacketCounter m_packetCounter

m_packetCountEmptyObserver

private java.util.Observer m_packetCountEmptyObserver

m_bEmptyMessageSent

private boolean m_bEmptyMessageSent

m_connectedCascade

private MixCascade m_connectedCascade

m_initialCC

private XMLEasyCC m_initialCC

m_aiLoginSyncObject

private java.util.Vector m_aiLoginSyncObject

m_synchronizedAILogin

private volatile boolean m_synchronizedAILogin
indicates that the login to a mix cascade is synchronized. (supported by mixes of version >= 00.07.20 )


m_prepaidAmountInPayRequest

private boolean m_prepaidAmountInPayRequest
indicates that the prepaid Bytes are transmitted by a PayRequest instead of a challenge. (supported by mixes of version >= 08.42 )

Constructor Detail

AIControlChannel

public AIControlChannel(Multiplexer a_multiplexer,
                        PacketCounter a_packetCounter,
                        IServiceContainer a_serviceContainer,
                        MixCascade a_connectedCascade)
Method Detail

addAIListener

public void addAIListener(IAIEventListener a_aiListener)

processXmlMessage

public void processXmlMessage(org.w3c.dom.Document docMsg)
proccessXMLMessage - this is called when a new request is coming in.

Specified by:
processXmlMessage in class XmlControlChannel
Parameters:
docMsg - Document

handlePrepaidBytesReceived

private void handlePrepaidBytesReceived(int prepaidBytes,
                                        PayAccount activeAccount)

processChallenge

private void processChallenge(XMLChallenge chal)
                       throws java.lang.Exception
processChallenge

Parameters:
xMLChallenge - XMLChallenge
Throws:
java.lang.Exception

processErrorMessage

private void processErrorMessage(XMLErrorMessage msg)
processErrorMessage

Parameters:
msg - XMLErrorMessage

processPayRequest

private void processPayRequest(XMLPayRequest request)
process a XMLPayRequest message, which might request a XMLAccountCertificate, request a XMLBalance, or contain a XMLEasyCC which the AI asks the JAP to sign

Parameters:
request - XMLPayRequest

updateBalance

private void updateBalance(PayAccount currentAccount,
                           boolean a_bSynchronous)

processCcToSign

private void processCcToSign(XMLEasyCC cc)
                      throws java.lang.Exception
processCcToSign: to be called by processPayRequest (only the initial, old CC is sent as a naked XMLEasyCC, new CCs to sign are sent inside a XMLPayRequest)

Throws:
java.lang.Exception

sendAccountCert

public int sendAccountCert()

getBytes

public static long getBytes()

processInitialCC

private void processInitialCC(XMLEasyCC a_cc)
processInitialCC: last step of connecting to a pay cascade: take last CC as sent by AI as base value for future CCs Also, send a CC for (bytes in last CC + prepay interval of cascade) to avoid triggering the cascade's hardlimit by starting to transfer bytes without prepaying

Parameters:
a_cc - XMLEasyCC: the last CC that the JAP sent to this Cascade, as returned from the AI

multiplexerClosed

public void multiplexerClosed()
Description copied from class: AbstractChannel
This method is called on every channel in the channel-table after the multiplexer is closed. Children of AbstractChannel should overwrite this method. It's not necessary to delete the channel from the channel-table but maybe there are some other tasks to do.

Overrides:
multiplexerClosed in class AbstractChannel

setAILoginTimeout

public void setAILoginTimeout(int aiLogin_timeout)

isPrepaidAmountInPayRequest

public boolean isPrepaidAmountInPayRequest()

setPrepaidAmountInPayRequest

public void setPrepaidAmountInPayRequest(boolean prepaidAmountInPayRequest)