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 | List of all members
CAAccountingInstance Class Reference

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

Classes

struct  t_aiqueueitem
 

Static Public Member Functions

static SINT32 init (CAFirstMix *callingMix)
 Returns a reference to the Singleton instance. More...
 
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. More...
 
static SINT32 initTableEntry (fmHashTableEntry *pHashEntry)
 This must be called whenever a JAP is connecting to init our per-user data structures. More...
 
static SINT32 handleJapPacket (fmHashTableEntry *pHashEntry, bool a_bControlMessage, bool a_bMessageToJAP)
 This should be called by the FirstMix for every incoming Jap packet. More...
 
static SINT32 isIPAddressBlocked (const UINT8 ip[4])
 Check if an IP address is temporarily blocked by the accounting instance. More...
 
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. More...
 
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. More...
 
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 More...
 
static void __commitSettlementToLoginTable (SettleEntry *entryList)
 only for internal use during the settleTransaction because no login table locks are acquired More...
 
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 More...
 
 ~CAAccountingInstance ()
 private destructor More...
 
UINT32 handleCostConfirmation (tAiAccountingInfo *pAccInfo, DOMElement *root)
 Handles a cost confirmation sent by a jap. More...
 
UINT32 handleCostConfirmation_internal (tAiAccountingInfo *pAccInfo, DOMElement *root)
 Handles a cost confirmation sent by a jap. More...
 
UINT32 handleAccountCertificate (tAiAccountingInfo *pAccInfo, DOMElement *root)
 Handles an account certificate of a newly connected Jap. More...
 
UINT32 handleAccountCertificate_internal (tAiAccountingInfo *pAccInfo, DOMElement *root)
 Handles an account certificate of a newly connected Jap. More...
 
UINT32 handleChallengeResponse (tAiAccountingInfo *pAccInfo, DOMElement *root)
 Checks the response of the challenge-response auth. More...
 
UINT32 handleChallengeResponse_internal (tAiAccountingInfo *pAccInfo, DOMElement *root)
 Handles the response to our challenge. More...
 
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 More...
 

Static Private Member Functions

static SINT32 handleJapPacket_internal (fmHashTableEntry *pHashEntry, bool a_bControlMessage, bool a_bMessageToJAP)
 Called by FirstMix for each incoming JAP packet. More...
 
static UINT64 unlockLogin (fmHashTableEntry *ownerRef)
 release login (particularly for use in error case) this function is thread-safe. More...
 
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). More...
 
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. More...
 
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. More...
 

Private Attributes

CAThreadPoolm_aiThreadPool
 reads messages from the queue and processes them More...
 
CAMutexm_pMutex
 this is for synchronizing the write access to the HashEntries More...
 
Hashtable * m_certHashCC
 
Hashtable * m_currentAccountsHashtable
 Stores the account number of all users currently logged in. More...
 
CAFirstMixm_mix
 
UINT8m_AiName
 the name of this accounting instance More...
 
UINT8m_currentCascade
 current cascade (identified by the concatenated hash values of the price certificates) More...
 
UINT8 ** m_allHashes
 The hash values of the Mixes ordered beginning with the AI Mix. More...
 
UINT32 m_allHashesLen
 
CAAccountingBIInterfacem_pPiInterface
 the interface to the database More...
 
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. More...
 
CAAccountingSettleThreadm_pSettleThread
 Signature verifying instance for BI signatures. More...
 
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. More...
 
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

◆ aiQueueItem

Constructor & Destructor Documentation

◆ CAAccountingInstance()

CAAccountingInstance::CAAccountingInstance ( CAFirstMix callingMix)
private

◆ ~CAAccountingInstance()

CAAccountingInstance::~CAAccountingInstance ( )
private

Member Function Documentation

◆ __commitSettlementToDatabase()

void CAAccountingInstance::__commitSettlementToDatabase ( SettleEntry entryList,
CAAccountingDBInterface dbInterface 
)
static

◆ __commitSettlementToLoginTable()

void CAAccountingInstance::__commitSettlementToLoginTable ( SettleEntry entryList)
static

◆ __handleSettleResult()

SettleEntry * CAAccountingInstance::__handleSettleResult ( CAXMLCostConfirmation *  pCC,
CAXMLErrorMessage pErrMsg,
CAAccountingDBInterface dbInterface,
UINT64  a_iSettlementTransactionNr 
)
static

◆ __newSettlementTransaction()

SINT32 CAAccountingInstance::__newSettlementTransaction ( UINT32 nrOfSettledCCs)
static

◆ cascadeMatchesCC()

bool CAAccountingInstance::cascadeMatchesCC ( CAXMLCostConfirmation *  pCC)
private

◆ clean()

static SINT32 CAAccountingInstance::clean ( )
static

◆ cleanupTableEntry()

SINT32 CAAccountingInstance::cleanupTableEntry ( fmHashTableEntry pHashEntry)
static

◆ finishLoginProcess()

