32 #include "../StdAfx.h"
33 #ifndef ONLY_LOCAL_PROXY
37 #include "../CAUtil.hpp"
39 #ifndef DELAY_CHANNELS
55 #ifdef LOG_CHAIN_STATISTICS
56 m_packetsFromUser = 0;
63 m_pDelayBucketMutex = a_delayBucketMutex;
64 m_pDelayBucket = a_delayBucket;
89 delete currentDeadline;
90 currentDeadline = NULL;
99 #ifdef LOG_CHAIN_STATISTICS
107 CAMsg::printMsg(LOG_DEBUG,
"%s,%u,%u,%u,%u,%u\n",
chainId, duration, m_bytesFromUser, m_bytesToUser, m_packetsFromUser, m_packetsToUser);
113 #ifdef DELAY_CHANNELS
117 m_pDelayBucketMutex->lock();
118 *m_pDelayBucket = -1;
119 m_pDelayBucketMutex->unlock();
127 #ifdef LOG_CHAIN_STATISTICS
130 m_bytesFromUser = a_alreadyProcessedBytes;
131 m_packetsFromUser = a_alreadyProcessedPackets;
150 *a_processedBytes = 0;
152 timespec currentTime;
187 delete testedDeadlineEntry;
206 #ifdef DELAY_CHANNELS
207 payloadData =
min(payloadData, (
UINT16)getDelayBucketInternal());
209 if (payloadData > 0) {
222 if (bytesReceived >= 0) {
223 if (bytesReceived == 0) {
229 #ifdef DELAY_CHANNELS
230 removeFromDelayBucketInternal(bytesReceived);
244 delete currentDeadline;
245 currentDeadline = NULL;
246 *a_processedBytes = (
UINT32)bytesReceived;
247 #ifdef LOG_CHAIN_STATISTICS
249 m_bytesToUser = m_bytesToUser + (
UINT32)bytesReceived;
275 delete currentChannel;
276 currentChannel = NULL;
280 delete currentChannelEntry;
281 currentChannelEntry = NULL;
282 #ifdef LOG_CHAIN_STATISTICS
297 timespec currentTime;
343 delete currentDeadline;
344 currentDeadline = NULL;
345 #ifdef LOG_CHAIN_STATISTICS
381 bool alreadyIncluded =
false;
382 while ((currentEntry != NULL) && (!alreadyIncluded)) {
384 alreadyIncluded =
true;
391 if (!alreadyIncluded) {
400 *previousNextEntryPointer = currentEntry;
414 while (currentEntry != NULL) {
440 return processedBytes;
448 #ifdef LOG_CHAIN_STATISTICS
450 m_bytesFromUser = m_bytesFromUser + a_size;
482 return printableChainId;
487 bool invalidChannel =
false;
496 invalidChannel =
true;
511 newChannel->
channel = a_channel;
512 if (lastChannel != NULL) {
521 timespec currentTime;
523 if (!invalidChannel) {
537 if (a_fastResponse && (i == 0)) {
541 currentDeadline->
deadline.tv_sec = currentTime.tv_sec;
550 currentDeadline->
deadline.tv_sec = currentTime.tv_sec;
552 currentDeadline->
deadline.tv_nsec = currentTime.tv_nsec;
553 *lastNextDeadlinePointer = currentDeadline;
554 lastNextDeadlinePointer = &(currentDeadline->
nextDeadline);
584 timespec currentTime;
587 while (currentChannel != NULL) {
589 while (currentDeadline != NULL) {
590 if (currentDeadline->
deadline.tv_sec > currentTime.tv_sec) {
591 currentDeadline->
deadline.tv_sec = currentTime.tv_sec;
592 currentDeadline->
deadline.tv_nsec = currentTime.tv_nsec;
595 if ((currentDeadline->
deadline.tv_sec == currentTime.tv_sec) && (currentDeadline->
deadline.tv_nsec > currentTime.tv_nsec)) {
596 currentDeadline->
deadline.tv_nsec = currentTime.tv_nsec;
608 while (currentEntry != NULL) {
612 currentEntry = nextEntry;
619 UINT32 length = a_maxLength;
624 if (errorCode >= 0) {
625 length = (
UINT32)errorCode;
638 #ifdef DELAY_CHANNELS
639 SINT32 CAChain::getDelayBucketInternal() {
641 m_pDelayBucketMutex->lock();
642 delayBucket = *m_pDelayBucket;
643 m_pDelayBucketMutex->unlock();
647 void CAChain::removeFromDelayBucketInternal(
SINT32 a_bytesToRemove) {
648 m_pDelayBucketMutex->lock();
649 *m_pDelayBucket = (*m_pDelayBucket) + a_bytesToRemove;
650 m_pDelayBucketMutex->unlock();
UINT8 * bytes2hex(const void *bytes, UINT32 len)
Converts the byte array to a hex string.
SINT32 getcurrentTimeMicros(UINT64 &u64Time)
Gets the current Systemtime in micros seconds.
UINT32 strtrim(UINT8 *s)
Removes leading and ending whitespaces (chars<=32) from a zero terminated string.
SINT32 getRandom(UINT32 *val)
Gets 32 random bits.
SINT32 getcurrentTime(timespec &t)
Gets the current Systemtime in milli seconds.
UINT32 diff64(const UINT64 &bigop, const UINT64 &smallop)
void removeFromSocketGroup(CASocketGroupEpoll *a_socketGroup)
bool isSignaledInSocketGroup(CASocketGroupEpoll *a_socketGroup)
void forceImmediateResponsesInternal()
void addToSocketGroup(CASocketGroupEpoll *a_socketGroup)
CAChain(UINT8 *a_chainId)
UINT8 * getPrintableChainId()
void signalConnectionError()
void setSocket(CASocket *a_socket)
void addChannel(t_lastMixBChannelListEntry *a_channel, bool a_fastResponse)
t_socketGroupEntry * m_firstSocketGroup
void closeChainInternal()
void addDataToUpstreamQueue(UINT8 *a_buffer, UINT32 a_size)
UINT32 sendUpstreamData(UINT32 a_maxLength, CASocketGroupEpoll *a_removedSocketGroup)
void removeFromAllSocketGroupsInternal()
void signalUnknownChain()
t_channelEntry * m_firstChannel
bool m_firstDownstreamPacket
CAQueue * m_upstreamSendQueue
SINT32 processDownstream(CASocketGroupEpoll *a_signalingGroup, MIXPACKET *a_downstreamPacket, UINT32 *a_processedBytes)
Returns: 0, if a packet was created.
UINT32 sendUpstreamDataInternal(UINT32 a_maxLength)
void removeFromTable(t_lastMixBChannelListEntry *a_channelEntry)
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
This is a simple FIFO-Queue.
SINT32 add(const void *buff, UINT32 size)
Adds data to the Queue.
SINT32 clean()
Removes any stored data from the Queue.
SINT32 peek(UINT8 *pbuff, UINT32 *psize)
Peeks data from the Queue.
SINT32 remove(UINT32 *psize)
Removes data from the Queue.
bool isEmpty()
Returns true, if the Queue is empty.
SINT32 remove(CASocket &s)
bool isSignaled(CASocket &s)
bool isSignaled(CASocket &s)
SINT32 remove(CASocket &s)
virtual SINT32 receive(UINT8 *buff, UINT32 len)
Will receive some bytes from the socket.
virtual SINT32 send(const UINT8 *buff, UINT32 len)
Sends some data over the network.
virtual SINT32 crypt2(const UINT8 *in, UINT8 *out, UINT32 len)=0
t_channelEntry * nextChannel
struct t_lastMixBChannelListEntry * channel
t_deadlineEntry * nextDeadline
t_first_downstream_chain_cell firstCell
t_sequel_downstream_chain_cell sequelCell
UINT8 chainId[CHAIN_ID_LENGTH]
UINT8 data[MAX_FIRST_DOWNSTREAM_CHAINCELL_PAYLOAD]
t_deadlineEntry * firstResponseDeadline
UINT16 remainingDownstreamPackets
class CALastMixBChannelList * associatedChannelList
CASymChannelCipher * channelCipher
UINT8 data[MAX_SEQUEL_DOWNSTREAM_CHAINCELL_PAYLOAD]
t_socketGroupEntry * nextSocketGroup
CASocketGroupEpoll * socketGroup
UINT8 chainId[CHAIN_ID_LENGTH]
#define MAX_SEQUEL_DOWNSTREAM_CHAINCELL_PAYLOAD
#define MAX_FIRST_DOWNSTREAM_CHAINCELL_PAYLOAD
#define CHAINFLAG_UNKNOWN_CHAIN
#define CHAINFLAG_STREAM_CLOSED
#define CHAINFLAG_CONNECTION_ERROR
#define CHANNEL_DOWNSTREAM_PACKETS