|
Mixes for Privacy and Anonymity in the Internet
|
Public Member Functions | |
| SINT32 | storeCostConfirmation (CAXMLCostConfirmation &cc, UINT8 *ccCascade) |
| Creates the tables we need in the DB. | |
| 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. | |
| SINT32 | markAsSettled (UINT64 accountNumber, UINT8 *cascadeId, UINT64 a_transferredBytes) |
| Marks this account as settled. | |
| 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) | |
| 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. | |
Static Public Member Functions | |
| static CAAccountingDBInterface * | getConnection () |
| static SINT32 | releaseConnection (CAAccountingDBInterface *dbIf) |
| static SINT32 | init () |
| static SINT32 | cleanup () |
Private Member Functions | |
| CAAccountingDBInterface () | |
| Constructor. | |
| ~CAAccountingDBInterface () | |
| Destructor. | |
| SINT32 | __storeCostConfirmation (CAXMLCostConfirmation &cc, UINT8 *ccCascade) |
| stores a cost confirmation in the DB | |
| SINT32 | __getCostConfirmation (UINT64 accountNumber, UINT8 *cascadeId, CAXMLCostConfirmation **pCC, bool &a_bSettled) |
| Gets the latest cost confirmation stored for the given user account. | |
| SINT32 | __getUnsettledCostConfirmations (CAXMLCostConfirmation ***resultCCs, UINT8 *cascadeId, UINT32 *nrOfCCs, UINT32 a_maxCCs) |
| Fills the CAQueue with pointer to all non-settled cost confirmations. | |
| SINT32 | __markAsSettled (UINT64 accountNumber, UINT8 *cascadeId, UINT64 a_transferredBytes) |
| Marks this account as settled. | |
| 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. | |
| SINT32 | terminateDBConnection () |
| Terminates the database connection. | |
| bool | isDBConnected () |
| bool | checkConnectionStatus () |
| Checks if the connection still exists and tries to reconnect if not. | |
| bool | checkOwner () |
| bool | testAndSetOwner () |
| bool | testAndResetOwner () |
| PGresult * | monitored_PQexec (PGconn *conn, const char *query) |
Private Attributes | |
| PGconn * | m_dbConn |
| connection to postgreSQL database | |
| 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
| CAAccountingDBInterface::CAAccountingDBInterface | ( | ) | [private] |
Constructor.
References m_bConnected, m_dbConn, m_free, m_owner, and m_pConnectionMutex.
Referenced by init().
| CAAccountingDBInterface::~CAAccountingDBInterface | ( | ) | [private] |
Destructor.
References m_pConnectionMutex, and terminateDBConnection().
| SINT32 CAAccountingDBInterface::__checkCountAllQuery | ( | UINT8 * | a_query, |
| UINT32 & | r_count | ||
| ) | [private] |
References E_SUCCESS, E_UNKNOWN, m_dbConn, monitored_PQexec(), and CAMsg::printMsg().
Referenced by __storeAccountStatus(), __storeCostConfirmation(), __storePrepaidAmount(), and checkCountAllQuery().
| SINT32 CAAccountingDBInterface::__clearAccountStatus | ( | UINT64 | a_accountNumber | ) | [private] |
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().
| SINT32 CAAccountingDBInterface::__deleteCC | ( | UINT64 | accountNumber, |
| UINT8 * | cascadeId | ||
| ) | [private] |
References checkConnectionStatus(), E_NOT_CONNECTED, E_SUCCESS, E_UNKNOWN, m_dbConn, monitored_PQexec(), MONITORING_FIRE_PAY_EVENT, print64(), and CAMsg::printMsg().
Referenced by deleteCC().
| SINT32 CAAccountingDBInterface::__getAccountStatus | ( | UINT64 | a_accountNumber, |
| UINT32 & | a_statusCode | ||
| ) | [private] |
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().
| SINT32 CAAccountingDBInterface::__getCostConfirmation | ( | UINT64 | accountNumber, |
| UINT8 * | cascadeId, | ||
| CAXMLCostConfirmation ** | pCC, | ||
| bool & | a_bSettled | ||
| ) | [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 |
References checkConnectionStatus(), E_NOT_CONNECTED, E_NOT_FOUND, E_SUCCESS, E_UNKNOWN, CAXMLCostConfirmation::getInstance(), m_dbConn, monitored_PQexec(), MONITORING_FIRE_PAY_EVENT, print64(), and CAMsg::printMsg().
Referenced by getCostConfirmation().
| SINT32 CAAccountingDBInterface::__getPrepaidAmount | ( | UINT64 | accountNumber, |
| UINT8 * | cascadeId, | ||
| bool | a_bDelete | ||
| ) | [private] |
References checkConnectionStatus(), E_NOT_CONNECTED, E_UNKNOWN, m_dbConn, monitored_PQexec(), MONITORING_FIRE_PAY_EVENT, print64(), and CAMsg::printMsg().
Referenced by getPrepaidAmount().
| SINT32 CAAccountingDBInterface::__getUnsettledCostConfirmations | ( | CAXMLCostConfirmation *** | resultCCs, |
| UINT8 * | cascadeId, | ||
| UINT32 * | nrOfCCs, | ||
| UINT32 | a_maxCCs | ||
| ) | [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) |
References checkConnectionStatus(), E_NOT_CONNECTED, E_SUCCESS, E_UNKNOWN, CAXMLCostConfirmation::getInstance(), m_dbConn, monitored_PQexec(), MONITORING_FIRE_PAY_EVENT, and CAMsg::printMsg().
Referenced by getUnsettledCostConfirmations().
| SINT32 CAAccountingDBInterface::__markAsSettled | ( | UINT64 | accountNumber, |
| UINT8 * | cascadeId, | ||
| UINT64 | a_transferredBytes | ||
| ) | [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 |
References checkConnectionStatus(), E_NOT_CONNECTED, E_SUCCESS, E_UNKNOWN, m_dbConn, monitored_PQexec(), MONITORING_FIRE_PAY_EVENT, and print64().
Referenced by markAsSettled().
| SINT32 CAAccountingDBInterface::__storeAccountStatus | ( | UINT64 | a_accountNumber, |
| UINT32 | a_statusCode | ||
| ) | [private] |
References __checkCountAllQuery(), checkConnectionStatus(), E_NOT_CONNECTED, E_SUCCESS, E_UNKNOWN, len, m_dbConn, monitored_PQexec(), MONITORING_FIRE_PAY_EVENT, print64(), and CAMsg::printMsg().
Referenced by storeAccountStatus().
| SINT32 CAAccountingDBInterface::__storeCostConfirmation | ( | CAXMLCostConfirmation & | cc, |
| UINT8 * | ccCascade | ||
| ) | [private] |
stores a cost confirmation in the DB
References __checkCountAllQuery(), checkConnectionStatus(), E_NOT_CONNECTED, E_SUCCESS, E_UNKNOWN, CAXMLCostConfirmation::getAccountNumber(), CAXMLCostConfirmation::getTransferredBytes(), len, m_dbConn, monitored_PQexec(), MONITORING_FIRE_PAY_EVENT, print64(), CAMsg::printMsg(), and CAXMLCostConfirmation::toXMLString().
Referenced by storeCostConfirmation().
| SINT32 CAAccountingDBInterface::__storePrepaidAmount | ( | UINT64 | accountNumber, |
| SINT32 | prepaidBytes, | ||
| UINT8 * | cascadeId | ||
| ) | [private] |
References __checkCountAllQuery(), checkConnectionStatus(), E_NOT_CONNECTED, E_SUCCESS, E_UNKNOWN, len, m_dbConn, monitored_PQexec(), MONITORING_FIRE_PAY_EVENT, print64(), and CAMsg::printMsg().
Referenced by storePrepaidAmount().
| bool CAAccountingDBInterface::checkConnectionStatus | ( | ) | [private] |
Checks if the connection still exists and tries to reconnect if not.
References m_bConnected, m_dbConn, CAMsg::printMsg(), and terminateDBConnection().
Referenced by __deleteCC(), __getAccountStatus(), __getCostConfirmation(), __getPrepaidAmount(), __getUnsettledCostConfirmations(), __markAsSettled(), __storeAccountStatus(), __storeCostConfirmation(), __storePrepaidAmount(), getConnection(), and monitored_PQexec().
| SINT32 CAAccountingDBInterface::checkCountAllQuery | ( | UINT8 * | a_query, |
| UINT32 & | r_count | ||
| ) |
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 |
References __checkCountAllQuery(), checkOwner(), and E_UNKNOWN.
| bool CAAccountingDBInterface::checkOwner | ( | ) | [private] |
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().
| SINT32 CAAccountingDBInterface::cleanup | ( | ) | [static] |
| SINT32 CAAccountingDBInterface::clearAccountStatus | ( | UINT64 | a_accountNumber | ) |
References __clearAccountStatus(), checkOwner(), and E_UNKNOWN.
Referenced by CAAccountingInstance::__commitSettlementToDatabase(), and CAAccountingInstance::settlementTransaction().
| SINT32 CAAccountingDBInterface::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)
References __deleteCC(), checkOwner(), and E_UNKNOWN.
Referenced by CAAccountingInstance::__handleSettleResult(), and CAAccountingInstance::settlementTransaction().
| SINT32 CAAccountingDBInterface::getAccountStatus | ( | UINT64 | a_accountNumber, |
| UINT32 & | a_statusCode | ||
| ) |
| CAAccountingDBInterface * CAAccountingDBInterface::getConnection | ( | ) | [static] |
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 | ||
| ) |
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 | ||
| ) |
| SINT32 CAAccountingDBInterface::getUnsettledCostConfirmations | ( | CAXMLCostConfirmation *** | resultCCs, |
| UINT8 * | cascadeId, | ||
| UINT32 * | nrOfCCs, | ||
| UINT32 | a_maxCCs | ||
| ) |
Fills the CAQueue with all non-settled cost confirmations.
References __getUnsettledCostConfirmations(), checkOwner(), and E_UNKNOWN.
Referenced by CAAccountingInstance::__newSettlementTransaction(), and CAAccountingInstance::settlementTransaction().
| SINT32 CAAccountingDBInterface::init | ( | ) | [static] |
| SINT32 CAAccountingDBInterface::initDBConnection | ( | ) | [private] |
Initiates the database connection.
This function is called inside the aiThread
References E_NOT_CONNECTED, E_SUCCESS, E_UNKNOWN, CACmdLnOptions::getDatabasePort(), CALibProxytest::getOptions(), m_bConnected, m_dbConn, and CAMsg::printMsg().
Referenced by getConnection(), and init().
| bool CAAccountingDBInterface::isDBConnected | ( | ) | [private] |
References m_bConnected.
| SINT32 CAAccountingDBInterface::markAsSettled | ( | UINT64 | accountNumber, |
| UINT8 * | cascadeId, | ||
| UINT64 | a_transferredBytes | ||
| ) |
Marks this account as settled.
References __markAsSettled(), checkOwner(), and E_UNKNOWN.
Referenced by CAAccountingInstance::__handleSettleResult(), and CAAccountingInstance::settlementTransaction().
| PGresult * CAAccountingDBInterface::monitored_PQexec | ( | PGconn * | conn, |
| const char * | query | ||
| ) | [private] |
References checkConnectionStatus(), and MONITORING_FIRE_PAY_EVENT.
Referenced by __checkCountAllQuery(), __clearAccountStatus(), __deleteCC(), __getAccountStatus(), __getCostConfirmation(), __getPrepaidAmount(), __getUnsettledCostConfirmations(), __markAsSettled(), __storeAccountStatus(), __storeCostConfirmation(), and __storePrepaidAmount().
| SINT32 CAAccountingDBInterface::releaseConnection | ( | CAAccountingDBInterface * | dbIf | ) | [static] |
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().
| SINT32 CAAccountingDBInterface::storeAccountStatus | ( | UINT64 | a_accountNumber, |
| UINT32 | a_statusCode | ||
| ) |
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.
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 | ||
| ) |
| SINT32 CAAccountingDBInterface::terminateDBConnection | ( | ) | [private] |
Terminates the database connection.
References E_SUCCESS, m_bConnected, and m_dbConn.
Referenced by checkConnectionStatus(), cleanup(), and ~CAAccountingDBInterface().
| bool CAAccountingDBInterface::testAndResetOwner | ( | ) | [private] |
References CAThread::getSelfID(), CAMutex::lock(), m_free, m_owner, m_pConnectionMutex, and CAMutex::unlock().
Referenced by releaseConnection().
| bool CAAccountingDBInterface::testAndSetOwner | ( | ) | [private] |
References CAThread::getSelfID(), CAMutex::lock(), m_free, m_owner, m_pConnectionMutex, and CAMutex::unlock().
Referenced by getConnection().
friend class CAAccountingInstance [friend] |
bool CAAccountingDBInterface::m_bConnected [private] |
Referenced by CAAccountingDBInterface(), checkConnectionStatus(), initDBConnection(), isDBConnected(), and terminateDBConnection().
PGconn* CAAccountingDBInterface::m_dbConn [private] |
connection to postgreSQL database
Referenced by __checkCountAllQuery(), __clearAccountStatus(), __deleteCC(), __getAccountStatus(), __getCostConfirmation(), __getPrepaidAmount(), __getUnsettledCostConfirmations(), __markAsSettled(), __storeAccountStatus(), __storeCostConfirmation(), __storePrepaidAmount(), CAAccountingDBInterface(), checkConnectionStatus(), initDBConnection(), and terminateDBConnection().
volatile bool CAAccountingDBInterface::m_free [private] |
Referenced by CAAccountingDBInterface(), checkOwner(), testAndResetOwner(), and testAndSetOwner().
volatile thread_id_t CAAccountingDBInterface::m_owner [private] |
Referenced by CAAccountingDBInterface(), checkOwner(), testAndResetOwner(), and testAndSetOwner().
int CAAccountingDBInterface::m_protocolVersion [private] |
volatile UINT64 CAAccountingDBInterface::ms_nextThreadNr = 0 [static, private] |
Referenced by getConnection(), init(), and releaseConnection().
CAConditionVariable * CAAccountingDBInterface::ms_pConnectionAvailable = NULL [static, private] |
Referenced by cleanup(), getConnection(), init(), and releaseConnection().
CAAccountingDBInterface * CAAccountingDBInterface::ms_pDBConnectionPool [static, private] |
Referenced by cleanup(), getConnection(), and init().
volatile UINT64 CAAccountingDBInterface::ms_threadWaitNr = 0 [static, private] |
Referenced by getConnection(), init(), and releaseConnection().
1.7.6.1