Mixes for Privacy and Anonymity in the Internet
Classes | Static Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | Friends
CAAccountingInstance Class Reference

This is the AI (accounting instance or abrechnungsinstanz in german) class. More...

List of all members.

Classes

struct  t_aiqueueitem

Static Public Member Functions

static SINT32 init (CAFirstMix *callingMix)
 Returns a reference to the Singleton instance.
static SINT32 clean ()
static UINT32 getAuthFlags (fmHashTableEntry *pHashEntry)
static SINT32 cleanupTableEntry (fmHashTableEntry *pHashEntry)
 This should always be called when closing a JAP connection to cleanup the data structures.
static SINT32 initTableEntry (fmHashTableEntry *pHashEntry)
 This must be called whenever a JAP is connecting to init our per-user data structures.
static SINT32 handleJapPacket (fmHashTableEntry *pHashEntry, bool a_bControlMessage, bool a_bMessageToJAP)
 This should be called by the FirstMix for every incoming Jap packet.
static SINT32 isIPAddressBlocked (const UINT8 ip[4])
 Check if an IP address is temporarily blocked by the accounting instance.
static SINT32 processJapMessage (fmHashTableEntry *pHashEntry, const XERCES_CPP_NAMESPACE::DOMDocument *a_DomDoc)
 Handle a user (xml) message sent to us by the Jap through the ControlChannel.
static UINT32 getNrOfUsers ()
static SINT32 loginProcessStatus (fmHashTableEntry *pHashEntry)
static SINT32 finishLoginProcess (fmHashTableEntry *pHashEntry)
 this method is for the corresponding CAFirstMix login thread to verify the result of the settlement.
static SINT32 settlementTransaction ()
static SettleEntry__handleSettleResult (CAXMLCostConfirmation *pCC, CAXMLErrorMessage *pErrMsg, CAAccountingDBInterface *dbInterface, UINT64 a_iSettlementTransactionNr)
static void __commitSettlementToDatabase (SettleEntry *entryList, CAAccountingDBInterface *dbInterface)
 only for internal use during the settleTransaction because the global settlement lock is not acquired
static void __commitSettlementToLoginTable (SettleEntry *entryList)
 only for internal use during the settleTransaction because no login table locks are acquired
static SINT32 newSettlementTransaction ()
static SINT32 __newSettlementTransaction (UINT32 *nrOfSettledCCs)

Static Public Attributes

static const SINT32 HANDLE_PACKET_CONNECTION_OK = 1
static const SINT32 HANDLE_PACKET_CONNECTION_UNCHECKED = 4
static const SINT32 HANDLE_PACKET_HOLD_CONNECTION = 0
static const SINT32 HANDLE_PACKET_PREPARE_FOR_CLOSING_CONNECTION = 2
static const SINT32 HANDLE_PACKET_CLOSE_CONNECTION = 3
static const UINT32 MAX_SETTLED_CCS = 10

Private Types

typedef struct t_aiqueueitem aiQueueItem

Private Member Functions

 CAAccountingInstance (CAFirstMix *callingMix)
 private Constructor
 ~CAAccountingInstance ()
 private destructor
UINT32 handleCostConfirmation (tAiAccountingInfo *pAccInfo, DOMElement *root)
 Handles a cost confirmation sent by a jap.
UINT32 handleCostConfirmation_internal (tAiAccountingInfo *pAccInfo, DOMElement *root)
 Handles a cost confirmation sent by a jap.
UINT32 handleAccountCertificate (tAiAccountingInfo *pAccInfo, DOMElement *root)
 Handles an account certificate of a newly connected Jap.
UINT32 handleAccountCertificate_internal (tAiAccountingInfo *pAccInfo, DOMElement *root)
 Handles an account certificate of a newly connected Jap.
UINT32 handleChallengeResponse (tAiAccountingInfo *pAccInfo, DOMElement *root)
 Checks the response of the challenge-response auth.
UINT32 handleChallengeResponse_internal (tAiAccountingInfo *pAccInfo, DOMElement *root)
 Handles the response to our challenge.
