Mixes for Privacy and Anonymity in the Internet
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Static Private Attributes | Friends
CAFirstMix Class Reference
Inheritance diagram for CAFirstMix:
CAMixWithReplayDB CAMix CAFirstMixA CAFirstMixB

List of all members.

Public Member Functions

 CAFirstMix ()
virtual ~CAFirstMix ()
tMixType getType () const
bool forceKickout (fmHashTableEntry *pHashTableEntry, const XERCES_CPP_NAMESPACE::DOMDocument *pErrDoc=NULL)
CAMutexgetLoginMutex ()
SINT32 connectToNextMix (CASocketAddr *a_pAddrNext)
SINT32 getMixedPackets (UINT64 &ppackets)
UINT32 getNrOfUsers ()
SINT32 getLevel (SINT32 *puser, SINT32 *prisk, SINT32 *ptraffic)
TermsAndConditionsgetTermsAndConditions (const UINT8 *opSki)
DOMNode * getTermsAndConditionsTemplate (UINT8 *templateRefID)
SINT32 getMixCount ()
tMixParametersgetMixParameters ()
 Returns the ordered list of the mix parameters from the first mix to the last mix.
SINT32 setMixParameters (const tMixParameters &params)
 Sets the parameters for the mix specified in the params.m_strMixID field.
SINT32 handleKeyInfoExtensions (DOMElement *root)
SINT32 handleTermsAndConditionsExtension (DOMElement *extensionRoot)

Public Attributes

UINT64 m_u64LastTimestampReceived

Protected Member Functions

virtual SINT32 loop ()=0
bool isShuttingDown ()
SINT32 init ()
SINT32 clean ()
virtual SINT32 initOnce ()
virtual SINT32 processKeyExchange ()
SINT32 initMixParameters (DOMElement *elemMixes)
 Initialises the MixParameters info for each mix form the <Mixes> element received from the second mix.
SINT32 incUsers (LP_fmHashTableEntry pHashEntry)
SINT32 decUsers (LP_fmHashTableEntry pHashEntry)
SINT32 incMixedPackets ()
SINT32 doUserLogin (CAMuxSocket *pNewUSer, UINT8 perrIP[4])
SINT32 reconfigure ()
SINT32 deleteCountryStats ()

Protected Attributes

CAIPListm_pIPList
CATempIPBlockListm_pIPBlockList
CAQueuem_pQueueSendToMix
CAQueuem_pQueueReadFromMix
CAFirstMixChannelListm_pChannelList
volatile UINT32 m_nUser
UINT32 m_nSocketsIn
volatile bool m_bRestart
CASocket ** m_arrSocketsIn
UINT32 m_u32MixCount
tMixParametersm_arMixParameters
CASocketGroupEpollm_psocketgroupUsersRead
CASocketGroupEpollm_psocketgroupUsersWrite
CAMuxSocketm_pMuxOut
UINT8m_xmlKeyInfoBuff
UINT16 m_xmlKeyInfoSize
XERCES_CPP_NAMESPACE::DOMDocument * m_docMixCascadeInfo
UINT64 m_nMixedPackets
CAASymCipherm_pRSA
CAMutexm_pmutexUser
CAMutexm_pmutexMixedPackets
CAMutexm_pmutexLoginThreads
CAThreadm_pthreadAcceptUsers
CAThreadPoolm_pthreadsLogin
CAThreadm_pthreadSendToMix
CAThreadm_pthreadReadFromMix
UINT32 m_nrOfTermsAndConditionsDefs
TermsAndConditions ** m_tnCDefs
UINT32 m_nrOfTermsAndConditionsTemplates
DOMNode ** m_tcTemplates
XERCES_CPP_NAMESPACE::DOMDocument * m_templatesOwner
const XMLCh * TNC_REQUEST
const XMLCh * TNC_CONFIRM
const XMLCh * TNC_INTERRUPT
tUINT32withLockm_PacketsPerCountryIN
tUINT32withLockm_PacketsPerCountryOUT
bool m_bIsShuttingDown
volatile bool m_bRunLog
CAMutexm_pmutexLogin

Private Member Functions

