Mixe for Privacy and Anonymity in the Internet
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
CAReplayCtrlChannelMsgProc Class Reference

#include <CAReplayCtrlChannelMsgProc.hpp>

Collaboration diagram for CAReplayCtrlChannelMsgProc:

Public Member Functions

 CAReplayCtrlChannelMsgProc (const CAMixWithReplayDB *pMix)
 Initialises the replay control channel messages processor with the necessary information. More...
 
 ~CAReplayCtrlChannelMsgProc ()
 
SINT32 propagateCurrentReplayTimestamp ()
 Propagates downstream the current replay timestamp. More...
 
SINT32 startTimeStampPorpagation (UINT32 minutesPropagationIntervall)
 Sends the current replay timestamp periodically on the downstream replay control channel. More...
 
SINT32 stopTimeStampPorpagation ()
 Stops the timestamp propagation. More...
 
SINT32 proccessGetTimestamp (const CAReplayControlChannel *pReceiver, const UINT8 *strMixID) const
 Proccesses a getTimeStamps request on a reply control channel. More...
 
SINT32 proccessGotTimestamp (const CAReplayControlChannel *pReceiver, const UINT8 *strMixID, const UINT32 offset) const
 Proccesses a received replay timestamp rt from mix strMixID. More...
 
SINT32 sendGetTimestamp (const UINT8 *strMixID)
 Sends upstram a request for the replay timestamp for the given mix. More...
 

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. More...
 

Private Attributes

const CAMixWithReplayDBm_pMix
 
CAReplayControlChannelm_pDownstreamReplayControlChannel
 
CAReplayControlChannelm_pUpstreamReplayControlChannel
 
UINT32 m_u32PropagationInterval
 
CAThreadm_pThreadTimestampPropagation
 
volatile bool m_bRun
 
XERCES_CPP_NAMESPACE::DOMDocument * m_docTemplate
 

Friends

THREAD_RETURN rp_loopPropagateTimestamp (void *param)
 

Detailed Description

Definition at line 37 of file CAReplayCtrlChannelMsgProc.hpp.

Constructor & Destructor Documentation

◆ CAReplayCtrlChannelMsgProc()

CAReplayCtrlChannelMsgProc::CAReplayCtrlChannelMsgProc ( const CAMixWithReplayDB pMix)

Initialises the replay control channel messages processor with the necessary information.

Definition at line 39 of file CAReplayCtrlChannelMsgProc.cpp.

40  {
41  CAMsg::printMsg(LOG_DEBUG,"CAReplayCtrlChannelMsgProc - constructor - this=%p\n",this);
45  m_pMix=pMix;
46  m_docTemplate=NULL;
49 
50  if(pDispatcher!=NULL)
51  {
52  #ifdef DEBUG
53  CAMsg::printMsg(LOG_DEBUG,"CAReplayCtrlChannelMsgProc - constructor - registering downstream replay control channel\n",this);
54  #endif
56  CAMsg::printMsg(LOG_DEBUG,"m_pDownstreamReplayControlChannel= %p\n",m_pDownstreamReplayControlChannel);
58  }
60  if(pDispatcher!=NULL)
61  {
62  #ifdef DEBUG
63  CAMsg::printMsg(LOG_DEBUG,"CAReplayCtrlChannelMsgProc - constructor - registering upstream replay control channel\n",this);
64  #endif
67  }
68  }
This class "dispatches" messages which it receives via proccessMixPacket() to the associated control ...
SINT32 registerControlChannel(CAAbstractControlChannel *pControlChannel)
Registers a control channel for receiving messages.
CAControlChannelDispatcher * getDownstreamControlChannelDispatcher() const
Definition: CAMix.hpp:115
CAControlChannelDispatcher * getUpstreamControlChannelDispatcher() const
Definition: CAMix.hpp:120
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
Definition: CAMsg.cpp:251
A Control channel for the exchange of the current replay detection timestamps.
SINT32 initTimestampsMessageTemplate()
We initialise the template used to generate the idividual responses to gettimestamps requests accordi...
CAReplayControlChannel * m_pDownstreamReplayControlChannel
XERCES_CPP_NAMESPACE::DOMDocument * m_docTemplate
CAReplayControlChannel * m_pUpstreamReplayControlChannel
CAMix * pMix
Definition: proxytest.cpp:75