bool cascadeMatchesCC (CAXMLCostConfirmation *pCC)
SINT32 prepareCCRequest (CAMix *callingMix, UINT8 *a_AiName)
 creating the xml of a new CC is really the responsability of the CAXMLCostConfirmation class knowledge about the structure of a CC's XML should be encapsulated in it TODO: add constructor to that class that takes accountnumber, transferredbytes etc as params (should use a template internally into which it only inserts accNumber and bytes,to speed things up TODO: add toXMLElement method then replace manually building the xml here with contructing a CAXMLCostConfirmation and just add the xml returned by its toXMLElement method

Static Private Member Functions

static SINT32 handleJapPacket_internal (fmHashTableEntry *pHashEntry, bool a_bControlMessage, bool a_bMessageToJAP)
 Called by FirstMix for each incoming JAP packet.
static UINT64 unlockLogin (fmHashTableEntry *ownerRef)
 release login (particularly for use in error case) this function is thread-safe.
static void processJapMessageLoginHelper (fmHashTableEntry *pHashEntry, UINT32 handlerReturnvalue, bool finishLogin)
static SINT32 getPrepaidBytes (tAiAccountingInfo *pAccInfos)
static SINT32 makeInitialCCRequest (CAXMLCostConfirmation *pCC, XERCES_CPP_NAMESPACE::DOMDocument *&doc, SINT32 prepaidBytes)
 new initialCCRequest containing the last CC and the prepaid bytes (this is a replacement for sending the prepaid with the challenge which is now deprecated).
static SINT32 makeCCRequest (const UINT64 accountNumber, const UINT64 transferredBytes, XERCES_CPP_NAMESPACE::DOMDocument *&doc)
static SINT32 sendInitialCCRequest (tAiAccountingInfo *pAccInfo, CAXMLCostConfirmation *pCC, SINT32 prepaidBytes)
static SINT32 sendCCRequest (tAiAccountingInfo *pAccInfo)
static SINT32 makeAccountRequest (XERCES_CPP_NAMESPACE::DOMDocument *&doc)
static SINT32 sendAILoginConfirmation (tAiAccountingInfo *pAccInfo, const UINT32 code, UINT8 *message)
static SINT32 returnKickout (tAiAccountingInfo *pAccInfo)
 When receiving this message, the Mix should kick the user out immediately.
static SINT32 returnPrepareKickout (tAiAccountingInfo *pAccInfo, CAXMLErrorMessage *a_error)
static void setPrepaidBytesToZero (tAiAccountingInfo *pAccInfo)
static void setPrepaidBytesToZero_internal (tAiAccountingInfo *pAccInfo)
static THREAD_RETURN processThread (void *a_param)
 The main loop of the AI thread - reads messages from the queue and starts process threads for these messages.

Private Attributes

CAThreadPoolm_aiThreadPool
 reads messages from the queue and processes them
CAMutexm_pMutex
 this is for synchronizing the write access to the HashEntries
Hashtablem_certHashCC
Hashtablem_currentAccountsHashtable
 Stores the account number of all users currently logged in.
CAFirstMixm_mix
UINT8m_AiName
 the name of this accounting instance
UINT8m_currentCascade
 current cascade (identified by the concatenated hash values of the price certificates)
UINT8 ** m_allHashes
 The hash values of the Mixes ordered beginning with the AI Mix.
UINT32 m_allHashesLen
CAAccountingBIInterfacem_pPiInterface
 the interface to the database
UINT32 m_iSoftLimitBytes
UINT32 m_iHardLimitBytes
CATempIPBlockListm_pIPBlockList
 Users that get kicked out because they sent no authentication certificate get their IP appended to this list.
CAAccountingSettleThreadm_pSettleThread
 Signature verifying instance for BI signatures.
bool m_bThreadRunning
volatile UINT64 m_nextSettleNr
volatile UINT64 m_settleWaitNr
CAConditionVariablem_pSettlementMutex
volatile UINT32 m_seqBIConnErrors

Static Private Attributes

static const UINT64 PACKETS_BEFORE_NEXT_CHECK = 100
static const UINT32 MAX_TOLERATED_MULTIPLE_LOGINS = 10
static
XERCES_CPP_NAMESPACE::DOMDocument * 
m_preparedCCRequest
static CAAccountingInstancems_pInstance = NULL
 Singleton: This is the reference to the only instance of this class.
static SINT32 m_prepaidBytesMinimum = 0
static volatile UINT64 m_iCurrentSettleTransactionNr = 0

Friends

class CAFirstMixA
class CAFirstMix

Detailed Description

This is the AI (accounting instance or abrechnungsinstanz in german) class.