SINT32 initCountryStats (char *db_host, char *db_user, char *db_passwd)
SINT32 updateCountryStats (const UINT8 ip[4], UINT32 a_countryID, bool bRemove)
 Update the statisitics of the countries users come from.
SINT32 sendReplayTimestampRequestsToAllMixes ()
SINT32 doUserLogin_internal (CAMuxSocket *pNewUSer, UINT8 perrIP[4])
 Sends and receives all data neccessary for a User to "login".
SINT32 isAllowedToPassRestrictions (CASocket *pNewMuxSocket)
termsAndConditionMixAnswer_thandleTermsAndConditionsLogin (XERCES_CPP_NAMESPACE::DOMDocument *request)
void incNewConnections ()
void decNewConnections ()

Private Attributes

volatile bool m_bRunLogCountries
volatile UINT32m_CountryStats
CAThreadm_threadLogLoop
MYSQL * m_mysqlCon
volatile UINT32 m_newConnections
CAMutexm_pmutexNewConnections

Static Private Attributes

static const UINT32 MAX_CONCURRENT_NEW_CONNECTIONS = NUM_LOGIN_WORKER_TRHEADS * 2

Friends

THREAD_RETURN fm_loopSendToMix (void *)
 How to end this thread: 0.
THREAD_RETURN fm_loopReadFromMix (void *)
THREAD_RETURN fm_loopAcceptUsers (void *)
THREAD_RETURN fm_loopReadFromUsers (void *)
THREAD_RETURN fm_loopDoUserLogin (void *param)
THREAD_RETURN iplist_loopDoLogCountries (void *param)
THREAD_RETURN fm_loopLog (void *)

Constructor & Destructor Documentation

virtual CAFirstMix::~CAFirstMix ( ) [virtual]

Member Function Documentation

SINT32 CAFirstMix::clean ( ) [protected, virtual]
void CAFirstMix::decNewConnections ( ) [private]
SINT32 CAFirstMix::decUsers ( LP_fmHashTableEntry  pHashEntry) [protected]
SINT32 CAFirstMix::doUserLogin ( CAMuxSocket pNewUSer,
UINT8  perrIP[4] 
) [protected]
SINT32 CAFirstMix::doUserLogin_internal ( CAMuxSocket pNewUser,
UINT8  peerIP[4] 
) [private]

Sends and receives all data neccessary for a User to "login".

This means sending the public key of the Mixes and receiving the sym keys of JAP. This is done in a thread on a per user basis

Todo:
Cleanup of runing thread if mix restarts...

TODO: move to the if-statement above

