|
Mixe for Privacy and Anonymity in the Internet
|
#include <CAReplayCtrlChannelMsgProc.hpp>
Public Member Functions | |
| CAReplayCtrlChannelMsgProc (const CAMixWithReplayDB *pMix) | |
| Initialises the replay control channel messages processor with the necessary information. | |
| ~CAReplayCtrlChannelMsgProc () | |
| SINT32 | propagateCurrentReplayTimestamp () |
| Propagates downstream the current replay timestamp. | |
| SINT32 | startTimeStampPorpagation (UINT32 minutesPropagationIntervall) |
| Sends the current replay timestamp periodically on the downstream replay control channel. | |
| SINT32 | stopTimeStampPorpagation () |
| Stops the timestamp propagation. | |
| SINT32 | proccessGetTimestamp (const CAReplayControlChannel *pReceiver, const UINT8 *strMixID) const |
| Proccesses a getTimeStamps request on a reply control channel. | |
| SINT32 | proccessGotTimestamp (const CAReplayControlChannel *pReceiver, const UINT8 *strMixID, const UINT32 offset) const |
| Proccesses a received replay timestamp rt from mix strMixID. | |
| SINT32 | sendGetTimestamp (const UINT8 *strMixID) |
| Sends upstram a request for the replay timestamp for the given mix. | |
Private Member Functions | |
| SINT32 | initTimestampsMessageTemplate () |
| We initialise the template used to generate the idividual responses to gettimestamps requests according to the mix ids of the cascade. | |
Private Attributes | |
| const CAMixWithReplayDB * | m_pMix |
| CAReplayControlChannel * | m_pDownstreamReplayControlChannel |
| CAReplayControlChannel * | m_pUpstreamReplayControlChannel |
| UINT32 | m_u32PropagationInterval |
| CAThread * | m_pThreadTimestampPropagation |
| volatile bool | m_bRun |
| XERCES_CPP_NAMESPACE::DOMDocument * | m_docTemplate |
Friends | |
| THREAD_RETURN | rp_loopPropagateTimestamp (void *param) |
Definition at line 37 of file CAReplayCtrlChannelMsgProc.hpp.
Initialises the replay control channel messages processor with the necessary information.
Definition at line 39 of file CAReplayCtrlChannelMsgProc.cpp.
References CAMix::getDownstreamControlChannelDispatcher(), CAMix::getUpstreamControlChannelDispatcher(), initTimestampsMessageTemplate(), m_docTemplate, m_pDownstreamReplayControlChannel, m_pMix, m_pThreadTimestampPropagation, m_pUpstreamReplayControlChannel, pMix, CAMsg::printMsg(), and CAControlChannelDispatcher::registerControlChannel().
{
CAMsg::printMsg(LOG_DEBUG,"CAReplayCtrlChannelMsgProc - constructor - this=%p\n",this);
m_pDownstreamReplayControlChannel=NULL;
m_pUpstreamReplayControlChannel=NULL;
m_pThreadTimestampPropagation=NULL;
m_pMix=pMix;
m_docTemplate=NULL;
initTimestampsMessageTemplate();
CAControlChannelDispatcher* pDispatcher=m_pMix->getDownstreamControlChannelDispatcher();
if(pDispatcher!=NULL)
{
#ifdef DEBUG
CAMsg::printMsg(LOG_DEBUG,"CAReplayCtrlChannelMsgProc - constructor - registering downstream replay control channel\n",this);
#endif
m_pDownstreamReplayControlChannel=new CAReplayControlChannel(this);
CAMsg::printMsg(LOG_DEBUG,"m_pDownstreamReplayControlChannel= %p\n",m_pDownstreamReplayControlChannel);
pDispatcher->registerControlChannel(m_pDownstreamReplayControlChannel);
}
pDispatcher=m_pMix->getUpstreamControlChannelDispatcher();
if(pDispatcher!=NULL)
{
#ifdef DEBUG
CAMsg::printMsg(LOG_DEBUG,"CAReplayCtrlChannelMsgProc - constructor - registering upstream replay control channel\n",this);
#endif
m_pUpstreamReplayControlChannel=new CAReplayControlChannel(this);
pDispatcher->registerControlChannel(m_pUpstreamReplayControlChannel);
}
}
Definition at line 70 of file CAReplayCtrlChannelMsgProc.cpp.
References CAMix::getDownstreamControlChannelDispatcher(), CAAbstractControlChannel::getID(), CAMix::getUpstreamControlChannelDispatcher(), m_pDownstreamReplayControlChannel, m_pMix, m_pUpstreamReplayControlChannel, CAMsg::printMsg(), CAControlChannelDispatcher::removeControlChannel(), and stopTimeStampPorpagation().
{
#ifdef DEBUG
CAMsg::printMsg(LOG_DEBUG,"CAReplayCtrlChannelMsgProc::~CAReplayCtrlChannelMsgProc()\n");
#endif
stopTimeStampPorpagation();
CAControlChannelDispatcher* pDispatcher=m_pMix->getDownstreamControlChannelDispatcher();
if(pDispatcher!=NULL)
{
pDispatcher->removeControlChannel(m_pDownstreamReplayControlChannel->getID());
delete m_pDownstreamReplayControlChannel;
m_pDownstreamReplayControlChannel = NULL;
}
pDispatcher=m_pMix->getUpstreamControlChannelDispatcher();
if(pDispatcher!=NULL)
{
pDispatcher->removeControlChannel(m_pUpstreamReplayControlChannel->getID());
delete m_pUpstreamReplayControlChannel;
m_pUpstreamReplayControlChannel = NULL;
}
}
We initialise the template used to generate the idividual responses to gettimestamps requests according to the mix ids of the cascade.
We later use this template to generate the responses quickly.
Definition at line 232 of file CAReplayCtrlChannelMsgProc.cpp.
References createDOMDocument(), createDOMElement(), E_SUCCESS, E_UNKNOWN, CAMix::FIRST_MIX, CAMix::getType(), m_docTemplate, m_pMix, REPLAY_BASE, setDOMElementAttribute(), and setDOMElementValue().
Referenced by CAReplayCtrlChannelMsgProc().
{
//NOT for the first mix! Only propagateCurrentReplayTimestamps is supported for the moment!
if(m_pMix->getType()==CAMix::FIRST_MIX)
{
return E_SUCCESS;
}
if(m_docTemplate!=NULL)
{
return E_UNKNOWN;
}
UINT8 buff[255];
pglobalOptions->getMixId(buff,255);
m_docTemplate=createDOMDocument();
DOMElement *elemMix=createDOMElement(m_docTemplate,"Mix");
setDOMElementAttribute(elemMix,"id",buff);
DOMElement *elemReplay=createDOMElement(m_docTemplate,"Replay");
elemMix->appendChild(elemReplay);
DOMElement *elemReplayOffset=createDOMElement(m_docTemplate,"ReplayOffset");
// setDOMElementValue(elemReplayOffset,(UINT32) (time(NULL)-m_pMix->m_u64ReferenceTime));
elemReplay->appendChild(elemReplayOffset);
DOMElement *elemReplayBase=createDOMElement(m_docTemplate,"ReplayBase");
setDOMElementValue(elemReplayBase,(UINT32) (REPLAY_BASE));
elemReplay->appendChild(elemReplayBase);
m_docTemplate->appendChild(elemMix);
return E_SUCCESS;
}
| SINT32 CAReplayCtrlChannelMsgProc::proccessGetTimestamp | ( | const CAReplayControlChannel * | pReceiver, |
| const UINT8 * | strMixID | ||
| ) | const |
Proccesses a getTimeStamps request on a reply control channel.
| pReceiver | the control chanel which receives the getTimeStamps request |
| E_SUCCESS | if the request could be processed successfully |
| E_UNKNOWN | otherwise Proccesses a getTimeStamp request on a reply control channel. |
| pReceiver | the control channel which receives the request |
| strMixID | the mix id for which the timestamp is requested. If NULL we timestamp of this mix is requested. |
| E_SUCCESS | if the request could be processed successfully |
| E_UNKNOWN | otherwise |
Definition at line 122 of file CAReplayCtrlChannelMsgProc.cpp.
References createDOMDocument(), createDOMElement(), E_SUCCESS, E_UNKNOWN, CAMix::FIRST_MIX, getDOMChildByName(), CAMix::getType(), m_docTemplate, m_pMix, m_pUpstreamReplayControlChannel, CAMixWithReplayDB::m_u64ReferenceTime, pMix, CAAbstractControlChannel::sendXMLMessage(), setDOMElementAttribute(), and setDOMElementValue().
Referenced by CAReplayControlChannel::processXMLMessage().
{
UINT8 buff[255];
pglobalOptions->getMixId(buff,255);
if(strMixID==NULL||strncmp((char*)strMixID,(char*)buff,255)==0)//our own replay timestamp is requested
{
//First Mixes does not have to send his timestamp!
if(m_pMix->getType()==CAMix::FIRST_MIX)
return E_SUCCESS;
const CAMixWithReplayDB* pMix=(CAMixWithReplayDB*)m_pMix;
DOMElement* elemReplayTimestamp=NULL;
if (getDOMChildByName(m_docTemplate->getDocumentElement(),"ReplayOffset",elemReplayTimestamp,true)!=E_SUCCESS){
return E_UNKNOWN;
}
setDOMElementValue(elemReplayTimestamp,(UINT32) (time(NULL)-m_pMix->m_u64ReferenceTime));
return pReceiver->sendXMLMessage(m_docTemplate);
}
else if(m_pUpstreamReplayControlChannel!=NULL&&strMixID!=NULL)//the replay timestamp of some other mix is requested
{
XERCES_CPP_NAMESPACE::DOMDocument* doc=createDOMDocument();
DOMElement *elemGet=createDOMElement(doc,"GetTimestamp");
setDOMElementAttribute(elemGet,"id",strMixID);
doc->appendChild(elemGet);
SINT32 return_value=m_pUpstreamReplayControlChannel->sendXMLMessage(doc);
if (doc != NULL)
{
doc->release();
doc = NULL;
}
return return_value;
}
return E_SUCCESS;
}
| SINT32 CAReplayCtrlChannelMsgProc::proccessGotTimestamp | ( | const CAReplayControlChannel * | pReceiver, |
| const UINT8 * | strMixID, | ||
| const UINT32 | offset | ||
| ) | const |
Proccesses a received replay timestamp rt from mix strMixID.
| pReceiver | the control channel which receives the timestamp |
| strMixID | the mix id of the mix which sends the timestamp |
| rt | the timestamp |
| E_SUCCESS | if the timestamp was preocessed successfully |
| E_UNKNOWN | otherwise |
Definition at line 265 of file CAReplayCtrlChannelMsgProc.cpp.
References createDOMDocument(), createDOMElement(), E_SUCCESS, CAMix::FIRST_MIX, CAMix::getType(), len, m_pDownstreamReplayControlChannel, m_pMix, t_mix_parameters::m_strMixID, t_mix_parameters::m_u32ReplayOffset, CAFirstMix::m_u64LastTimestampReceived, pMix, CAMsg::printMsg(), CAAbstractControlChannel::sendXMLMessage(), setDOMElementAttribute(), setDOMElementValue(), and CAFirstMix::setMixParameters().
Referenced by CAReplayControlChannel::processXMLMessage().
{
//if not first mix just forwards them down the drain...
#ifdef DEBUG
CAMsg::printMsg(LOG_DEBUG,"CAReplayCtrlChannelMsgProc::proccessGotTimestamp() \n");
#endif
if(m_pMix->getType()!=CAMix::FIRST_MIX)
{
XERCES_CPP_NAMESPACE::DOMDocument* doc=createDOMDocument();
DOMElement *elemMix=createDOMElement(doc,"Mix");
setDOMElementAttribute(elemMix,"id",strMixID);
DOMElement *elemReplay=createDOMElement(doc,"Replay");
elemMix->appendChild(elemReplay);
DOMElement *elemReplayOffset=createDOMElement(doc,"ReplayOffset");
setDOMElementValue(elemReplayOffset,(UINT32) offset);
elemReplay->appendChild(elemReplayOffset);
doc->appendChild(elemMix);
SINT32 return_value=m_pDownstreamReplayControlChannel->sendXMLMessage(doc);
if (doc != NULL)
{
doc->release();
doc = NULL;
}
return return_value;
}
//First mix --> update mix parameters
CAFirstMix* pMix=(CAFirstMix*)m_pMix;
#ifdef DEBUG
CAMsg::printMsg(LOG_DEBUG,"CAReplayCtrlChannelMsgProc::proccessGotTimestamp() - MixID: %s\n",strMixID);
CAMsg::printMsg(LOG_DEBUG,"CAReplayCtrlChannelMsgProc::proccessGotTimestamp() - LastTimestamp DIFF: %d\n",time(NULL)-pMix->m_u64LastTimestampReceived);
#endif
tMixParameters params;
UINT32 len=strlen((char*)strMixID);
params.m_strMixID=new UINT8[len+1];
memcpy(params.m_strMixID,strMixID,len+1);
params.m_u32ReplayOffset=offset;
pMix->setMixParameters(params);
pMix->m_u64LastTimestampReceived=time(NULL);
delete[] params.m_strMixID;
params.m_strMixID = NULL;
return E_SUCCESS;
}
Propagates downstream the current replay timestamp.
Definition at line 161 of file CAReplayCtrlChannelMsgProc.cpp.
References E_SUCCESS, E_UNKNOWN, getDOMChildByName(), m_docTemplate, m_pDownstreamReplayControlChannel, m_pMix, CAMixWithReplayDB::m_u64ReferenceTime, CAMsg::printMsg(), CAAbstractControlChannel::sendXMLMessage(), and setDOMElementValue().
Referenced by rp_loopPropagateTimestamp().
{
UINT8 buff[255];
pglobalOptions->getMixId(buff,255);
#ifdef DEBUG
CAMsg::printMsg(LOG_DEBUG,"Start replay timestamp propagation\n");
#endif
if(m_pDownstreamReplayControlChannel==NULL)
return E_UNKNOWN;
DOMElement* elemReplayTimestamp=NULL;
if (getDOMChildByName(m_docTemplate->getDocumentElement(),"ReplayOffset",elemReplayTimestamp,true)!=E_SUCCESS){
return E_UNKNOWN;
}
setDOMElementValue(elemReplayTimestamp,(UINT32) (time(NULL)-m_pMix->m_u64ReferenceTime));
m_pDownstreamReplayControlChannel->sendXMLMessage(m_docTemplate);
#ifdef DEBUG
CAMsg::printMsg(LOG_DEBUG,"Replay timestamp propagation finished\n");
#endif
return E_SUCCESS;
}
| SINT32 CAReplayCtrlChannelMsgProc::sendGetTimestamp | ( | const UINT8 * | strMixID | ) |
Sends upstram a request for the replay timestamp for the given mix.
Definition at line 313 of file CAReplayCtrlChannelMsgProc.cpp.
References createDOMDocument(), createDOMElement(), E_UNKNOWN, m_pUpstreamReplayControlChannel, CAAbstractControlChannel::sendXMLMessage(), and setDOMElementAttribute().
Referenced by CAFirstMix::sendReplayTimestampRequestsToAllMixes().
{
if(strMixID==NULL||strlen((const char*)strMixID)>400)
return E_UNKNOWN;
XERCES_CPP_NAMESPACE::DOMDocument* doc=createDOMDocument();
DOMElement *elemGet=createDOMElement(doc,"GetTimestamp");
setDOMElementAttribute(elemGet,"id",strMixID);
doc->appendChild(elemGet);
SINT32 return_value=m_pUpstreamReplayControlChannel->sendXMLMessage(doc);
if (doc != NULL)
{
doc->release();
doc = NULL;
}
return return_value;
}
| SINT32 CAReplayCtrlChannelMsgProc::startTimeStampPorpagation | ( | UINT32 | minutesPropagationIntervall | ) |
Sends the current replay timestamp periodically on the downstream replay control channel.
| minutesPropagationIntervall | says, how often (in minutes) should the timestamp information be sent |
Definition at line 205 of file CAReplayCtrlChannelMsgProc.cpp.
References m_bRun, m_pThreadTimestampPropagation, m_u32PropagationInterval, rp_loopPropagateTimestamp, CAThread::setMainLoop(), and CAThread::start().
Referenced by CAMiddleMix::init(), and CALastMix::init().
{
m_u32PropagationInterval=minutesPropagationInterval;
m_pThreadTimestampPropagation=new CAThread();
m_pThreadTimestampPropagation->setMainLoop(rp_loopPropagateTimestamp);
m_bRun=true;
return m_pThreadTimestampPropagation->start(this);
}
Stops the timestamp propagation.
Definition at line 214 of file CAReplayCtrlChannelMsgProc.cpp.
References E_SUCCESS, CAThread::join(), m_bRun, and m_pThreadTimestampPropagation.
Referenced by ~CAReplayCtrlChannelMsgProc().
{
m_bRun=false;
if(m_pThreadTimestampPropagation!=NULL)
{
m_pThreadTimestampPropagation->join();
delete m_pThreadTimestampPropagation;
m_pThreadTimestampPropagation = NULL;
}
m_pThreadTimestampPropagation=NULL;
return E_SUCCESS;
}
| THREAD_RETURN rp_loopPropagateTimestamp | ( | void * | param | ) | [friend] |
Definition at line 188 of file CAReplayCtrlChannelMsgProc.cpp.
Referenced by startTimeStampPorpagation().
{
CAReplayCtrlChannelMsgProc* pReplayMsgProc=(CAReplayCtrlChannelMsgProc*)param;
UINT32 propagationInterval=pReplayMsgProc->m_u32PropagationInterval;
while(pReplayMsgProc->m_bRun)
{
if(propagationInterval==0)
{
pReplayMsgProc->propagateCurrentReplayTimestamp();
propagationInterval=pReplayMsgProc->m_u32PropagationInterval;
}
sSleep(60);
propagationInterval--;
}
THREAD_RETURN_SUCCESS;
}
volatile bool CAReplayCtrlChannelMsgProc::m_bRun [private] |
Definition at line 96 of file CAReplayCtrlChannelMsgProc.hpp.
Referenced by rp_loopPropagateTimestamp(), startTimeStampPorpagation(), and stopTimeStampPorpagation().
XERCES_CPP_NAMESPACE::DOMDocument* CAReplayCtrlChannelMsgProc::m_docTemplate [private] |
Definition at line 97 of file CAReplayCtrlChannelMsgProc.hpp.
Referenced by CAReplayCtrlChannelMsgProc(), initTimestampsMessageTemplate(), proccessGetTimestamp(), and propagateCurrentReplayTimestamp().
Definition at line 90 of file CAReplayCtrlChannelMsgProc.hpp.
Referenced by CAReplayCtrlChannelMsgProc(), proccessGotTimestamp(), propagateCurrentReplayTimestamp(), and ~CAReplayCtrlChannelMsgProc().
const CAMixWithReplayDB* CAReplayCtrlChannelMsgProc::m_pMix [private] |
Definition at line 89 of file CAReplayCtrlChannelMsgProc.hpp.
Referenced by CAReplayCtrlChannelMsgProc(), initTimestampsMessageTemplate(), proccessGetTimestamp(), proccessGotTimestamp(), propagateCurrentReplayTimestamp(), and ~CAReplayCtrlChannelMsgProc().
Definition at line 93 of file CAReplayCtrlChannelMsgProc.hpp.
Referenced by CAReplayCtrlChannelMsgProc(), startTimeStampPorpagation(), and stopTimeStampPorpagation().
Definition at line 91 of file CAReplayCtrlChannelMsgProc.hpp.
Referenced by CAReplayCtrlChannelMsgProc(), proccessGetTimestamp(), sendGetTimestamp(), and ~CAReplayCtrlChannelMsgProc().
Definition at line 92 of file CAReplayCtrlChannelMsgProc.hpp.
Referenced by rp_loopPropagateTimestamp(), and startTimeStampPorpagation().
1.7.6.1