Its purpose is to count packets for every user and to decide wether the connection should be closed (e.g. when a user is betraying us, or simply when the account is empty and the user refuses to charge it).

It is a singleton class, only one instance exists at a time. On the first call to getInstance() the initialization is performed.


Member Typedef Documentation


Constructor & Destructor Documentation


Member Function Documentation

SettleEntry * CAAccountingInstance::__handleSettleResult ( CAXMLCostConfirmation pCC,
CAXMLErrorMessage pErrMsg,
CAAccountingDBInterface dbInterface,
UINT64  a_iSettlementTransactionNr 
) [static]
static SINT32 CAAccountingInstance::clean ( ) [static]
Returns:
the payment auth flags of the given connecttion or 0 if no auth flags are set

References t_accountinginfo::authFlags, and t_fmhashtableentry::pAccountingInfo.

Referenced by CAFirstMixA::checkUserConnections().

UINT32 CAAccountingInstance::handleAccountCertificate ( tAiAccountingInfo pAccInfo,
DOMElement *  root 
) [private]

Handles an account certificate of a newly connected Jap.

References FINISH_STACK, handleAccountCertificate_internal(), and INIT_STACK.

Referenced by processJapMessage().

UINT32 CAAccountingInstance::handleAccountCertificate_internal ( tAiAccountingInfo pAccInfo,
DOMElement *  root 
) [private]

Handles an account certificate of a newly connected Jap.

Parses accountnumber and publickey, checks the signature and generates and sends a challenge XML structure to the Jap. TODO: think about switching account without changing mixcascade (receive a new acc.cert. though we already have one)

References t_accountinginfo::accountNumber, AUTH_CHALLENGE_SENT, AUTH_DELETE_ENTRY, AUTH_FAKE, AUTH_GOT_ACCOUNTCERT, AUTH_TIMEOUT_STARTED, t_accountinginfo::authFlags, BEGIN_STACK, t_accountinginfo::challengeSentSeconds, createDOMDocument(), createDOMElement(), DOM_Output::dumpToMem(), E_SUCCESS, CABase64::encode(), CAXMLErrorMessage::ERR_BAD_REQUEST, CAXMLErrorMessage::ERR_BAD_SIGNATURE, CAXMLErrorMessage::ERR_INTERNAL_SERVER_ERROR, CAXMLErrorMessage::ERR_KEY_NOT_FOUND, CAXMLErrorMessage::ERR_NO_ERROR_GIVEN, CAXMLErrorMessage::ERR_NO_RECORD_FOUND, CAXMLErrorMessage::ERR_OK, CAXMLErrorMessage::ERR_WRONG_FORMAT, CAAccountingDBInterface::getConnection(), getcurrentTime(), getDOMChildByName(), getDOMElementValue(), CALibProxytest::getOptions(), CAAccountingDBInterface::getPrepaidAmount(), getRandom(), INIT_STACK, len, CAMutex::lock(), m_currentCascade, t_accountinginfo::mutex, t_accountinginfo::pChallenge, t_accountinginfo::pControlChannel, t_accountinginfo::pPublicKey, CAMsg::printMsg(), t_accountinginfo::pstrBIID, CAAccountingDBInterface::releaseConnection(), CAAbstractControlChannel::sendXMLMessage(), setDOMElementAttribute(), setDOMElementValue(), CASignature::setVerifyKey(), CAAbstractXMLEncodable::toXmlDocument(), CAMutex::unlock(), and CAMultiSignature::verifyXML().

Referenced by handleAccountCertificate().

UINT32 CAAccountingInstance::handleChallengeResponse ( tAiAccountingInfo pAccInfo,
DOMElement *  root 
) [private]

Checks the response of the challenge-response auth.

References FINISH_STACK, handleChallengeResponse_internal(), and INIT_STACK.

Referenced by processJapMessage().

UINT32 CAAccountingInstance::handleChallengeResponse_internal ( tAiAccountingInfo pAccInfo,
DOMElement *  root 
) [private]

Handles the response to our challenge.

Checks the validity of the response and sets the user's authFlags Also gets the last CC of the user, and sends it to the JAP accordingly.

Todo:
We need this trick so that the program does not freeze with active AI ThreadPool!!!!
Todo:
Dangerous, as this may collide with previous accounts that have been used and deleted before... There should be something like an expiration date for the account status, e.g. 1 month
Todo:
We need this trick so that the program does not freeze with active AI ThreadPool!!!!