References CASocketGroupEpoll::add(), CAFirstMixChannelList::add(), AI_LOGIN_SO_TIMEOUT, AUTH_LOGIN_FAILED, AUTH_LOGIN_NOT_FINISHED, AUTH_LOGIN_SKIP_SETTLEMENT, AUTH_WAITING_FOR_FIRST_SETTLED_CC, BEGIN_STACK, t_MixPacket::channel, cleanupTnCMixAnswer(), t_fmhashtableentry::countryID, createDOMDocument(), createDOMElement(), CABase64::decode(), decryptXMLElement(), DOM_Output::dumpToMem(), E_SOCKETCLOSED, E_SUCCESS, E_TIMEDOUT, E_UNKNOWN, CABase64::encode(), equals(), CAAccountingInstance::finishLoginProcess(), FIRST_MIX_RECEIVE_SYM_KEY_FROM_JAP_TIME_OUT, CAQueue::get(), CAFirstMixChannelList::get(), GET_NET_ERROR, GET_NET_ERROR_STR, CAMuxSocket::getCASocket(), getDOMChildByName(), getDOMElementValue(), getMixCount(), CACmdLnOptions::getMixId(), CALibProxytest::getOptions(), CAQueue::getSize(), handleTermsAndConditionsLogin(), t_fmhashtableentry::id, incUsers(), INIT_STACK, CATempIPBlockList::insertIP(), CASocket::isClosed(), CAAccountingInstance::loginProcessStatus(), m_arMixParameters, m_pChannelList, m_pIPBlockList, m_pIPList, CAMix::m_pMultiSignature, CAMixWithReplayDB::m_pReplayMsgProc, m_pRSA, m_psocketgroupUsersRead, m_psocketgroupUsersWrite, m_u64LastTimestampReceived, CAMixWithReplayDB::m_u64ReferenceTime, m_xmlKeyInfoBuff, m_xmlKeyInfoSize, MIXPACKET_SIZE, CAAccountingInstance::newSettlementTransaction(), parseDOMDocument(), t_fmhashtableentry::pControlChannelDispatcher, t_fmhashtableentry::pControlMessageQueue, T_UserLoginData::pNewUser, CAMuxSocket::prepareForSend(), CAMsg::printMsg(), CAControlChannelDispatcher::proccessMixPacket(), t_fmhashtableentry::pSymCipher, CAFirstMixChannelList::pushTimeoutEntry(), CAMuxSocket::receive(), CASocket::receiveFullyT(), CAControlChannelDispatcher::registerControlChannel(), CAFirstMixChannelList::remove(), CAIPList::removeIP(), REPLAY_BASE, termsAndConditionMixAnswer_t::result, SAVE_STACK, CASocket::sendFullyTimeOut(), SET_NET_ERROR, CAMuxSocket::setCrypt(), setDOMElementAttribute(), setDOMElementValue(), CASymCipher::setIVs(), CASocket::setKeepAlive(), CASymCipher::setKey(), CASocket::setNonBlocking(), CAMuxSocket::setReceiveKey(), CAMuxSocket::setSendKey(), CAMultiSignature::sign(), strerror(), TC_FAILED, TC_UNFINISHED, CAAccountingInstance::unlockLogin(), and termsAndConditionMixAnswer_t::xmlAnswer.

Referenced by doUserLogin().

bool CAFirstMix::forceKickout ( fmHashTableEntry pHashTableEntry,
const XERCES_CPP_NAMESPACE::DOMDocument *  pErrDoc = NULL 
)
SINT32 CAFirstMix::getLevel ( SINT32 puser,
SINT32 prisk,
SINT32 ptraffic 
)

References E_SUCCESS, and getNrOfUsers().

References m_u32MixCount.

Referenced by doUserLogin_internal().

References E_SUCCESS, m_nMixedPackets, and set64().

Returns the ordered list of the mix parameters from the first mix to the last mix.

References m_arMixParameters.

References m_nUser.

Referenced by fm_loopAcceptUsers(), and getLevel().

DOMNode * CAFirstMix::getTermsAndConditionsTemplate ( UINT8 templateRefID)
tMixType CAFirstMix::getType ( ) const [virtual]

Implements CAMix.

References CAMix::FIRST_MIX.

SINT32 CAFirstMix::handleTermsAndConditionsExtension ( DOMElement *  extensionRoot)
termsAndConditionMixAnswer_t * CAFirstMix::handleTermsAndConditionsLogin ( XERCES_CPP_NAMESPACE::DOMDocument *  request) [private]
void CAFirstMix::incNewConnections ( ) [private]
SINT32 CAFirstMix::incUsers ( LP_fmHashTableEntry  pHashEntry) [protected]
SINT32 CAFirstMix::init ( ) [protected, virtual]

Connect to the next mix

Implements CAMix.