References CAMix::getDownstreamControlChannelDispatcher(), CAMix::getUpstreamControlChannelDispatcher(), initTimestampsMessageTemplate(), m_docTemplate, m_pDownstreamReplayControlChannel, m_pMix, m_pThreadTimestampPropagation, m_pUpstreamReplayControlChannel, pMix, CAMsg::printMsg(), and CAControlChannelDispatcher::registerControlChannel().

Here is the call graph for this function:

◆ ~CAReplayCtrlChannelMsgProc()

CAReplayCtrlChannelMsgProc::~CAReplayCtrlChannelMsgProc ( )

Definition at line 70 of file CAReplayCtrlChannelMsgProc.cpp.

71  {
72  #ifdef DEBUG
73  CAMsg::printMsg(LOG_DEBUG,"CAReplayCtrlChannelMsgProc::~CAReplayCtrlChannelMsgProc()\n");
74  #endif
77  if(pDispatcher!=NULL)
78  {
82  }
84  if(pDispatcher!=NULL)
85  {
89  }
90  }
UINT32 getID() const
Returns the id of this control channel.
SINT32 stopTimeStampPorpagation()
Stops the timestamp propagation.

References CAMix::getDownstreamControlChannelDispatcher(), CAAbstractControlChannel::getID(), CAMix::getUpstreamControlChannelDispatcher(), m_pDownstreamReplayControlChannel, m_pMix, m_pUpstreamReplayControlChannel, CAMsg::printMsg(), CAControlChannelDispatcher::removeControlChannel(), and stopTimeStampPorpagation().

Here is the call graph for this function:

Member Function Documentation

◆ initTimestampsMessageTemplate()

SINT32 CAReplayCtrlChannelMsgProc::initTimestampsMessageTemplate ( )
private

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.

233  {
234  //NOT for the first mix! Only propagateCurrentReplayTimestamps is supported for the moment!
236  {
237  return E_SUCCESS;
238  }
239 
240  if(m_docTemplate!=NULL)
241  {
242  return E_UNKNOWN;
243  }
244 
245  UINT8 buff[255];
246  pglobalOptions->getMixId(buff,255);
247 
249  DOMElement *elemMix=createDOMElement(m_docTemplate,"Mix");
250  setDOMElementAttribute(elemMix,"id",buff);
251  DOMElement *elemReplay=createDOMElement(m_docTemplate,"Replay");
252  elemMix->appendChild(elemReplay);
253  DOMElement *elemReplayOffset=createDOMElement(m_docTemplate,"ReplayOffset");
254 // setDOMElementValue(elemReplayOffset,(UINT32) (time(NULL)-m_pMix->m_u64ReferenceTime));
255  elemReplay->appendChild(elemReplayOffset);
256  DOMElement *elemReplayBase=createDOMElement(m_docTemplate,"ReplayBase");
257  setDOMElementValue(elemReplayBase,(UINT32) (REPLAY_BASE));
258  elemReplay->appendChild(elemReplayBase);
259  m_docTemplate->appendChild(elemMix);
260 
261  return E_SUCCESS;
262  }
#define REPLAY_BASE
SINT32 setDOMElementAttribute(DOMNode *pElem, const char *attrName, const char *value)
Definition: CAUtil.cpp:831
SINT32 setDOMElementValue(DOMElement *pElem, SINT32 value)
Definition: CAUtil.cpp:939
XERCES_CPP_NAMESPACE::DOMDocument * createDOMDocument()
Parses a timestamp in JDBC timestamp escape format (as it comes from the BI) and outputs the value in...
Definition: CAUtil.cpp:1568
DOMElement * createDOMElement(XERCES_CPP_NAMESPACE::DOMDocument *pOwnerDoc, const char *const name)
Creates a new DOMElement with the given name which belongs to the DOMDocument owernDoc.
Definition: CAUtil.cpp:814
unsigned char UINT8
Definition: basetypedefs.h:135
unsigned int UINT32
Definition: basetypedefs.h:131
virtual tMixType getType() const =0
@ FIRST_MIX
Definition: CAMix.hpp:53
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
#define E_UNKNOWN
Definition: errorcodes.hpp:3