References AccountLoginHashEntry::accountNumber, t_accountinginfo::accountNumber, AUTH_ACCOUNT_EMPTY, AUTH_ACCOUNT_OK, AUTH_BLOCKED, AUTH_CHALLENGE_SENT, AUTH_DELETE_ENTRY, AUTH_FAKE, AUTH_GOT_ACCOUNTCERT, AUTH_INVALID_ACCOUNT, AUTH_MULTIPLE_LOGIN, AUTH_WAITING_FOR_FIRST_SETTLED_CC, AccountLoginHashEntry::authFlags, t_accountinginfo::authFlags, AccountLoginHashEntry::authRemoveFlags, BEGIN_STACK, t_accountinginfo::bytesToConfirm, cascadeMatchesCC(), t_fmhashtableentry::cleanupNotifier, CLIENT_VERSION_STR_LEN, t_accountinginfo::clientVersion, AccountLoginHashEntry::confirmedBytes, t_accountinginfo::confirmedBytes, AccountLoginHashEntry::count, CABase64::decode(), E_SUCCESS, CAXMLErrorMessage::ERR_ACCOUNT_EMPTY, CAXMLErrorMessage::ERR_BAD_SIGNATURE, CAXMLErrorMessage::ERR_BLOCKED, CAXMLErrorMessage::ERR_INTERNAL_SERVER_ERROR, CAXMLErrorMessage::ERR_KEY_NOT_FOUND, CAXMLErrorMessage::ERR_MULTIPLE_LOGIN, CAXMLErrorMessage::ERR_NO_ERROR_GIVEN, CAXMLErrorMessage::ERR_NO_RECORD_FOUND, CAXMLErrorMessage::ERR_OK, CAXMLErrorMessage::ERR_WRONG_FORMAT, CAFirstMix::forceKickout(), CAAccountingDBInterface::getAccountStatus(), CAAccountingDBInterface::getConnection(), CAAccountingDBInterface::getCostConfirmation(), getDOMChildByName(), getDOMElementValue(), CAFirstMix::getLoginMutex(), Hashtable::getMutex(), CALibProxytest::getOptions(), CAAccountingDBInterface::getPrepaidAmount(), CACmdLnOptions::getPrepaidInterval(), CAXMLCostConfirmation::getTransferredBytes(), Hashtable::getValue(), CAXMLCostConfirmation::getXMLDocument(), INIT_STACK, CAMutex::lock(), AccountLoginHashEntry::loginOngoing, m_currentAccountsHashtable, m_currentCascade, m_mix, ms_pInstance, t_accountinginfo::mutex, AccountLoginHashEntry::ownerLock, AccountLoginHashEntry::ownerRef, t_accountinginfo::ownerRef, t_accountinginfo::pChallenge, t_accountinginfo::pControlChannel, t_accountinginfo::pPublicKey, PREPAID_PROTO_CLIENT_VERSION, print64(), CAMsg::printMsg(), Hashtable::put(), CAAccountingDBInterface::releaseConnection(), Hashtable::remove(), sendCCRequest(), sendInitialCCRequest(), CAAbstractControlChannel::sendXMLMessage(), testAndSetLoginOwner(), CAAbstractXMLEncodable::toXmlDocument(), t_accountinginfo::transferredBytes, CAMutex::unlock(), AccountLoginHashEntry::userID, t_accountinginfo::userID, CASignature::verifyDER(), and CAConditionVariable::wait().

Referenced by handleChallengeResponse().

UINT32 CAAccountingInstance::handleCostConfirmation ( tAiAccountingInfo pAccInfo,
DOMElement *  root 
) [private]

Handles a cost confirmation sent by a jap.

References FINISH_STACK, handleCostConfirmation_internal(), and INIT_STACK.

Referenced by processJapMessage().

UINT32 CAAccountingInstance::handleCostConfirmation_internal ( tAiAccountingInfo pAccInfo,
DOMElement *  root 
) [private]

Handles a cost confirmation sent by a jap.

