33 #if !defined(AFX_STDAFX_H__9A5B051F_FF3A_11D3_9F5E_000001037024__INCLUDED_)
34 #define AFX_STDAFX_H__9A5B051F_FF3A_11D3_9F5E_000001037024__INCLUDED_
36 #define MIX_VERSION "00.12.08"
39 #define MIX_VERSION_TESTING true
41 #define MIX_VERSION_TESTING_TEXT "This is a testing/development version. Please do not expect it to work in a productive environment, and don't be surprised if you get unpredictive results or segmentation faults. If you don't like experiments, go and get the stable code.\n"
45 #define STR_HELPER(x) #x
46 #define STR(x) STR_HELPER(x)
50 #if defined(DEBUG)|| defined(_DEBUG)
76 #define NO_INFOSERVICE_TRHEADS
95 #define NEW_FLOW_CONTROL
96 #define NEW_CHANNEL_ENCRYPTION
116 #if !defined(PRINT_THREAD_STACK_TRACE) && defined (DEBUG)&& ! defined(ONLY_LOCAL_PROXY)
117 #define PRINT_THREAD_STACK_TRACE
120 #if defined(LOG_DIALOG)
124 #ifndef COUNTRY_STATS
125 #define COUNTRY_STATS
128 #if (defined(LOG_CHANNEL)) && !defined(LOG_TRAFFIC_PER_USER)
129 #define LOG_TRAFFIC_PER_USER
133 #define LOG_COUNTRIES_INTERVALL 6
136 #ifdef DELAY_CHANNELS
137 #ifndef DELAY_CHANNEL_TRAFFIC
138 #define DELAY_CHANNEL_TRAFFIC 10000
142 #ifndef DELAY_CHANNEL_KBYTE_PER_SECOND
143 #define DELAY_BUCKET_GROW_INTERVALL 100
144 #define DELAY_BUCKET_GROW PAYLOAD_SIZE
147 #define DELAY_BUCKET_GROW_INTERVALL (1000/DELAY_CHANNEL_KBYTE_PER_SECOND)
148 #define DELAY_BUCKET_GROW PAYLOAD_SIZE
153 #ifndef DELAY_USERS_TRAFFIC
154 #define DELAY_USERS_TRAFFIC 0
158 #ifndef DELAY_USERS_PACKETS_PER_SECOND
159 #define DELAY_USERS_BUCKET_GROW_INTERVALL 100
160 #define DELAY_USERS_BUCKET_GROW 10
163 #define DELAY_USERS_BUCKET_GROW_INTERVALL 1000
164 #define DELAY_USERS_BUCKET_GROW DELAY_USERS_PACKETS_PER_SECOND
168 #ifndef DELAY_CHANNELS_LATENCY
169 #define DELAY_CHANNEL_LATENCY 0
172 #if defined LASTMIX_CHECK_MEMORY && ! defined(QUEUE_SIZE_LOG)
173 #define QUEUE_SIZE_LOG
176 #define REPLAY_TIMESTAMP_PROPAGATION_INTERVALL 1
178 #define KEEP_ALIVE_TRAFFIC_RECV_WAIT_TIME 75000
180 #define KEEP_ALIVE_TRAFFIC_SEND_WAIT_TIME 65000
183 #undef ANON_DEBUG_MODE
186 #if defined(PAYMENT) && ! defined(SSL_HACK)
192 #define MAX_POLLFD 8192
194 #define CLIENTS_PER_IP 100
195 #define CHANNELS_PER_CLIENT 500
197 #define FIRST_MIX_RECEIVE_SYM_KEY_FROM_JAP_TIME_OUT 40000
198 #define LAST_MIX_TO_PROXY_CONNECT_TIMEOUT 2000
199 #define AI_LOGIN_SO_TIMEOUT (UINT32) 10000
200 #define LAST_MIX_TO_PROXY_SEND_TIMEOUT (UINT32)5000
201 #define MIX_TO_INFOSERVICE_TIMEOUT 30000
202 #define NUM_LOGIN_WORKER_TRHEADS 10
203 #define MAX_LOGIN_QUEUE 500
205 #if defined(PAYMENT) || defined(MANIOQ)
206 #define MAX_USER_SEND_QUEUE 100000
207 #define MAX_DATA_PER_CHANNEL 100000
208 #define USER_SEND_BUFFER_RESUME 10000
211 #define MAX_USER_SEND_QUEUE 1000000
212 #define MAX_DATA_PER_CHANNEL 1000000
213 #define USER_SEND_BUFFER_RESUME 100000
216 #define PAYMENT_ACCOUNT_CERT_TIMEOUT 180
217 #define CLEANUP_THREAD_SLEEP_INTERVAL 60
218 #define BALANCE_REQUEST_TIMEOUT 60
220 #define MAX_SIGNATURE_ELEMENTS 10
222 #define FLOW_CONTROL_SENDME_HARD_LIMIT 1600000
223 #define FLOW_CONTROL_SENDME_SOFT_LIMIT 800000
225 #if defined(PAYMENT) || defined(MANIOQ)
226 #define MAX_READ_FROM_PREV_MIX_QUEUE_SIZE 10000000
227 #define MAX_READ_FROM_NEXT_MIX_QUEUE_SIZE 10000000
228 #define MAX_MIXIN_SEND_QUEUE_SIZE 10000000
229 #define MAX_NEXT_MIX_QUEUE_SIZE 10000000
232 #define MAX_READ_FROM_PREV_MIX_QUEUE_SIZE 10000000000
233 #define MAX_READ_FROM_NEXT_MIX_QUEUE_SIZE 10000000000
234 #define MAX_MIXIN_SEND_QUEUE_SIZE 10000000000
235 #define MAX_NEXT_MIX_QUEUE_SIZE 10000000000
240 #define DEFAULT_INFOSERVICE "141.76.45.37"
242 #ifndef MIX_POOL_SIZE
243 #define MIX_POOL_SIZE 10
245 #define MIX_POOL_TIMEOUT 200
246 #define DUMMY_CHANNEL 0
248 #define FM_PACKET_STATS_LOG_INTERVALL 1
249 #define LM_PACKET_STATS_LOG_INTERVALL 1
251 #define MIX_CASCADE_PROTOCOL_VERSION_0_1_2 12
252 #define MIX_CASCADE_PROTOCOL_VERSION_0_1_1 11
253 #define MIX_CASCADE_PROTOCOL_VERSION_0_1_0 10
255 #define MIX_CASCADE_PROTOCOL_VERSION_0_8 8
256 #define MIX_CASCADE_PROTOCOL_VERSION_0_7 7
258 #define MIX_CASCADE_PROTOCOL_VERSION_0_5 5
259 #define MIX_CASCADE_PROTOCOL_VERSION_0_4 4
260 #define MIX_CASCADE_PROTOCOL_VERSION_0_3 3
261 #define MIX_CASCADE_PROTOCOL_VERSION_0_2 2
263 #ifdef REPLAY_DETECTION
264 #define MIX_CASCADE_PROTOCOL_VERSION "0.81"
267 #elif defined (WITH_INTEGRITY_CHECK)
268 #define MIX_CASCADE_PROTOCOL_VERSION "0.12"
270 #define MIX_CASCADE_PROTOCOL_VERSION "0.10"
274 #define PAYMENT_VERSION "2.0"
276 #define INCLUDE_MIDDLE_MIX
277 #ifdef ONLY_MIDDLE_MIX
278 #define ONLY_LOCAL_PROXY
279 #define INCLUDE_MIDDLE_MIX
280 #define INCLUDE_LAST_MIX
281 #define INCLUDE_FIRST_MIX
284 #if defined (_WIN32) &&!defined(__CYGWIN__)
287 #define _CRT_SECURE_NO_DEPRECATE
288 #define _CRT_SECURE_NO_WARNINGS
289 #define WIN32_LEAN_AND_MEAN
293 #define _WIN32_WINDOWS 0x0410
294 #include <winsock2.h>
295 #include <Ws2tcpip.h>
300 #define socklen_t int
301 #define MSG_NOSIGNAL 0
304 #include <sys/timeb.h>
306 #include "wepoll/wepoll.h"
310 #define NEED_GMTIME_R_WINDOWS
311 struct tm * gmtime_r(
const time_t *timep,
struct tm *result);
314 #define HAVE_MALLOC_H
315 #define SET_NET_ERROR(x)
316 #define GET_NET_ERROR (WSAGetLastError())
317 #define GET_NET_ERROR_STR(x) ("Unknown error")
318 #define RESETERROR errno=0;
319 #define GETERROR (errno)
320 #define ERR_INTERN_TIMEDOUT WSAETIMEDOUT
321 #define ERR_INTERN_CONNREFUSED WSAECONNREFUSED
322 #define ERR_INTERN_WOULDBLOCK WSAEWOULDBLOCK
323 #define ERR_INTERN_SOCKET_CLOSED WSAENOTSOCK
324 #define MSG_DONTWAIT 0
327 #define SHUT_RDWR SD_BOTH
328 #define HAVE_VSNPRINTF
329 #define HAVE_SNPRINTF
331 #define vsnprintf _vsnprintf
334 #define snprintf _snprintf
336 #define getpid _getpid
337 #define strncasecmp _strnicmp
339 #define myfilewrite _write
342 #define access _access
344 #define alloca _alloca
345 #define HAVE_PTHREAD_MUTEX_INIT
346 #define HAVE_PTHREAD_COND_INIT
347 #define HAVE_SEM_INIT
348 #define BYTE_ORDER_LITTLE_ENDIAN
350 #define EPOLL_HANDLE HANDLE
351 #define S_IRUSR _S_IREAD
352 #define S_IWUSR _S_IWRITE
355 #if defined(__linux__) && !defined(__linux)
359 #include <libcw/sysd.h>
360 #include <libcw/debug.h>
365 #ifndef HAVE_SOCKLEN_T
369 #define HAVE_UNIX_DOMAIN_PROTOCOL
370 #define HAVE_VSNPRINTF
371 #define HAVE_SNPRINTF
374 #define HAVE_PTHREAD_MUTEX_INIT
375 #define HAVE_PTHREAD_COND_INIT
376 #define HAVE_SEM_INIT
378 #define HAVE_TCP_KEEPALIVE
381 #undef HAVE_TCP_KEEPALIVE
384 #undef HAVE_TCP_KEEPALIVE
389 #undef HAVE_TCP_KEEPALIVE
390 #define MSG_DONTWAIT 0
392 #if !defined(__FreeBSD__)&&!defined(__linux)
399 #define MAX_PATH 4096
402 #undef HAVE_VSNPRINTF
406 #if !defined( __linux) &&!defined(__CYGWIN__)
407 #include <sys/filio.h>
408 #define MSG_NOSIGNAL 0
413 #if !defined(BYTE_ORDER_LITTLE_ENDIAN) && ! defined(BYTE_ORDER_BIG_ENDIAN)
415 #error "You MUST define either BYTE_ORDER_BIG_ENDIAN or BYTE_ORDER_LITTLE_ENDIAN"
417 #if BYTE_ORDER == BIG_ENDIAN
418 #define BYTE_ORDER_BIG_ENDIAN
420 #define BYTE_ORDER_LITTLE_ENDIAN
426 #include <sys/filio.h>
432 #include <sys/epoll.h>
433 #define EPOLL_HANDLE SINT32
434 #define epoll_close close
436 #include <sys/ioctl.h>
437 #include <sys/types.h>
438 #include <sys/socket.h>
441 #include <sys/time.h>
442 #include <netinet/in.h>
443 #include <arpa/inet.h>
451 #include <sys/resource.h>
452 #include <sys/wait.h>
461 typedef struct hostent
HOSTENT;
462 #define ioctlsocket(a,b,c) ioctl(a,b,c)
463 #define closesocket(s) close(s)
464 #define SOCKET_ERROR -1
465 #define INVALID_SOCKET -1
469 #define GET_NET_ERROR (errno)
470 #define SET_NET_ERROR(x) (errno = x)
471 #define GET_NET_ERROR_STR(x) (errno == E_TIMEDOUT ? "Connection timed out." : (errno == E_SOCKETCLOSED ? "Socket is closed." : strerror(x)))
472 #define RESETERROR errno=0;
473 #define GETERROR (errno)
474 #define ERR_INTERN_TIMEDOUT ETIMEDOUT
475 #define ERR_INTERN_CONNREFUSED ECONNREFUSED
476 #define ERR_INTERN_WOULDBLOCK EAGAIN
477 #define ERR_INTERN_SOCKET_CLOSED EBADF
479 #define INADDR_NONE -1
482 #define AF_LOCAL AF_UNIX
484 #if !defined(HAVE_MSG_DONTWAIT)&&!defined(MSG_DONTWAIT)
485 #define MSG_DONTWAIT 0
488 #define S_IREAD S_IRUSR
491 #define S_IWRITE S_IWUSR
493 #define myfilewrite write
508 #ifdef HAVE_PTHREAD_COND_INIT
509 #define HAVE_PTHREAD_CV
511 #ifdef HAVE_PTHREAD_MUTEX_INIT
512 #define HAVE_PTHREAD_MUTEXES
515 #if !defined(HAVE_PTHREAD_CV) || !defined (HAVE_PTHREAD_MUTEXES)
516 #define USE_SEMAPHORE
520 #define HAVE_PTHREAD_SEMAPHORE
524 #ifdef HAVE_PTHREAD_SEMAPHORE
525 #include <semaphore.h>
531 #define THREAD_RETURN void
532 #define THREAD_RETURN_ERROR return
533 #define THREAD_RETURN_SUCCESS return
534 #include <l4/thread/thread.h>
535 #include <l4/util/macros.h>
536 #include <l4/env/errno.h>
540 #define THREAD_RETURN void*
541 #define THREAD_RETURN_ERROR return(NULL)
542 #define THREAD_RETURN_SUCCESS return (NULL)
546 #define ASSERT(cond,msg)
548 #define ASSERT(cond,msg) {if(!(cond)){CAMsg::printMsg(LOG_DEBUG,"ASSERT: %s (File: %s, Line: %u)\n",msg,__FILE__,__LINE__);}}
551 #if defined(HAVE_VSNPRINTF) && defined(HAVE_SNPRINTF)
557 #ifdef __GOOGLE_UNIT_TEST__
558 #include <gtest/gtest.h>
564 #include <sys/types.h>
567 #include <sys/stat.h>
570 #include "trio/trio.hpp"
571 #include "trio/triostr.hpp"
574 #include <openssl/rsa.h>
575 #include <openssl/aes.h>
576 #include <openssl/rand.h>
577 #include <openssl/evp.h>
578 #ifdef USE_OPENSSL_GCM
581 #include <openssl/modes.h>
584 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_MIDDLE_MIX
585 #include <openssl/x509v3.h>
586 #include <openssl/pkcs12.h>
587 #include <openssl/dsa.h>
589 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_FIRST_MIX
590 #include <openssl/md5.h>
592 #ifndef ONLY_LOCAL_PROXY
593 #include <openssl/asn1.h>
594 #include <openssl/ssl.h>
595 #include <openssl/sha.h>
596 #include <openssl/md5.h>
606 #include "xml/dom/mxml/mxmlDOM.hpp"
608 #include <util/XercesDefs.hpp>
609 #include <util/PlatformUtils.hpp>
610 #include <util/XMLString.hpp>
611 #include <util/XMLUniDefs.hpp>
612 #include <framework/XMLFormatter.hpp>
613 #include <util/TranscodingException.hpp>
614 #include <framework/MemBufInputSource.hpp>
624 #include <dom/DOM.hpp>
625 #include <parsers/XercesDOMParser.hpp>
627 #if (_XERCES_VERSION >= 20200)
628 XERCES_CPP_NAMESPACE_USE
635 #define O_LARGEFILE 0
641 #define O_SYNC O_FSYNC
649 #define min(a,b) (( (a) < (b) ) ? (a):(b) )
654 #define max(a,b) (((a) > (b) ) ? (a):(b))
658 #if defined(COUNTRY_STATS)
660 #ifdef HAVE_MYSQL_MYSQL_H
661 #include <mysql/mysql.h>
666 #include <mysql/mysql.h>
673 #ifdef HAVE_POSTGRESQL_LIBPQ_FE_H
674 #include <postgresql/libpq-fe.h>
675 #elif defined(HAVE_PGSQL_LIBPQ_FE_H)
676 #include <pgsql/libpq-fe.h>
678 #include <libpq-fe.h>
680 #elif defined(__FreeBSD__) ||defined (_WIN32)
681 #include <libpq-fe.h>
683 #include <postgresql/libpq-fe.h>
687 #ifdef COMPRESSED_LOGS
694 #ifdef XERCES_FULLVERSIONDOT
695 #define MY_XERCES_VERSION XERCES_FULLVERSIONDOT
696 #elif defined(Xerces_DLLVersionStr)
697 #define MY_XERCES_VERSION Xerces_DLLVersionStr
699 #define MY_XERCES_VERSION "unknown"
702 #ifdef ENABLE_GPERFTOOLS_CPU_PROFILER
703 #include <gperftools/profiler.h>
706 #ifdef INTEL_IPP_CRYPTO
711 #define PAYMENT_VERSION_INFO " (payment)"
712 #define PAYMENT_COMPATIBILITY "Payment"
714 #define PAYMENT_VERSION_INFO
715 #define PAYMENT_COMPATIBILITY
718 #ifdef DATA_RETENTION_LOG
719 #define DATA_RETENTION_LOG_INFO " (with data retention log)"
721 #define DATA_RETENTION_LOG_INFO
724 #define NEW_FLOW_CONTROL_INFO " (with new flow control)"
725 #define NEW_FLOW_CONTROL_COMPATIBILITY "NewFlowControl"
727 #define NEW_CHANNEL_ENCRYPTION_INFO " (with enhanced channel encryption)"
728 #define NEW_CHANNEL_ENCRYPTION_COMPATIBILITY "NewChannelEncryption"
730 #ifdef WITH_INTEGRITY_CHECK
731 #define WITH_INTEGRITY_CHECK_INFO " (with integrity check for data channels)"
732 #define WITH_INTEGRITY_CHECK_COMPATIBILITY "WithIntegrityCheck"
734 #define WITH_INTEGRITY_CHECK_INFO
735 #define WITH_INTEGRITY_CHECK_COMPATIBILITY
738 #ifdef DELAY_CHANNELS
739 #define WITH_DELAY_CHANNELS_INFO " (with delay channels)"
741 #define WITH_DELAY_CHANNELS_INFO
745 #define WITH_DELAY_USERS_INFO " (with delay users)"
747 #define WITH_DELAY_USERS_INFO
751 #define XML_LIB_VERSION "\nUsing Xerces-C: " MY_XERCES_VERSION
753 #ifdef MXML_MAJOR_VERSION
754 #define MAKE_A_STRING(x) #x
755 #define TOSTRING(x) MAKE_A_STRING(x)
756 #define XML_LIB_VERSION "\nUsing Mini-XML: " TOSTRING(MXML_MAJOR_VERSION) "." TOSTRING(MXML_MINOR_VERSION)
758 #define XML_LIB_VERSION "\nUsing Mini-XML: unknown"
761 #define MIX_VERSION_INFO "Mix-Version: " MIX_VERSION PAYMENT_VERSION_INFO DATA_RETENTION_LOG_INFO NEW_FLOW_CONTROL_INFO NEW_CHANNEL_ENCRYPTION_INFO WITH_INTEGRITY_CHECK_INFO WITH_DELAY_CHANNELS_INFO WITH_DELAY_USERS_INFO "\nUsing: " OPENSSL_VERSION_TEXT XML_LIB_VERSION "\n"
762 #define MIX_VERSION_COMPATIBILITY PAYMENT_COMPATIBILITY " " NEW_FLOW_CONTROL_COMPATIBILITY " " NEW_CHANNEL_ENCRYPTION_COMPATIBILITY " " WITH_INTEGRITY_CHECK_COMPATIBILITY
767 #define MAX_ACCOUNTNUMBER 999999999999ULL
768 #define MIN_ACCOUNTNUMBER 100000000000ULL
769 #define ACCOUNT_NUMBER_SIZE 12