SINT32 CAAccountingInstance::finishLoginProcess ( fmHashTableEntry pHashEntry)
static

◆ getAuthFlags()

UINT32 CAAccountingInstance::getAuthFlags ( fmHashTableEntry pHashEntry)
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().

◆ getNrOfUsers()

UINT32 CAAccountingInstance::getNrOfUsers ( )
static

◆ getPrepaidBytes()

SINT32 CAAccountingInstance::getPrepaidBytes ( tAiAccountingInfo pAccInfos)
staticprivate

◆ handleAccountCertificate()

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().

◆ handleAccountCertificate_internal()

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().

◆ handleChallengeResponse()

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().

◆ handleChallengeResponse_internal()

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(), CALibProxytest::getOptions(), CAAccountingDBInterface::getPrepaidAmount(), CACmdLnOptions::getPrepaidInterval(), 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(), CAAccountingDBInterface::releaseConnection(), 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().

◆ handleCostConfirmation()

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().

◆ handleCostConfirmation_internal()

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, CAAccountingDBInterface::getConnection(), getcurrentTimeMillis(), CALibProxytest::getOptions(), getPrepaidBytes(), CACmdLnOptions::getPrepaidInterval(), 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().

◆ handleJapPacket()

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().

◆ handleJapPacket_internal()

SINT32 CAAccountingInstance::handleJapPacket_internal ( fmHashTableEntry pHashEntry,
bool  a_bControlMessage,
bool  a_bMessageToJAP 
)
staticprivate

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(), CALibProxytest::getOptions(), getPrepaidBytes(), CACmdLnOptions::getPrepaidInterval(), 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().

◆ init()

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.

Referenced by CAFirstMix::init().

◆ initTableEntry()

SINT32 CAAccountingInstance::initTableEntry ( fmHashTableEntry pHashEntry)
static

◆ isIPAddressBlocked()

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

◆ loginProcessStatus()

SINT32 CAAccountingInstance::loginProcessStatus ( fmHashTableEntry pHashEntry)
static

◆ makeAccountRequest()

static SINT32 CAAccountingInstance::makeAccountRequest ( XERCES_CPP_NAMESPACE::DOMDocument *&  doc)
staticprivate

◆ makeCCRequest()

SINT32 CAAccountingInstance::makeCCRequest ( const UINT64  accountNumber,
const UINT64  transferredBytes,
XERCES_CPP_NAMESPACE::DOMDocument *&  doc 
)
staticprivate

◆ makeInitialCCRequest()

SINT32 CAAccountingInstance::makeInitialCCRequest ( CAXMLCostConfirmation *  pCC,
XERCES_CPP_NAMESPACE::DOMDocument *&  doc,
SINT32  prepaidBytes 
)
staticprivate

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(), m_preparedCCRequest, CAMsg::printMsg(), setDOMElementAttribute(), and setDOMElementValue().

Referenced by sendInitialCCRequest().

◆ newSettlementTransaction()

SINT32 CAAccountingInstance::newSettlementTransaction ( )
static

◆ prepareCCRequest()

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
callingMixthe 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().

◆ processJapMessage()

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().

◆ processJapMessageLoginHelper()

void CAAccountingInstance::processJapMessageLoginHelper ( fmHashTableEntry pHashEntry,
UINT32  handlerReturnvalue,
bool  finishLogin 
)
staticprivate

◆ processThread()

THREAD_RETURN CAAccountingInstance::processThread ( void *  a_param)
staticprivate

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().

◆ returnKickout()

SINT32 CAAccountingInstance::returnKickout ( tAiAccountingInfo pAccInfo)
staticprivate

◆ returnPrepareKickout()

SINT32 CAAccountingInstance::returnPrepareKickout ( tAiAccountingInfo pAccInfo,
CAXMLErrorMessage a_error 
)
staticprivate

◆ sendAILoginConfirmation()

SINT32 CAAccountingInstance::sendAILoginConfirmation ( tAiAccountingInfo pAccInfo,
const UINT32  code,
UINT8 message 
)
staticprivate

◆ sendCCRequest()

SINT32 CAAccountingInstance::sendCCRequest ( tAiAccountingInfo pAccInfo)
staticprivate

◆ sendInitialCCRequest()

SINT32 CAAccountingInstance::sendInitialCCRequest ( tAiAccountingInfo pAccInfo,
CAXMLCostConfirmation *  pCC,
SINT32  prepaidBytes 
)
staticprivate

◆ setPrepaidBytesToZero()

void CAAccountingInstance::setPrepaidBytesToZero ( tAiAccountingInfo pAccInfo)
staticprivate

◆ setPrepaidBytesToZero_internal()

void CAAccountingInstance::setPrepaidBytesToZero_internal ( tAiAccountingInfo pAccInfo)
staticprivate

◆ settlementTransaction()