References t_accountinginfo::accountNumber, AUTH_ACCOUNT_EMPTY, AUTH_ACCOUNT_OK, AUTH_DATABASE, AUTH_DELETE_ENTRY, AUTH_FAKE, AUTH_GOT_ACCOUNTCERT, AUTH_HARD_LIMIT_REACHED, AUTH_LOGIN_NOT_FINISHED, AUTH_LOGIN_SKIP_SETTLEMENT, AUTH_SENT_CC_REQUEST, AUTH_WAITING_FOR_FIRST_SETTLED_CC, t_accountinginfo::authFlags, BEGIN_STACK, t_accountinginfo::bytesToConfirm, cascadeMatchesCC(), t_accountinginfo::confirmedBytes, E_SUCCESS, E_UNKNOWN, CAXMLErrorMessage::ERR_BAD_REQUEST, CAXMLErrorMessage::ERR_BAD_SIGNATURE, CAXMLErrorMessage::ERR_INTERNAL_SERVER_ERROR, CAXMLErrorMessage::ERR_NO_ERROR_GIVEN, CAXMLErrorMessage::ERR_NO_RECORD_FOUND, CAXMLErrorMessage::ERR_OK, CAXMLErrorMessage::ERR_WRONG_DATA, CAXMLErrorMessage::ERR_WRONG_FORMAT, CAXMLCostConfirmation::getAccountNumber(), CAAccountingDBInterface::getConnection(), getcurrentTimeMillis(), CAXMLCostConfirmation::getInstance(), CAXMLCostConfirmation::getNumberOfHashes(), CALibProxytest::getOptions(), getPrepaidBytes(), CACmdLnOptions::getPrepaidInterval(), CAXMLCostConfirmation::getTransferredBytes(), INIT_STACK, t_accountinginfo::lastHardLimitSeconds, CAMutex::lock(), m_allHashesLen, m_currentCascade, m_pSettleThread, t_accountinginfo::mutex, t_accountinginfo::pControlChannel, t_accountinginfo::pPublicKey, print64(), CAMsg::printMsg(), CAAccountingDBInterface::releaseConnection(), CAAbstractControlChannel::sendXMLMessage(), CAAccountingSettleThread::settle(), CAAccountingDBInterface::storeCostConfirmation(), CAAbstractXMLEncodable::toXmlDocument(), t_accountinginfo::transferredBytes, CAMutex::unlock(), and CASignature::verifyXML().

Referenced by handleCostConfirmation().

SINT32 CAAccountingInstance::handleJapPacket ( fmHashTableEntry pHashEntry,
bool  a_bControlMessage,
bool  a_bMessageToJAP 
) [static]

This should be called by the FirstMix for every incoming Jap packet.

References FINISH_STACK, handleJapPacket_internal(), and INIT_STACK.

Referenced by CAFirstMixA::accountTrafficDownstream(), CAFirstMixA::accountTrafficUpstream(), and CAFirstMixB::loop().

SINT32 CAAccountingInstance::handleJapPacket_internal ( fmHashTableEntry pHashEntry,
bool  a_bControlMessage,
bool  a_bMessageToJAP 
) [static, private]

Called by FirstMix for each incoming JAP packet.

Determines whether the packet should be let through or not

Possible return values, and FirstMix's reaction:

Returns:
1: everything is OK, forward packet to next mix
2: we need something (cert, CC,...) from the user, hold packet and start timeout
3: fatal error, or timeout exceeded -> kick the user out

Do not make further checkings. Let the client use the remaining prepaid bytes, and then disconnect him afterwards. As the confirmedBytes are set to zero when the client connects and the account has been empty before, no other (unauthenticated) client may use these bytes.

Todo:
We need this trick so that the program does not freeze with active AI ThreadPool!!!!