References CATargetInterface::cleanAddr(), connectToNextMix(), CASocket::create(), createDOMDocument(), CACmdLnOptions::createSockets(), E_SHUTDOWN, E_SUCCESS, E_UNKNOWN, ev_net_keyExchangeNextSuccessful, ev_net_nextConnected, ev_net_nextConnectionClosed, fm_loopAcceptUsers, fm_loopReadFromMix, fm_loopSendToMix, FM_PACKET_STATS_LOG_INTERVALL, GET_NET_ERROR_STR, CATargetInterface::getAddr(), CAMuxSocket::getCASocket(), CACmdLnOptions::getCountryStatsDBConnectionLoginData(), CALibProxytest::getOptions(), CASocket::getRecvBuff(), CASocket::getSendBuff(), CACmdLnOptions::getTargetInterface(), CACmdLnOptions::getTargetInterfaceCount(), CATargetInterface::getTargetType(), CASocketAddr::getType(), CAAccountingDBInterface::init(), initCountryStats(), isShuttingDown(), m_arrSocketsIn, m_bRestart, m_nMixedPackets, m_nSocketsIn, m_pChannelList, m_pIPBlockList, m_pIPList, m_pMuxOut, CAMix::m_pMuxOutControlChannelDispatcher, m_pQueueReadFromMix, m_pQueueSendToMix, CAMixWithReplayDB::m_pReplayDB, CAMixWithReplayDB::m_pReplayMsgProc, m_psocketgroupUsersRead, m_psocketgroupUsersWrite, m_pthreadAcceptUsers, m_pthreadReadFromMix, m_pthreadSendToMix, m_pthreadsLogin, m_templatesOwner, m_u64LastTimestampReceived, CAMixWithReplayDB::m_u64ReferenceTime, MAX_LOGIN_QUEUE, MIXPACKET_SIZE, MONITORING_FIRE_NET_EVENT, NUM_LOGIN_WORKER_TRHEADS, CAMsg::printMsg(), processKeyExchange(), CASocket::setKeepAlive(), CAThread::setMainLoop(), CASocket::setRecvBuff(), CASocket::setSendBuff(), CADatabase::start(), CAThread::start(), and TARGET_MIX.

SINT32 CAFirstMix::initCountryStats ( char *  db_host,
char *  db_user,
char *  db_passwd 
) [private]
SINT32 CAFirstMix::initMixParameters ( DOMElement *  elemMixes) [protected]

Initialises the MixParameters info for each mix form the <Mixes> element received from the second mix.

set u32MixCount and m_arMixParameters from the <Mixes> element received from the second mix.

References E_SUCCESS, getDOMElementAttribute(), getElementsByTagName(), CACmdLnOptions::getMixId(), CALibProxytest::getOptions(), len, m_arMixParameters, t_mix_parameters::m_strMixID, and m_u32MixCount.

Referenced by processKeyExchange().

SINT32 CAFirstMix::initOnce ( ) [protected, virtual]
bool CAFirstMix::isShuttingDown ( ) [protected]

References m_bIsShuttingDown.

Referenced by init().

virtual SINT32 CAFirstMix::loop ( ) [protected, pure virtual]

Implements CAMix.

Implemented in CAFirstMixA, and CAFirstMixB.

SINT32 CAFirstMix::processKeyExchange ( ) [protected, virtual]

Getting the KeepAlive Traffic...

initialises MixParameters struct

Implements CAMix.

References CAMix::addMixInfo(), CAMix::appendCompatibilityInfo(), CAMix::appendTermsAndConditionsExtension(), CAMix::checkCompatibility(), createDOMDocument(), createDOMElement(), CABase64::decode(), DOM_Output::dumpToMem(), E_SUCCESS, E_UNKNOWN, CABase64::encode(), encodeXMLEncryptedKey(), equals(), CAASymCipher::generateKeyPair(), GET_NET_ERROR, GET_NET_ERROR_STR, CAMuxSocket::getCASocket(), getDOMChildByName(), getDOMElementAttribute(), getDOMElementValue(), CACmdLnOptions::getKeepAliveRecvInterval(), CACmdLnOptions::getKeepAliveSendInterval(), CACmdLnOptions::getNextMixTestCertificate(), CALibProxytest::getOptions(), CAASymCipher::getPublicKeyAsDOMElement(), getRandom(), getTermsAndConditions(), CACmdLnOptions::getTrustedCertificateStore(), handleKeyInfoExtensions(), CAMix::initMixCascadeInfo(), initMixParameters(), len, CAMix::m_pMultiSignature, m_pMuxOut, m_pRSA, CAMix::m_u32KeepAliveRecvInterval, CAMix::m_u32KeepAliveSendInterval, m_xmlKeyInfoBuff, m_xmlKeyInfoSize, MIX_CASCADE_PROTOCOL_VERSION, parseDOMDocument(), PAYMENT_VERSION, CAMsg::printMsg(), readFile(), CAMuxSocket::receiveFully(), saveFile(), CASocket::send(), CAMuxSocket::setCrypt(), setDOMElementAttribute(), setDOMElementValue(), CACmdLnOptions::setNextMixTestCertificate(), CAASymCipher::setPublicKeyAsDOMNode(), CAMuxSocket::setReceiveKey(), CAMuxSocket::setSendKey(), CAMultiSignature::signXML(), CAMix::signXML(), CAMix::termsAndConditionsInfoNode(), CAMix::TIMEOUT_MIX_CONNECTION_ESTABLISHEMENT, CACertStore::verifyMixCert(), CACmdLnOptions::verifyMixCertificates(), and CAMultiSignature::verifyXML().