SINT32 CAAccountingInstance::settlementTransaction ( )
static

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, CAAccountingDBInterface::getAccountStatus(), CAAccountingDBInterface::getConnection(), CAXMLErrorMessage::getDescription(), CAXMLErrorMessage::getErrorCode(), CAXMLErrorMessage::getMessageObject(), CAAccountingDBInterface::getPrepaidAmount(), CAAccountingDBInterface::getUnsettledCostConfirmations(), 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().

◆ unlockLogin()

UINT64 CAAccountingInstance::unlockLogin ( fmHashTableEntry ownerRef)
staticprivate

release login (particularly for use in error case) this function is thread-safe.

References t_accountinginfo::accountNumber, m_currentAccountsHashtable, ms_pInstance, t_fmhashtableentry::pAccountingInfo, and resetLoginOngoing().

Referenced by CAFirstMix::doUserLogin_internal().

Friends And Related Function Documentation

◆ CAFirstMix

friend class CAFirstMix
friend

◆ CAFirstMixA

friend class CAFirstMixA
friend

Member Data Documentation

◆ HANDLE_PACKET_CLOSE_CONNECTION

const SINT32 CAAccountingInstance::HANDLE_PACKET_CLOSE_CONNECTION = 3
static

◆ HANDLE_PACKET_CONNECTION_OK

const SINT32 CAAccountingInstance::HANDLE_PACKET_CONNECTION_OK = 1
static

◆ HANDLE_PACKET_CONNECTION_UNCHECKED

const SINT32 CAAccountingInstance::HANDLE_PACKET_CONNECTION_UNCHECKED = 4
static

◆ HANDLE_PACKET_HOLD_CONNECTION

const SINT32 CAAccountingInstance::HANDLE_PACKET_HOLD_CONNECTION = 0
static

◆ HANDLE_PACKET_PREPARE_FOR_CLOSING_CONNECTION

const SINT32 CAAccountingInstance::HANDLE_PACKET_PREPARE_FOR_CLOSING_CONNECTION = 2
static

◆ m_AiName

UINT8* CAAccountingInstance::m_AiName
private

the name of this accounting instance

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

◆ m_aiThreadPool

CAThreadPool* CAAccountingInstance::m_aiThreadPool
private

reads messages from the queue and processes them

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

◆ m_allHashes

UINT8** CAAccountingInstance::m_allHashes
private

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

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

◆ m_allHashesLen

UINT32 CAAccountingInstance::m_allHashesLen
private

◆ m_bThreadRunning

bool CAAccountingInstance::m_bThreadRunning
private

◆ m_certHashCC

Hashtable* CAAccountingInstance::m_certHashCC
private

◆ m_currentAccountsHashtable

Hashtable* CAAccountingInstance::m_currentAccountsHashtable
private

◆ m_currentCascade

UINT8* CAAccountingInstance::m_currentCascade
private

◆ m_iCurrentSettleTransactionNr

volatile UINT64 CAAccountingInstance::m_iCurrentSettleTransactionNr = 0
staticprivate

◆ m_iHardLimitBytes

UINT32 CAAccountingInstance::m_iHardLimitBytes
private

◆ m_iSoftLimitBytes

UINT32 CAAccountingInstance::m_iSoftLimitBytes
private

◆ m_mix

CAFirstMix* CAAccountingInstance::m_mix
private

◆ m_nextSettleNr

volatile UINT64 CAAccountingInstance::m_nextSettleNr
private

◆ m_pIPBlockList

CATempIPBlockList* CAAccountingInstance::m_pIPBlockList
private

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

◆ m_pMutex

CAMutex* CAAccountingInstance::m_pMutex
private

this is for synchronizing the write access to the HashEntries

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

◆ m_pPiInterface

CAAccountingBIInterface* CAAccountingInstance::m_pPiInterface
private

◆ m_prepaidBytesMinimum

SINT32 CAAccountingInstance::m_prepaidBytesMinimum = 0
staticprivate

◆ m_preparedCCRequest

XERCES_CPP_NAMESPACE::DOMDocument * CAAccountingInstance::m_preparedCCRequest
staticprivate

◆ m_pSettlementMutex

CAConditionVariable* CAAccountingInstance::m_pSettlementMutex
private

◆ m_pSettleThread

CAAccountingSettleThread* CAAccountingInstance::m_pSettleThread
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().

◆ m_seqBIConnErrors

volatile UINT32 CAAccountingInstance::m_seqBIConnErrors
private

◆ m_settleWaitNr

volatile UINT64 CAAccountingInstance::m_settleWaitNr
private

◆ MAX_SETTLED_CCS

const UINT32 CAAccountingInstance::MAX_SETTLED_CCS = 10
static

◆ MAX_TOLERATED_MULTIPLE_LOGINS

const UINT32 CAAccountingInstance::MAX_TOLERATED_MULTIPLE_LOGINS = 10
staticprivate

◆ ms_pInstance

CAAccountingInstance * CAAccountingInstance::ms_pInstance = NULL
staticprivate

◆ PACKETS_BEFORE_NEXT_CHECK

const UINT64 CAAccountingInstance::PACKETS_BEFORE_NEXT_CHECK = 100
staticprivate