References t_accountinginfo::accountNumber, AUTH_ACCOUNT_EMPTY, AUTH_BLOCKED, AUTH_DATABASE, AUTH_DELETE_ENTRY, AUTH_FATAL_ERROR, AUTH_HARD_LIMIT_REACHED, AUTH_INVALID_ACCOUNT, AUTH_LOGIN_NOT_FINISHED, AUTH_MULTIPLE_LOGIN, AUTH_OUTDATED_CC, AUTH_SENT_CC_REQUEST, AUTH_TIMEOUT_STARTED, AUTH_UNKNOWN, AUTH_WAITING_FOR_FIRST_SETTLED_CC, AccountLoginHashEntry::authFlags, t_accountinginfo::authFlags, AccountLoginHashEntry::authRemoveFlags, BEGIN_STACK, AccountLoginHashEntry::confirmedBytes, t_accountinginfo::confirmedBytes, CAXMLErrorMessage::ERR_ACCOUNT_EMPTY, CAXMLErrorMessage::ERR_BLOCKED, CAXMLErrorMessage::ERR_DATABASE_ERROR, CAXMLErrorMessage::ERR_INTERNAL_SERVER_ERROR, CAXMLErrorMessage::ERR_KEY_NOT_FOUND, CAXMLErrorMessage::ERR_MULTIPLE_LOGIN, CAXMLErrorMessage::ERR_NO_CONFIRMATION, CAAccountingDBInterface::getConnection(), CAAccountingDBInterface::getCostConfirmation(), Hashtable::getMutex(), CALibProxytest::getOptions(), getPrepaidBytes(), CACmdLnOptions::getPrepaidInterval(), Hashtable::getValue(), CAXMLCostConfirmation::getXMLDocument(), HANDLE_PACKET_CLOSE_CONNECTION, HANDLE_PACKET_CONNECTION_OK, HANDLE_PACKET_CONNECTION_UNCHECKED, HANDLE_PACKET_PREPARE_FOR_CLOSING_CONNECTION, HARD_LIMIT_TIMEOUT, INIT_STACK, t_accountinginfo::lastHardLimitSeconds, CAMutex::lock(), m_currentAccountsHashtable, m_currentCascade, m_iHardLimitBytes, m_iSoftLimitBytes, MIXPACKET_SIZE, ms_pInstance, t_accountinginfo::mutex, t_accountinginfo::ownerRef, t_fmhashtableentry::pAccountingInfo, PACKETS_BEFORE_NEXT_CHECK, t_accountinginfo::pControlChannel, print64(), CAMsg::printMsg(), CAAccountingDBInterface::releaseConnection(), returnKickout(), returnPrepareKickout(), SAVE_STACK, sendCCRequest(), CAAbstractControlChannel::sendXMLMessage(), t_accountinginfo::sessionPackets, t_accountinginfo::transferredBytes, and CAMutex::unlock().

Referenced by handleJapPacket().

static SINT32 CAAccountingInstance::init ( CAFirstMix callingMix) [static]

Returns a reference to the Singleton instance.

References CAAccountingInstance(), E_SUCCESS, MONITORING_FIRE_PAY_EVENT, and ms_pInstance.

static SINT32 CAAccountingInstance::isIPAddressBlocked ( const UINT8  ip[4]) [static]

Check if an IP address is temporarily blocked by the accounting instance.

This should be called by the FirstMix when a JAP is connecting.

Return values:
1if the given IP is blocked
0if it is not blocked
static SINT32 CAAccountingInstance::makeAccountRequest ( XERCES_CPP_NAMESPACE::DOMDocument *&  doc) [static, private]
SINT32 CAAccountingInstance::makeCCRequest ( const UINT64  accountNumber,
const UINT64  transferredBytes,
XERCES_CPP_NAMESPACE::DOMDocument *&  doc 
) [static, private]
SINT32 CAAccountingInstance::makeInitialCCRequest ( CAXMLCostConfirmation pCC,
XERCES_CPP_NAMESPACE::DOMDocument *&  doc,
SINT32  prepaidBytes 
) [static, private]

new initialCCRequest containing the last CC and the prepaid bytes (this is a replacement for sending the prepaid with the challenge which is now deprecated).

References createDOMDocument(), createDOMElement(), E_SUCCESS, E_UNKNOWN, getDOMChildByName(), CAXMLCostConfirmation::getXMLDocument(), m_preparedCCRequest, CAMsg::printMsg(), setDOMElementAttribute(), and setDOMElementValue().

Referenced by sendInitialCCRequest().

SINT32 CAAccountingInstance::prepareCCRequest ( CAMix callingMix,
UINT8 a_AiName 
) [private]

creating the xml of a new CC is really the responsability of the CAXMLCostConfirmation class knowledge about the structure of a CC's XML should be encapsulated in it TODO: add constructor to that class that takes accountnumber, transferredbytes etc as params (should use a template internally into which it only inserts accNumber and bytes,to speed things up TODO: add toXMLElement method then replace manually building the xml here with contructing a CAXMLCostConfirmation and just add the xml returned by its toXMLElement method