Referenced by init().

SINT32 CAFirstMix::reconfigure ( ) [protected, virtual]

Sets the parameters for the mix specified in the params.m_strMixID field.

Only the values which are set are copied to the stored parameters of the mixes of this cascade.

References E_SUCCESS, m_arMixParameters, t_mix_parameters::m_strMixID, m_u32MixCount, t_mix_parameters::m_u32ReplayBase, t_mix_parameters::m_u32ReplayOffset, and m_u64LastTimestampReceived.

Referenced by CAReplayCtrlChannelMsgProc::proccessGotTimestamp().

SINT32 CAFirstMix::updateCountryStats ( const UINT8  ip[4],
UINT32  a_countryID,
bool  bRemove 
) [private]

Update the statisitics of the countries users come from.

The dependency between the argumenst is as follow:

Parameters:
bRemoveif true the number of users of a given country is decreased, if false it is increased
a_countryIDthe country the user comes from. Must be set if bRemove==true. If bRemove==false and ip==NULL, than if also must be set to the country the user comes from. In case ip!=NULL if holdes the default country id, if no country for the ip could be found
ipthe ip the user comes from. this ip is looked up in the databse to find the corresponding country. it is only used if bRemove==false. If no country for that ip could be found a_countryID is used as default value
Returns:
the countryID which was asigned to the user. This may be the default value a_countryID, if no country could be found.

References m_CountryStats, m_mysqlCon, NR_OF_COUNTRIES, and CAMsg::printMsg().

Referenced by decUsers(), and incUsers().


Friends And Related Function Documentation

THREAD_RETURN fm_loopAcceptUsers ( void *  ) [friend]

Referenced by init().

THREAD_RETURN fm_loopDoUserLogin ( void *  param) [friend]
THREAD_RETURN fm_loopLog ( void *  ) [friend]

Referenced by CAFirstMixA::loop().

THREAD_RETURN fm_loopReadFromMix ( void *  ) [friend]

Referenced by init().

THREAD_RETURN fm_loopReadFromUsers ( void *  ) [friend]
THREAD_RETURN fm_loopSendToMix ( void *  ) [friend]

How to end this thread: 0.

set bRestart=true; 1. Close connection to next mix 2. put some bytes (len>MIX_PACKET_SIZE) in the Mix-Output-Queue

Referenced by init().

THREAD_RETURN iplist_loopDoLogCountries ( void *  param) [friend]

Referenced by initCountryStats().


Member Data Documentation

volatile bool CAFirstMix::m_bRestart [protected]
volatile bool CAFirstMix::m_bRunLog [protected]
volatile bool CAFirstMix::m_bRunLogCountries [private]
volatile UINT32* CAFirstMix::m_CountryStats [private]
XERCES_CPP_NAMESPACE::DOMDocument* CAFirstMix::m_docMixCascadeInfo [protected]

Reimplemented from CAMix.

Referenced by CAFirstMix(), and clean().

MYSQL* CAFirstMix::m_mysqlCon [private]
volatile UINT32 CAFirstMix::m_nUser [protected]

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

DOMNode** CAFirstMix::m_tcTemplates [protected]
XERCES_CPP_NAMESPACE::DOMDocument* CAFirstMix::m_templatesOwner [protected]

Referenced by fm_loopAcceptUsers().

const XMLCh* CAFirstMix::TNC_CONFIRM [protected]
const XMLCh* CAFirstMix::TNC_INTERRUPT [protected]
const XMLCh* CAFirstMix::TNC_REQUEST [protected]