References createDOMDocument(), createDOMElement(), E_SUCCESS, E_UNKNOWN, CAMix::FIRST_MIX, CAMix::getType(), m_docTemplate, m_pMix, REPLAY_BASE, setDOMElementAttribute(), and setDOMElementValue().

Referenced by CAReplayCtrlChannelMsgProc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ proccessGetTimestamp()

SINT32 CAReplayCtrlChannelMsgProc::proccessGetTimestamp ( const CAReplayControlChannel pReceiver,
const UINT8 strMixID 
) const

Proccesses a getTimeStamps request on a reply control channel.

Parameters
pReceiverthe control chanel which receives the getTimeStamps request
Return values
E_SUCCESSif the request could be processed successfully
E_UNKNOWNotherwise Proccesses a getTimeStamp request on a reply control channel.
Parameters
pReceiverthe control channel which receives the request
strMixIDthe mix id for which the timestamp is requested. If NULL we timestamp of this mix is requested.
Return values
E_SUCCESSif the request could be processed successfully
E_UNKNOWNotherwise

Definition at line 122 of file CAReplayCtrlChannelMsgProc.cpp.

123  {
124  UINT8 buff[255];
125  pglobalOptions->getMixId(buff,255);
126  if(strMixID==NULL||strncmp((char*)strMixID,(char*)buff,255)==0)//our own replay timestamp is requested
127  {
128  //First Mixes does not have to send his timestamp!
130  return E_SUCCESS;
131 
133 
134  DOMElement* elemReplayTimestamp=NULL;
135  if (getDOMChildByName(m_docTemplate->getDocumentElement(),"ReplayOffset",elemReplayTimestamp,true)!=E_SUCCESS){
136  return E_UNKNOWN;
137  }
138  setDOMElementValue(elemReplayTimestamp,(UINT32) (time(NULL)-m_pMix->m_u64ReferenceTime));
139 
140  return pReceiver->sendXMLMessage(m_docTemplate);
141  }
142  else if(m_pUpstreamReplayControlChannel!=NULL&&strMixID!=NULL)//the replay timestamp of some other mix is requested
143  {
144  XERCES_CPP_NAMESPACE::DOMDocument* doc=createDOMDocument();
145  DOMElement *elemGet=createDOMElement(doc,"GetTimestamp");
146  setDOMElementAttribute(elemGet,"id",strMixID);
147  doc->appendChild(elemGet);
148 
150  if (doc != NULL)
151  {
152  doc->release();
153  doc = NULL;
154  }
155 
156  return return_value;
157  }
158  return E_SUCCESS;
159  }
SINT32 getDOMChildByName(const DOMNode *pNode, const char *const name, DOMElement *&child, bool deep)
Definition: CAUtil.cpp:458
signed int SINT32
Definition: basetypedefs.h:132
SINT32 sendXMLMessage(const XERCES_CPP_NAMESPACE::DOMDocument *pDocMsg) const
Call to send a XML message via this control channel.
This class (interface) adds the functionality used by last and middle mixes to detecte replays.

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ proccessGotTimestamp()

SINT32 CAReplayCtrlChannelMsgProc::proccessGotTimestamp ( const CAReplayControlChannel pReceiver,
const UINT8 strMixID,
const UINT32  offset 
) const

Proccesses a received replay timestamp rt from mix strMixID.

Parameters
pReceiverthe control channel which receives the timestamp
strMixIDthe mix id of the mix which sends the timestamp
rtthe timestamp
Return values
E_SUCCESSif the timestamp was preocessed successfully
E_UNKNOWNotherwise

Definition at line 265 of file CAReplayCtrlChannelMsgProc.cpp.