Parameters:
callingMix,:the Mix instance to which the AI belongs (needed to get cascadeInfo to extract the price certificates to include in cost confirmations)

References createDOMDocument(), createDOMElement(), E_SUCCESS, E_UNKNOWN, CABase64::encode(), getDOMChildByName(), getElementsByTagName(), CAMix::getMixCascadeInfo(), len, m_allHashes, m_allHashesLen, m_currentCascade, m_preparedCCRequest, DOM_Output::makeCanonical(), CAMsg::printMsg(), setDOMElementAttribute(), setDOMElementValue(), and strtrim().

Referenced by CAAccountingInstance().

SINT32 CAAccountingInstance::processJapMessage ( fmHashTableEntry pHashEntry,
const XERCES_CPP_NAMESPACE::DOMDocument *  a_DomDoc 
) [static]

Handle a user (xml) message sent to us by the Jap through the ControlChannel.

Handle a user (xml) message sent to us by the Jap.

This function determines what type of message we have and sends the appropriate handle...() function to the ai thread.

This function is running inside the AiThread. It determines what type of message we have and calls the appropriate handle...() function

Todo:
this does not work yet due to errors in CAMutex!!! if (handleFunc) { pItem = new aiQueueItem; pItem->pDomDoc = new DOM_Document(a_DomDoc); pItem->pAccInfo = pHashEntry->pAccountingInfo; pItem->handleFunc = handleFunc;

pHashEntry->pAccountingInfo->mutex->lock(); pItem->pAccInfo->nrInQueue++; ret = ms_pInstance->m_aiThreadPool->addRequest(processThread, pItem); if (ret !=E_SUCCESS) { pItem->pAccInfo->nrInQueue--; CAMsg::printMsg(LOG_CRIT, "CAAccountingInstance: Process could not add to AI thread pool!\n" ); delete pItem->pDomDoc; delete pItem; } pHashEntry->pAccountingInfo->mutex->unlock(); return ret; }

References AUTH_ACCOUNT_EMPTY, AUTH_BLOCKED, AUTH_INVALID_ACCOUNT, AUTH_LOGIN_SKIP_SETTLEMENT, t_accountinginfo::authFlags, BEGIN_STACK, E_SUCCESS, E_UNKNOWN, CAXMLErrorMessage::ERR_OK, FINISH_STACK, getPrepaidBytes(), handleAccountCertificate(), handleChallengeResponse(), handleCostConfirmation(), INIT_STACK, ms_pInstance, t_fmhashtableentry::pAccountingInfo, CAMsg::printMsg(), processJapMessageLoginHelper(), and SAVE_STACK.

Referenced by CAAccountingControlChannel::processXMLMessage().

void CAAccountingInstance::processJapMessageLoginHelper ( fmHashTableEntry pHashEntry,
UINT32  handlerReturnvalue,
bool  finishLogin 
) [static, private]
THREAD_RETURN CAAccountingInstance::processThread ( void *  a_param) [static, private]

The main loop of the AI thread - reads messages from the queue and starts process threads for these messages.

Processes JAP messages asynchronously by calls to the appropriate handlers.

References AUTH_DELETE_ENTRY, t_accountinginfo::authFlags, BEGIN_STACK, FINISH_STACK, CAAccountingInstance::t_aiqueueitem::handleFunc, INIT_STACK, CAMutex::lock(), ms_pInstance, t_accountinginfo::mutex, t_accountinginfo::nrInQueue, CAAccountingInstance::t_aiqueueitem::pAccInfo, CAAccountingInstance::t_aiqueueitem::pDomDoc, CAMsg::printMsg(), THREAD_RETURN_SUCCESS, and CAMutex::unlock().

SINT32 CAAccountingInstance::returnPrepareKickout ( tAiAccountingInfo pAccInfo,
CAXMLErrorMessage a_error 
) [static, private]
SINT32 CAAccountingInstance::sendAILoginConfirmation ( tAiAccountingInfo pAccInfo,
const UINT32  code,
UINT8 message 
) [static, private]
SINT32 CAAccountingInstance::sendInitialCCRequest ( tAiAccountingInfo pAccInfo,
CAXMLCostConfirmation pCC,
SINT32  prepaidBytes 
) [static, private]
void CAAccountingInstance::setPrepaidBytesToZero ( tAiAccountingInfo pAccInfo) [static, private]

