41 #include "UDPMix/CAUDPMixMiddle.hpp"
44 const char* _malloc_options=
"AX";
47 #ifdef REPLAY_DATABASE_PERFORMANCE_TEST
51 #ifdef DO_MIDDLE_MIX_BENCHMARK
52 #include "benchmarking/CAMiddleMixBenchmarkDummy.hpp"
56 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_MIDDLE_MIX || defined INLUDE_LAST_MIX
58 #ifdef INCLUDE_MIDDLE_MIX
62 #ifdef INCLUDE_LAST_MIX
81 #ifndef ONLY_LOCAL_PROXY
98 #ifdef REPLAY_DATABASE_PERFORMANCE_TEST
105 #if defined(HAVE_CRTDBG)
112 void signal_broken_pipe(
int sig)
115 signal(SIGPIPE,signal_broken_pipe);
128 UINT8 strPidFile[512];
131 if(::remove((
char*)strPidFile)!=0)
134 int old_uid=geteuid();
136 ::remove((
char*)strPidFile);
153 #ifdef ENABLE_GPERFTOOLS_CPU_PROFILER
158 #ifndef ONLY_LOCAL_PROXY
166 #if defined(HAVE_CRTDBG)
167 _CrtMemCheckpoint( &s2 );
168 if ( _CrtMemDifference( &s3, s1, &s2 ) )
169 _CrtMemDumpStatistics( &s3 );
172 printf(
"Memory leak check clean!\n");
177 Debug(list_allocations_on(libcw_do));
187 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_MIDDLE_MIX
206 signal(SIGSEGV,SIG_DFL);
214 #ifdef PRINT_THREAD_STACK_TRACE
215 METHOD_STACK* stack = CAThread::getCurrentStack();
218 CAMsg::printMsg( LOG_CRIT,
"Stack trace: %s, \"%s\"\n", stack->strMethodName, stack->strPosition);
236 CAMsg::printMsg(LOG_INFO,
"Hm.. Signal SIG_TERM received... exiting!\n");
245 #if defined _DEBUG && ! defined (ONLY_LOCAL_PROXY)
246 CAMsg::printMsg(LOG_INFO,
"%d threads listed.\n",CALibProxytest::getThreadList()->getSize());
247 CALibProxytest::getThreadList()->showAll();
253 #ifndef ONLY_LOCAL_PROXY
265 #pragma warning( push )
266 #pragma warning( disable : 4127 )
270 CAMsg::printMsg(LOG_CRIT,
"sizeof(SINT8) != 1 --> maybe a compiler (optimization) problem!\n");
275 CAMsg::printMsg(LOG_CRIT,
"sizeof(UINT8) != 1 --> maybe a compiler (optimization) problem!\n");
280 CAMsg::printMsg(LOG_CRIT,
"sizeof(SINT16) != 2 --> maybe a compiler (optimization) problem!\n");
285 CAMsg::printMsg(LOG_CRIT,
"sizeof(UINT16) != 2 --> maybe a compiler (optimization) problem!\n");
290 CAMsg::printMsg(LOG_CRIT,
"sizeof(SINT32) != 4 --> maybe a compiler (optimization) problem!\n");
295 CAMsg::printMsg(LOG_CRIT,
"sizeof(UINT32) != 4 --> maybe a compiler (optimization) problem!\n");
298 #ifdef HAVE_NATIVE_UINT64
301 CAMsg::printMsg(LOG_CRIT,
"sizeof(UINT64) != 8 --> maybe a compiler (optimization) problem!\n");
307 #pragma warning( pop )
317 UINT32 soffsets[7] = { 0, 4, 6, 6, 6, 8, 9 };
326 for (
int i = 0; i < 7; i++)
327 if (soffsets[i] != hoffsets[i])
329 CAMsg::printMsg(LOG_CRIT,
"Hm, The Offsets seams to be ok - so we try to continue - hope that works...\n");
332 if (UDPMIXPACKET_SIZE !=
sizeof(UDPMIXPACKET))
334 CAMsg::printMsg(LOG_CRIT,
"UDPMIXPACKET_SIZE [%u] != sizeof(UDPMUXPACKET) [%u] --> maybe a compiler (optimization) problem!\n", UDPMIXPACKET_SIZE,
sizeof(UDPMIXPACKET));
336 if (UDPMIXPACKET_LINKHEADER_TYPE_SIZE !=
sizeof(UDPMIXPACKET_LINKHEADER))
338 CAMsg::printMsg(LOG_CRIT,
"UDPMIXPACKET_LINKHEADER_TYPE_SIZE [%u] != sizeof(UDPMIXPACKET_LINKHEADER) [%u] --> maybe a compiler (optimization) problem!\n", UDPMIXPACKET_LINKHEADER_TYPE_SIZE,
sizeof(UDPMIXPACKET_LINKHEADER));
519 int main(
int argc,
const char* argv[])
522 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_MIDDLE_MIX || defined INLUDE_LAST_MIX|| defined INLUDE_FIRST_MIX
525 #if defined(HAVE_CRTDBG)
527 _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
529 _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDOUT );
531 _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDOUT );
533 UINT32 tmpDbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
534 tmpDbgFlag |= _CRTDBG_ALLOC_MEM_DF;
535 tmpDbgFlag |=_CRTDBG_LEAK_CHECK_DF;
536 _CrtSetDbgFlag(tmpDbgFlag);
538 _CrtMemCheckpoint( s1 );
542 Debug(libcw_do.on());
543 Debug(dc::malloc.on());
551 #ifdef REPLAY_DATABASE_PERFORMANCE_TEST
557 #ifdef DATA_RETENTION_LOG
558 if(
sizeof(t_dataretentionLogEntry)!=18)
560 CAMsg::printMsg(LOG_CRIT,
"sizeof(tDataRetentionLogEntry) [%u] != 18 --> maybe a compiler (optimization) problem!\n",
sizeof(t_dataretentionLogEntry));
575 CAMsg::printMsg(LOG_CRIT,
"An error occurred before we could finish parsing the configuration file. Exiting...\n");
576 exitCode=EXIT_FAILURE;
594 CAMsg::printMsg(LOG_CRIT,
"You must specify which kind of Mix you want to run!\n");
598 exitCode=EXIT_FAILURE;
622 close(STDOUT_FILENO);
623 close(STDERR_FILENO);
630 exitCode=EXIT_FAILURE;
639 #ifdef ENABLE_GPERFTOOLS_CPU_PROFILER
640 ProfilerStart(
"gperf.cpuprofiler.data");
641 ProfilerRegisterThread();
646 signal(SIGPIPE,signal_broken_pipe);
648 signal(SIGPIPE,SIG_IGN);
650 #ifndef ONLY_LOCAL_PROXY
651 struct sigaction newAction;
652 memset(&newAction,0,
sizeof(newAction));
654 newAction.sa_flags=0;
655 sigaction(SIGHUP,&newAction,NULL);
660 #if !defined (_DEBUG) && !defined(NO_SIGSEV_CATCH)
664 UINT8 strPidFile[512];
668 int old_uid=geteuid();
672 sprintf((
char*)thePid,
"%i",pid);
673 int len=strlen((
char*)thePid);
674 int hFile=open((
char*)strPidFile,O_TRUNC|O_CREAT|O_WRONLY,
S_IREAD|
S_IWRITE);
676 if(hFile==-1&&seteuid(0)!=-1)
678 hFile=open((
char*)strPidFile,O_TRUNC|O_CREAT|O_WRONLY,
S_IREAD|
S_IWRITE);
681 if(hFile==-1||
len!=write(hFile,thePid,
len))
687 exitCode=EXIT_FAILURE;
712 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_MIDDLE_MIX || defined INCLUDE_LAST_MIX
713 SINT32 s32MaxSockets=10000;
714 CAMsg::printMsg(LOG_INFO,
"Max Number of sockets we can open: %i\n",s32MaxSockets);
716 #ifdef SERVER_MONITORING
720 if(s32MaxSockets>100&&s32MaxSockets<10000)
725 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_FIRST_MIX
729 #if !defined(NEW_MIX_TYPE)
738 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_MIDDLE_MIX
746 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_LAST_MIX
750 #if !defined(NEW_MIX_TYPE)
758 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_LAST_MIX
762 #if !defined(NEW_MIX_TYPE)
770 CAMsg::printMsg(LOG_ERR,
"this Mix is compiled to work only as local proxy!\n");
774 #ifdef DO_MIDDLE_MIX_BENCHMARK
775 pMix =
new CAMiddleMixBenchmarkDummy();
782 exitCode=EXIT_FAILURE;
804 #if !defined(NEW_MIX_TYPE)
818 CAMsg::printMsg( LOG_ERR,
"Tried to reconfigure a former first/middle-Mix to a LastMix -> impossible!\n");
#define MONITORING_FIRE_SYS_EVENT(e_type)
#define MONITORING_FIRE_NET_EVENT(e_type)
SINT32 sSleep(UINT32 sec)
Sleeps sec Seconds.
SINT32 msSleep(UINT32 ms)
Sleeps ms milliseconds.
SINT32 reread(CAMix *pMix)
Rereads the configuration file (if one was given on startup) and reconfigures the mix according to th...
static CACmdLnOptions * getOptions()
static SINT32 cleanup()
do necessary cleanups of libraries etc.
static SINT32 init()
do necessary initialisations of libraries etc.
virtual bool isShutDown()
static const char *const getLogLevelStr()
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
static SINT32 measurePerformance(UINT8 *strLogFile, UINT32 lowerBoundEntries, UINT32 upperBoundEntries, UINT32 stepBy, UINT32 meassuresPerStep, UINT32 insertsPerMeasure)
This mehtod can be used to measure the performance of the Replay database.
static SINT32 setMaxNormalSockets(UINT32 u)
Sets the max number of allowed "normal" sockets.
void init()
do necessary initialisations of libraries etc.
void signal_interrupt(int)
void checkSizesOfTypes()
Check what the sizes of (base) types are as expected – if not kill the programm.
void cleanup()
do necessary cleanups of libraries etc.
void removePidFile()
Removes the stored PID (file)
void my_terminate(void)
Remark: terminate() might be already defined by the c lib – do not use this name.....
int main(int argc, const char *argv[])
struct t_MixPacketPayload payload