266  {
267  //if not first mix just forwards them down the drain...
268  #ifdef DEBUG
269  CAMsg::printMsg(LOG_DEBUG,"CAReplayCtrlChannelMsgProc::proccessGotTimestamp() \n");
270  #endif
272  {
273  XERCES_CPP_NAMESPACE::DOMDocument* doc=createDOMDocument();
274  DOMElement *elemMix=createDOMElement(doc,"Mix");
275  setDOMElementAttribute(elemMix,"id",strMixID);
276  DOMElement *elemReplay=createDOMElement(doc,"Replay");
277  elemMix->appendChild(elemReplay);
278  DOMElement *elemReplayOffset=createDOMElement(doc,"ReplayOffset");
279  setDOMElementValue(elemReplayOffset,(UINT32) offset);
280  elemReplay->appendChild(elemReplayOffset);
281  doc->appendChild(elemMix);
282 
284  if (doc != NULL)
285  {
286  doc->release();
287  doc = NULL;
288  }
289 
290  return return_value;
291  }
292 
293  //First mix --> update mix parameters
295  #ifdef DEBUG
296  CAMsg::printMsg(LOG_DEBUG,"CAReplayCtrlChannelMsgProc::proccessGotTimestamp() - MixID: %s\n",strMixID);
297  CAMsg::printMsg(LOG_DEBUG,"CAReplayCtrlChannelMsgProc::proccessGotTimestamp() - LastTimestamp DIFF: %d\n",time(NULL)-pMix->m_u64LastTimestampReceived);
298  #endif
299 
300  tMixParameters params;
301  UINT32 len=strlen((char*)strMixID);
302  params.m_strMixID=new UINT8[len+1];
303  memcpy(params.m_strMixID,strMixID,len+1);
304  params.m_u32ReplayOffset=offset;
305  pMix->setMixParameters(params);
306 
307  pMix->m_u64LastTimestampReceived=time(NULL);
308  delete[] params.m_strMixID;
309  params.m_strMixID = NULL;
310  return E_SUCCESS;
311  }
UINT32 m_u32ReplayOffset
Definition: typedefs.hpp:218
UINT8 * m_strMixID
Definition: typedefs.hpp:216
UINT16 len
Definition: typedefs.hpp:0

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

Referenced by CAReplayControlChannel::processXMLMessage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ propagateCurrentReplayTimestamp()

SINT32 CAReplayCtrlChannelMsgProc::propagateCurrentReplayTimestamp ( )

Propagates downstream the current replay timestamp.

Definition at line 161 of file CAReplayCtrlChannelMsgProc.cpp.

162  {
163  UINT8 buff[255];
164  pglobalOptions->getMixId(buff,255);
165 
166  #ifdef DEBUG
167  CAMsg::printMsg(LOG_DEBUG,"Start replay timestamp propagation\n");
168  #endif
169 
171  return E_UNKNOWN;
172 
173  DOMElement* elemReplayTimestamp=NULL;
174  if (getDOMChildByName(m_docTemplate->getDocumentElement(),"ReplayOffset",elemReplayTimestamp,true)!=E_SUCCESS){
175  return E_UNKNOWN;
176  }
177  setDOMElementValue(elemReplayTimestamp,(UINT32) (time(NULL)-m_pMix->m_u64ReferenceTime));
178 
180 
181  #ifdef DEBUG
182  CAMsg::printMsg(LOG_DEBUG,"Replay timestamp propagation finished\n");
183  #endif
184 
185  return E_SUCCESS;
186  }

References E_SUCCESS, E_UNKNOWN, getDOMChildByName(), m_docTemplate, m_pDownstreamReplayControlChannel, m_pMix, CAMixWithReplayDB::m_u64ReferenceTime, CAMsg::printMsg(), CAAbstractControlChannel::sendXMLMessage(), and setDOMElementValue().

Here is the call graph for this function:

◆ sendGetTimestamp()

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.

314  {
315  if(strMixID==NULL||strlen((const char*)strMixID)>400)
316  return E_UNKNOWN;
317 
318  XERCES_CPP_NAMESPACE::DOMDocument* doc=createDOMDocument();
319  DOMElement *elemGet=createDOMElement(doc,"GetTimestamp");
320  setDOMElementAttribute(elemGet,"id",strMixID);
321  doc->appendChild(elemGet);
322 
324  if (doc != NULL)
325  {
326  doc->release();
327  doc = NULL;
328  }
329 
330  return return_value;
331  }

References createDOMDocument(), createDOMElement(), E_UNKNOWN, m_pUpstreamReplayControlChannel, CAAbstractControlChannel::sendXMLMessage(), and setDOMElementAttribute().

