Mixe for Privacy and Anonymity in the Internet
|
#include <CAAccountingDBInterface.hpp>
Public Member Functions | |
SINT32 | storeCostConfirmation (CAXMLCostConfirmation &cc, UINT8 *ccCascade) |
Creates the tables we need in the DB. More... | |
SINT32 | getCostConfirmation (UINT64 accountNumber, UINT8 *cascadeId, CAXMLCostConfirmation **pCC, bool &a_bSettled) |
SINT32 | getUnsettledCostConfirmations (CAXMLCostConfirmation ***resultCCs, UINT8 *cascadeId, UINT32 *nrOfCCs, UINT32 a_maxCCs) |
Fills the CAQueue with all non-settled cost confirmations. More... | |
SINT32 | markAsSettled (UINT64 accountNumber, UINT8 *cascadeId, UINT64 a_transferredBytes) |
Marks this account as settled. More... | |
SINT32 | deleteCC (UINT64 accountNumber, UINT8 *cascadeId) |
if the BI reports an error while trying to settle a CC, this will be called to delete it from the database (otherwise the AI would try forever in vain to settle the unusable CC) More... | |
SINT32 | storePrepaidAmount (UINT64 accountNumber, SINT32 prepaidBytes, UINT8 *cascadeId) |
SINT32 | getPrepaidAmount (UINT64 accountNumber, UINT8 *cascadeId, bool a_bDelete) |
SINT32 | storeAccountStatus (UINT64 a_accountNumber, UINT32 a_statusCode) |
SINT32 | getAccountStatus (UINT64 a_accountNumber, UINT32 &a_statusCode) |
SINT32 | clearAccountStatus (UINT64 a_accountNumber) |
SINT32 | checkCountAllQuery (UINT8 *a_query, UINT32 &r_count) |
Takes and executes a query that counts databae records and tests if the result is valid. More... | |
Static Public Member Functions | |
static CAAccountingDBInterface * | getConnection () |
static SINT32 | releaseConnection (CAAccountingDBInterface *dbIf) |
static SINT32 | init () |
static SINT32 | cleanup () |
Private Member Functions | |
CAAccountingDBInterface () | |
Constructor. More... | |
~CAAccountingDBInterface () | |
Destructor. More... | |
SINT32 | __storeCostConfirmation (CAXMLCostConfirmation &cc, UINT8 *ccCascade) |
stores a cost confirmation in the DB More... | |
SINT32 | __getCostConfirmation (UINT64 accountNumber, UINT8 *cascadeId, CAXMLCostConfirmation **pCC, bool &a_bSettled) |
Gets the latest cost confirmation stored for the given user account. More... | |
SINT32 | __getUnsettledCostConfirmations (CAXMLCostConfirmation ***resultCCs, UINT8 *cascadeId, UINT32 *nrOfCCs, UINT32 a_maxCCs) |
Fills the CAQueue with pointer to all non-settled cost confirmations. More... | |
SINT32 | __markAsSettled (UINT64 accountNumber, UINT8 *cascadeId, UINT64 a_transferredBytes) |
Marks this account as settled. More... | |
SINT32 | __deleteCC (UINT64 accountNumber, UINT8 *cascadeId) |
SINT32 | __storePrepaidAmount (UINT64 accountNumber, SINT32 prepaidBytes, UINT8 *cascadeId) |
SINT32 | __getPrepaidAmount (UINT64 accountNumber, UINT8 *cascadeId, bool a_bDelete) |
SINT32 | __storeAccountStatus (UINT64 a_accountNumber, UINT32 a_statusCode) |
SINT32 | __getAccountStatus (UINT64 a_accountNumber, UINT32 &a_statusCode) |
SINT32 | __clearAccountStatus (UINT64 a_accountNumber) |
SINT32 | __checkCountAllQuery (UINT8 *a_query, UINT32 &r_count) |
SINT32 | initDBConnection () |
Initiates the database connection. More... | |
SINT32 | terminateDBConnection () |
Terminates the database connection. More... | |
bool | isDBConnected () |
bool | checkConnectionStatus () |
Checks if the connection still exists and tries to reconnect if not. More... | |
bool | checkOwner () |
bool | testAndSetOwner () |
bool | testAndResetOwner () |
PGresult * | monitored_PQexec (PGconn *conn, const char *query) |
Private Attributes | |
PGconn * | m_dbConn |
connection to postgreSQL database More... | |
bool | m_bConnected |
volatile thread_id_t | m_owner |
volatile bool | m_free |
int | m_protocolVersion |
CAMutex * | m_pConnectionMutex |
Static Private Attributes | |
static CAConditionVariable * | ms_pConnectionAvailable = NULL |
static volatile UINT64 | ms_threadWaitNr = 0 |
static volatile UINT64 | ms_nextThreadNr = 0 |
static CAAccountingDBInterface * | ms_pDBConnectionPool [] |
Friends | |
class | CAAccountingInstance |
This class is used to store cost confirmations in a postgresql database
Definition at line 54 of file CAAccountingDBInterface.hpp.
|
private |
Constructor.
Definition at line 45 of file CAAccountingDBInterface.cpp.
References m_bConnected, m_dbConn, m_free, m_owner, and m_pConnectionMutex.
Referenced by init().
|
private |
Destructor.
Definition at line 62 of file CAAccountingDBInterface.cpp.
References m_pConnectionMutex, and terminateDBConnection().
Definition at line 295 of file CAAccountingDBInterface.cpp.
References E_SUCCESS, E_UNKNOWN, m_dbConn, monitored_PQexec(), and CAMsg::printMsg().
Referenced by __storeAccountStatus(), __storeCostConfirmation(), __storePrepaidAmount(), and checkCountAllQuery().
Definition at line 913 of file CAAccountingDBInterface.cpp.
References ACCOUNT_NUMBER_SIZE, E_SUCCESS, E_UNKNOWN, m_dbConn, MAX_ACCOUNTNUMBER, MIN_ACCOUNTNUMBER, monitored_PQexec(), CAMsg::printMsg(), and STMT_CLEAR_ACCOUNT_STATUS.
Referenced by clearAccountStatus().
Definition at line 596 of file CAAccountingDBInterface.cpp.
References checkConnectionStatus(), E_NOT_CONNECTED, E_SUCCESS, E_UNKNOWN, m_dbConn, monitored_PQexec(), MONITORING_FIRE_PAY_EVENT, print64(), and CAMsg::printMsg().
Referenced by deleteCC().
|
private |
Definition at line 962 of file CAAccountingDBInterface.cpp.
References checkConnectionStatus(), E_NOT_CONNECTED, E_SUCCESS, E_UNKNOWN, CAXMLErrorMessage::ERR_OK, m_dbConn, monitored_PQexec(), MONITORING_FIRE_PAY_EVENT, print64(), and CAMsg::printMsg().
Referenced by getAccountStatus().
|
private |
Gets the latest cost confirmation stored for the given user account.
accountNumber | the account for which the cost confirmation is requested |
pCC | on return contains a pointer to the Cost confirmation (the caller is responsible for deleting this object), NULL in case of an error |
E_SUCCESS,if | everything is OK |
E_NOT_CONNECTED,if | the DB query could not be executed |
E_NOT_FOUND,if | there was no XMLCC found |
E_UNKOWN | in case of a general error |
Definition at line 218 of file CAAccountingDBInterface.cpp.
References checkConnectionStatus(), E_NOT_CONNECTED, E_NOT_FOUND, E_SUCCESS, E_UNKNOWN, m_dbConn, monitored_PQexec(), MONITORING_FIRE_PAY_EVENT, print64(), and CAMsg::printMsg().
Referenced by getCostConfirmation().
|
private |
Definition at line 753 of file CAAccountingDBInterface.cpp.
References checkConnectionStatus(), E_NOT_CONNECTED, E_UNKNOWN, m_dbConn, monitored_PQexec(), MONITORING_FIRE_PAY_EVENT, print64(), and CAMsg::printMsg().
Referenced by getPrepaidAmount().
|
private |
Fills the CAQueue with pointer to all non-settled cost confirmations.
The caller is responsible for deleating this cost confirmations.
E_NOT_CONNECTED | if a connection to the DB could not be established |
E_UNKNOWN | in case of a general error |
E_SUCCESS | : database operation completed successfully (but queue might still be empty if there were no unsettled cost confirmation to find). Param: cascadeId : String identifier of a cascade for which to return the cost confirmations (concatenated hashes of all the cascade's mixes' price certs) |
Definition at line 471 of file CAAccountingDBInterface.cpp.
References checkConnectionStatus(), E_NOT_CONNECTED, E_SUCCESS, E_UNKNOWN, m_dbConn, monitored_PQexec(), MONITORING_FIRE_PAY_EVENT, and CAMsg::printMsg().
Referenced by getUnsettledCostConfirmations().
|
private |
Marks this account as settled.
E_NOT_CONNECTED | if a connection to the DB could not be established |
E_UNKNOWN | in case of a general error |
Definition at line 552 of file CAAccountingDBInterface.cpp.
References checkConnectionStatus(), E_NOT_CONNECTED, E_SUCCESS, E_UNKNOWN, m_dbConn, monitored_PQexec(), MONITORING_FIRE_PAY_EVENT, and print64().
Referenced by markAsSettled().
|
private |
Definition at line 830 of file CAAccountingDBInterface.cpp.
References __checkCountAllQuery(), checkConnectionStatus(), E_NOT_CONNECTED, E_SUCCESS, E_UNKNOWN, len, m_dbConn, max, monitored_PQexec(), MONITORING_FIRE_PAY_EVENT, print64(), and CAMsg::printMsg().
Referenced by storeAccountStatus().
|
private |
stores a cost confirmation in the DB
Definition at line 352 of file CAAccountingDBInterface.cpp.
References __checkCountAllQuery(), checkConnectionStatus(), E_NOT_CONNECTED, E_SUCCESS, E_UNKNOWN, len, m_dbConn, max, monitored_PQexec(), MONITORING_FIRE_PAY_EVENT, print64(), and CAMsg::printMsg().
Referenced by storeCostConfirmation().
|
private |
Definition at line 659 of file CAAccountingDBInterface.cpp.
References __checkCountAllQuery(), checkConnectionStatus(), E_NOT_CONNECTED, E_SUCCESS, E_UNKNOWN, len, m_dbConn, max, monitored_PQexec(), MONITORING_FIRE_PAY_EVENT, print64(), and CAMsg::printMsg().
Referenced by storePrepaidAmount().
|
private |
Checks if the connection still exists and tries to reconnect if not.
Definition at line 134 of file CAAccountingDBInterface.cpp.
References m_bConnected, m_dbConn, CAMsg::printMsg(), and terminateDBConnection().
Referenced by __deleteCC(), __getAccountStatus(), __getCostConfirmation(), __getPrepaidAmount(), __getUnsettledCostConfirmations(), __markAsSettled(), __storeAccountStatus(), __storeCostConfirmation(), __storePrepaidAmount(), getConnection(), and monitored_PQexec().
Takes and executes a query that counts databae records and tests if the result is valid.
a_query | a query that should return the count of database rows |
r_count | number of database rows; only valid if E_SUCCESS is returned |
Definition at line 283 of file CAAccountingDBInterface.cpp.
References __checkCountAllQuery(), checkOwner(), and E_UNKNOWN.
|
private |
Definition at line 182 of file CAAccountingDBInterface.cpp.
References CAThread::getSelfID(), CAMutex::lock(), m_free, m_owner, m_pConnectionMutex, and CAMutex::unlock().
Referenced by checkCountAllQuery(), clearAccountStatus(), deleteCC(), getAccountStatus(), getCostConfirmation(), getPrepaidAmount(), getUnsettledCostConfirmations(), markAsSettled(), storeAccountStatus(), storeCostConfirmation(), and storePrepaidAmount().
|
static |
Definition at line 1212 of file CAAccountingDBInterface.cpp.
References E_SUCCESS, MAX_DB_CONNECTIONS, ms_pConnectionAvailable, ms_pDBConnectionPool, CAMsg::printMsg(), and terminateDBConnection().
Referenced by CAFirstMix::clean(), and CACmdLnOptions::setAccountingDatabase().
Definition at line 901 of file CAAccountingDBInterface.cpp.
References __clearAccountStatus(), checkOwner(), and E_UNKNOWN.
Referenced by CAAccountingInstance::__commitSettlementToDatabase(), and CAAccountingInstance::settlementTransaction().
if the BI reports an error while trying to settle a CC, this will be called to delete it from the database (otherwise the AI would try forever in vain to settle the unusable CC)
Definition at line 584 of file CAAccountingDBInterface.cpp.
References __deleteCC(), checkOwner(), and E_UNKNOWN.
Referenced by CAAccountingInstance::__handleSettleResult(), and CAAccountingInstance::settlementTransaction().
Definition at line 947 of file CAAccountingDBInterface.cpp.
References __getAccountStatus(), checkOwner(), and E_UNKNOWN.
Referenced by CAAccountingInstance::__handleSettleResult(), CAAccountingInstance::finishLoginProcess(), CAAccountingInstance::handleChallengeResponse_internal(), and CAAccountingInstance::settlementTransaction().
|
static |
Definition at line 1020 of file CAAccountingDBInterface.cpp.
References checkConnectionStatus(), E_SUCCESS, initDBConnection(), CAMutex::lock(), MAX_DB_CONNECTIONS, MONITORING_FIRE_PAY_EVENT, ms_nextThreadNr, ms_pConnectionAvailable, ms_pDBConnectionPool, ms_threadWaitNr, CAMsg::printMsg(), testAndSetOwner(), CAMutex::unlock(), and CAConditionVariable::wait().
Referenced by CAAccountingInstance::__newSettlementTransaction(), CAAccountingInstance::cleanupTableEntry(), CAAccountingInstance::finishLoginProcess(), CAAccountingInstance::handleAccountCertificate_internal(), CAAccountingInstance::handleChallengeResponse_internal(), CAAccountingInstance::handleCostConfirmation_internal(), CAAccountingInstance::handleJapPacket_internal(), and CAAccountingInstance::settlementTransaction().
SINT32 CAAccountingDBInterface::getCostConfirmation | ( | UINT64 | accountNumber, |
UINT8 * | cascadeId, | ||
CAXMLCostConfirmation ** | pCC, | ||
bool & | a_bSettled | ||
) |
Definition at line 195 of file CAAccountingDBInterface.cpp.
References __getCostConfirmation(), checkOwner(), and E_UNKNOWN.
Referenced by CAAccountingInstance::handleChallengeResponse_internal(), and CAAccountingInstance::handleJapPacket_internal().
SINT32 CAAccountingDBInterface::getPrepaidAmount | ( | UINT64 | accountNumber, |
UINT8 * | cascadeId, | ||
bool | a_bDelete | ||
) |
Definition at line 736 of file CAAccountingDBInterface.cpp.
References __getPrepaidAmount(), checkOwner(), and E_UNKNOWN.
Referenced by CAAccountingInstance::__commitSettlementToDatabase(), CAAccountingInstance::handleAccountCertificate_internal(), CAAccountingInstance::handleChallengeResponse_internal(), and CAAccountingInstance::settlementTransaction().
SINT32 CAAccountingDBInterface::getUnsettledCostConfirmations | ( | CAXMLCostConfirmation *** | resultCCs, |
UINT8 * | cascadeId, | ||
UINT32 * | nrOfCCs, | ||
UINT32 | a_maxCCs | ||
) |
Fills the CAQueue with all non-settled cost confirmations.
Definition at line 452 of file CAAccountingDBInterface.cpp.
References __getUnsettledCostConfirmations(), checkOwner(), and E_UNKNOWN.
Referenced by CAAccountingInstance::__newSettlementTransaction(), and CAAccountingInstance::settlementTransaction().
|
static |
Definition at line 1174 of file CAAccountingDBInterface.cpp.
References CAAccountingDBInterface(), E_SUCCESS, E_UNKNOWN, initDBConnection(), MAX_DB_CONNECTIONS, ms_nextThreadNr, ms_pConnectionAvailable, ms_pDBConnectionPool, ms_threadWaitNr, and CAMsg::printMsg().
Referenced by CAFirstMix::init(), and CACmdLnOptions::setAccountingDatabase().
|
private |
Initiates the database connection.
This function is called inside the aiThread
Definition at line 78 of file CAAccountingDBInterface.cpp.
References E_NOT_CONNECTED, E_SUCCESS, E_UNKNOWN, CACmdLnOptions::getDatabasePort(), CALibProxytest::getOptions(), m_bConnected, m_dbConn, and CAMsg::printMsg().
Referenced by getConnection(), and init().
|
private |
Definition at line 161 of file CAAccountingDBInterface.cpp.
References m_bConnected.
SINT32 CAAccountingDBInterface::markAsSettled | ( | UINT64 | accountNumber, |
UINT8 * | cascadeId, | ||
UINT64 | a_transferredBytes | ||
) |
Marks this account as settled.
Definition at line 535 of file CAAccountingDBInterface.cpp.
References __markAsSettled(), checkOwner(), and E_UNKNOWN.
Referenced by CAAccountingInstance::__handleSettleResult(), and CAAccountingInstance::settlementTransaction().
|
private |
Definition at line 1246 of file CAAccountingDBInterface.cpp.
References checkConnectionStatus(), and MONITORING_FIRE_PAY_EVENT.
Referenced by __checkCountAllQuery(), __clearAccountStatus(), __deleteCC(), __getAccountStatus(), __getCostConfirmation(), __getPrepaidAmount(), __getUnsettledCostConfirmations(), __markAsSettled(), __storeAccountStatus(), __storeCostConfirmation(), and __storePrepaidAmount().
|
static |
Definition at line 1104 of file CAAccountingDBInterface.cpp.
References CAConditionVariable::broadcast(), E_SUCCESS, E_UNKNOWN, CAMutex::lock(), m_pConnectionMutex, ms_nextThreadNr, ms_pConnectionAvailable, ms_threadWaitNr, CAMsg::printMsg(), testAndResetOwner(), and CAMutex::unlock().
Referenced by CAAccountingInstance::__newSettlementTransaction(), CAAccountingInstance::cleanupTableEntry(), CAAccountingInstance::finishLoginProcess(), CAAccountingInstance::handleAccountCertificate_internal(), CAAccountingInstance::handleChallengeResponse_internal(), CAAccountingInstance::handleCostConfirmation_internal(), CAAccountingInstance::handleJapPacket_internal(), and CAAccountingInstance::settlementTransaction().
Definition at line 816 of file CAAccountingDBInterface.cpp.
References __storeAccountStatus(), checkOwner(), and E_UNKNOWN.
Referenced by CAAccountingInstance::__handleSettleResult(), and CAAccountingInstance::settlementTransaction().
SINT32 CAAccountingDBInterface::storeCostConfirmation | ( | CAXMLCostConfirmation & | cc, |
UINT8 * | ccCascade | ||
) |
Creates the tables we need in the DB.
Definition at line 337 of file CAAccountingDBInterface.cpp.
References __storeCostConfirmation(), checkOwner(), and E_UNKNOWN.
Referenced by CAAccountingInstance::__handleSettleResult(), CAAccountingInstance::handleCostConfirmation_internal(), and CAAccountingInstance::settlementTransaction().
SINT32 CAAccountingDBInterface::storePrepaidAmount | ( | UINT64 | accountNumber, |
SINT32 | prepaidBytes, | ||
UINT8 * | cascadeId | ||
) |
Definition at line 645 of file CAAccountingDBInterface.cpp.
References __storePrepaidAmount(), checkOwner(), and E_UNKNOWN.
Referenced by CAAccountingInstance::__commitSettlementToDatabase(), CAAccountingInstance::cleanupTableEntry(), and CAAccountingInstance::settlementTransaction().
|
private |
Terminates the database connection.
Definition at line 170 of file CAAccountingDBInterface.cpp.
References E_SUCCESS, m_bConnected, and m_dbConn.
Referenced by checkConnectionStatus(), cleanup(), and ~CAAccountingDBInterface().
|
private |
Definition at line 1160 of file CAAccountingDBInterface.cpp.
References CAThread::getSelfID(), CAMutex::lock(), m_free, m_owner, m_pConnectionMutex, and CAMutex::unlock().
Referenced by releaseConnection().
|
private |
Definition at line 1146 of file CAAccountingDBInterface.cpp.
References CAThread::getSelfID(), CAMutex::lock(), m_free, m_owner, m_pConnectionMutex, and CAMutex::unlock().
Referenced by getConnection().
|
friend |
Definition at line 169 of file CAAccountingDBInterface.hpp.
|
private |
Definition at line 188 of file CAAccountingDBInterface.hpp.
Referenced by CAAccountingDBInterface(), checkConnectionStatus(), initDBConnection(), isDBConnected(), and terminateDBConnection().
|
private |
connection to postgreSQL database
Definition at line 187 of file CAAccountingDBInterface.hpp.
Referenced by __checkCountAllQuery(), __clearAccountStatus(), __deleteCC(), __getAccountStatus(), __getCostConfirmation(), __getPrepaidAmount(), __getUnsettledCostConfirmations(), __markAsSettled(), __storeAccountStatus(), __storeCostConfirmation(), __storePrepaidAmount(), CAAccountingDBInterface(), checkConnectionStatus(), initDBConnection(), and terminateDBConnection().
|
private |
Definition at line 195 of file CAAccountingDBInterface.hpp.
Referenced by CAAccountingDBInterface(), checkOwner(), testAndResetOwner(), and testAndSetOwner().
|
private |
Definition at line 191 of file CAAccountingDBInterface.hpp.
Referenced by CAAccountingDBInterface(), checkOwner(), testAndResetOwner(), and testAndSetOwner().
|
private |
Definition at line 201 of file CAAccountingDBInterface.hpp.
Referenced by CAAccountingDBInterface(), checkOwner(), releaseConnection(), testAndResetOwner(), testAndSetOwner(), and ~CAAccountingDBInterface().
|
private |
Definition at line 196 of file CAAccountingDBInterface.hpp.
|
staticprivate |
Definition at line 210 of file CAAccountingDBInterface.hpp.
Referenced by getConnection(), init(), and releaseConnection().
|
staticprivate |
Definition at line 204 of file CAAccountingDBInterface.hpp.
Referenced by cleanup(), getConnection(), init(), and releaseConnection().
|
staticprivate |
Definition at line 212 of file CAAccountingDBInterface.hpp.
Referenced by cleanup(), getConnection(), and init().
|
staticprivate |
Definition at line 208 of file CAAccountingDBInterface.hpp.
Referenced by getConnection(), init(), and releaseConnection().