References SettleEntry::accountNumber, AUTH_ACCOUNT_EMPTY, AUTH_BLOCKED, AUTH_INVALID_ACCOUNT, AUTH_OUTDATED_CC, AUTH_SETTLED_ONCE, AUTH_UNKNOWN, AUTH_WAITING_FOR_FIRST_SETTLED_CC, AccountLoginHashEntry::authFlags, SettleEntry::authFlags, AccountLoginHashEntry::authRemoveFlags, SettleEntry::authRemoveFlags, BEGIN_STACK, CAAccountingDBInterface::clearAccountStatus(), AccountLoginHashEntry::confirmedBytes, SettleEntry::confirmedBytes, CRITICAL_SUBSEQUENT_BI_CONN_ERRORS, CAAccountingDBInterface::deleteCC(), SettleEntry::diffBytes, E_NOT_CONNECTED, E_SUCCESS, E_UNKNOWN, CAXMLErrorMessage::ERR_ACCOUNT_EMPTY, CAXMLErrorMessage::ERR_BLOCKED, CAXMLErrorMessage::ERR_DATABASE_ERROR, CAXMLErrorMessage::ERR_INTERNAL_SERVER_ERROR, CAXMLErrorMessage::ERR_KEY_NOT_FOUND, CAXMLErrorMessage::ERR_OK, CAXMLErrorMessage::ERR_OUTDATED_CC, CAXMLErrorMessage::ERR_SUCCESS_BUT_WITH_ERRORS, FINISH_STACK, CAXMLCostConfirmation::getAccountNumber(), CAAccountingDBInterface::getAccountStatus(), CAAccountingDBInterface::getConnection(), CAXMLErrorMessage::getDescription(), CAXMLErrorMessage::getErrorCode(), CAXMLErrorMessage::getMessageObject(), Hashtable::getMutex(), CAAccountingDBInterface::getPrepaidAmount(), CAXMLCostConfirmation::getTransferredBytes(), CAAccountingDBInterface::getUnsettledCostConfirmations(), Hashtable::getValue(), INIT_STACK, CAAccountingBIInterface::initBIConnection(), CAMutex::lock(), m_currentAccountsHashtable, m_currentCascade, m_nextSettleNr, m_pPiInterface, m_pSettlementMutex, m_seqBIConnErrors, m_settleWaitNr, CAAccountingDBInterface::markAsSettled(), MAX_SETTLED_CCS, MONITORING_FIRE_PAY_EVENT, ms_pInstance, SettleEntry::nextEntry, print64(), CAMsg::printMsg(), CAAccountingDBInterface::releaseConnection(), SAVE_STACK, CAAccountingBIInterface::settle(), CAConditionVariable::signal(), CAAccountingDBInterface::storeAccountStatus(), CAAccountingDBInterface::storeCostConfirmation(), SettleEntry::storedStatus, CAAccountingDBInterface::storePrepaidAmount(), CAAccountingBIInterface::terminateBIConnection(), CAMutex::unlock(), and CAConditionVariable::wait().

UINT64 CAAccountingInstance::unlockLogin ( fmHashTableEntry ownerRef) [static, private]

Friends And Related Function Documentation

friend class CAFirstMix [friend]
friend class CAFirstMixA [friend]

Member Data Documentation

the name of this accounting instance

Referenced by CAAccountingInstance(), and ~CAAccountingInstance().

reads messages from the queue and processes them

Referenced by CAAccountingInstance(), and ~CAAccountingInstance().

The hash values of the Mixes ordered beginning with the AI Mix.

Referenced by CAAccountingInstance(), prepareCCRequest(), and ~CAAccountingInstance().

Users that get kicked out because they sent no authentication certificate get their IP appended to this list.

Connections from IP Addresses contained in this list get blocked, so that evil JAP users can't use the mix cascade without paying

this is for synchronizing the write access to the HashEntries

Referenced by CAAccountingInstance(), getNrOfUsers(), and ~CAAccountingInstance().

XERCES_CPP_NAMESPACE::DOMDocument * CAAccountingInstance::m_preparedCCRequest [static, private]

Signature verifying instance for BI signatures.

Todo:
initialize this member

this thread sends cost confirmations to the BI in regular intervals

Referenced by CAAccountingInstance(), handleCostConfirmation_internal(), and ~CAAccountingInstance().