Referenced by CAFirstMix::sendReplayTimestampRequestsToAllMixes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ startTimeStampPorpagation()

SINT32 CAReplayCtrlChannelMsgProc::startTimeStampPorpagation ( UINT32  minutesPropagationIntervall)

Sends the current replay timestamp periodically on the downstream replay control channel.

Parameters
minutesPropagationIntervallsays, how often (in minutes) should the timestamp information be sent

Definition at line 205 of file CAReplayCtrlChannelMsgProc.cpp.

206  {
207  m_u32PropagationInterval=minutesPropagationInterval;
210  m_bRun=true;
211  return m_pThreadTimestampPropagation->start(this);
212  }
friend THREAD_RETURN rp_loopPropagateTimestamp(void *param)
SINT32 start(void *param, bool bDaemon=false, bool bSilent=false)
Starts the execution of the main function of this thread.
Definition: CAThread.cpp:115
SINT32 setMainLoop(THREAD_MAIN_TYP fnc)
Sets the main function which will be executed within this thread.
Definition: CAThread.hpp:148

References m_bRun, m_pThreadTimestampPropagation, m_u32PropagationInterval, rp_loopPropagateTimestamp, CAThread::setMainLoop(), and CAThread::start().

Referenced by CAMiddleMix::init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stopTimeStampPorpagation()

SINT32 CAReplayCtrlChannelMsgProc::stopTimeStampPorpagation ( )

Stops the timestamp propagation.

Definition at line 214 of file CAReplayCtrlChannelMsgProc.cpp.

215  {
216  m_bRun=false;
218  {
222  }
224  return E_SUCCESS;
225  }
SINT32 join()
Waits for the main function to finish execution.
Definition: CAThread.cpp:187

References E_SUCCESS, CAThread::join(), m_bRun, and m_pThreadTimestampPropagation.

Referenced by ~CAReplayCtrlChannelMsgProc().

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ rp_loopPropagateTimestamp

THREAD_RETURN rp_loopPropagateTimestamp ( void *  param)
friend

Definition at line 188 of file CAReplayCtrlChannelMsgProc.cpp.

189  {
191  UINT32 propagationInterval=pReplayMsgProc->m_u32PropagationInterval;
192  while(pReplayMsgProc->m_bRun)
193  {
194  if(propagationInterval==0)
195  {
196  pReplayMsgProc->propagateCurrentReplayTimestamp();
197  propagationInterval=pReplayMsgProc->m_u32PropagationInterval;
198  }
199  sSleep(60);
200  propagationInterval--;
201  }
203  }
SINT32 sSleep(UINT32 sec)
Sleeps sec Seconds.
Definition: CAUtil.cpp:425
#define THREAD_RETURN_SUCCESS
Definition: StdAfx.h:542
SINT32 propagateCurrentReplayTimestamp()
Propagates downstream the current replay timestamp.

Referenced by startTimeStampPorpagation().

Member Data Documentation

◆ m_bRun

volatile bool CAReplayCtrlChannelMsgProc::m_bRun
private

◆ m_docTemplate

XERCES_CPP_NAMESPACE::DOMDocument* CAReplayCtrlChannelMsgProc::m_docTemplate
private

◆ m_pDownstreamReplayControlChannel

CAReplayControlChannel* CAReplayCtrlChannelMsgProc::m_pDownstreamReplayControlChannel
private

◆ m_pMix

const CAMixWithReplayDB* CAReplayCtrlChannelMsgProc::m_pMix
private

◆ m_pThreadTimestampPropagation

CAThread* CAReplayCtrlChannelMsgProc::m_pThreadTimestampPropagation
private

◆ m_pUpstreamReplayControlChannel

CAReplayControlChannel* CAReplayCtrlChannelMsgProc::m_pUpstreamReplayControlChannel
private

◆ m_u32PropagationInterval

UINT32 CAReplayCtrlChannelMsgProc::m_u32PropagationInterval
private

Definition at line 92 of file CAReplayCtrlChannelMsgProc.hpp.

Referenced by startTimeStampPorpagation().


The documentation for this class was generated from the following files: