Mixe for Privacy and Anonymity in the Internet
CAChain.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2006, The JAP-Team
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * - Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
10  * - Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * - Neither the name of the University of Technology Dresden, Germany nor
15  * the names of its contributors may be used to endorse or promote
16  * products derived from this software without specific prior written
17  * permission.
18  *
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE
31  */
32 #ifndef __CA_CHAIN__
33 #define __CA_CHAIN__
34 #include "../doxygen.h"
35 #ifndef ONLY_LOCAL_PROXY
37 #include "../CASocket.hpp"
38 #include "../CAQueue.hpp"
39 #ifdef HAVE_EPOLL
40  #include "../CASocketGroupEpoll.hpp"
41 #else
42  #include "../CASocketGroup.hpp"
43 #endif
44 #ifdef DELAY_CHANNELS
45  #include "../CAMutex.hpp"
46 #endif
47 
48 
52 };
53 
55  #ifdef HAVE_EPOLL
57  #else
59  #endif
61 };
62 
63 
64 class CAChain {
65  public:
66  #ifndef DELAY_CHANNELS
67  CAChain(UINT8* a_chainId);
68  #else
69  CAChain(UINT8* a_chainId, CAMutex* a_delayBucketMutex, SINT32* a_delayBucket);
70  #endif
71  ~CAChain(void);
72  UINT8* getChainId();
73  #ifdef LOG_CHAIN_STATISTICS
74  void setSocket(CASocket* a_socket, UINT32 a_alreadyProcessedPackets, UINT32 a_alreadyProcessedBytes);
75  #else
76  void setSocket(CASocket* a_socket);
77  #endif
78  void addChannel(t_lastMixBChannelListEntry* a_channel, bool a_fastResponse);
79  void addDataToUpstreamQueue(UINT8* a_buffer, UINT32 a_size);
80  void signalConnectionError();
81  void signalUnknownChain();
82  void closeUpstream();
83  void closeDownstream();
85  #ifdef HAVE_EPOLL
86  void addToSocketGroup(CASocketGroupEpoll* a_socketGroup);
87  void removeFromSocketGroup(CASocketGroupEpoll* a_socketGroup);
88  bool isSignaledInSocketGroup(CASocketGroupEpoll* a_socketGroup);
89  UINT32 sendUpstreamData(UINT32 a_maxLength, CASocketGroupEpoll* a_removedSocketGroup);
90  SINT32 processDownstream(CASocketGroupEpoll* a_signalingGroup, MIXPACKET* a_downstreamPacket, UINT32* a_processedBytes);
91  #else
92  void addToSocketGroup(CASocketGroup* a_socketGroup);
93  void removeFromSocketGroup(CASocketGroup* a_socketGroup);
94  bool isSignaledInSocketGroup(CASocketGroup* a_socketGroup);
95  UINT32 sendUpstreamData(UINT32 a_maxLength, CASocketGroup* a_removedSocketGroup);
96  SINT32 processDownstream(CASocketGroup* a_signalingGroup, MIXPACKET* a_downstreamPacket, UINT32* a_processedBytes);
97  #endif
98 
99  private:
111 
112  #ifdef LOG_CHAIN_STATISTICS
113  /* some statistics */
114  UINT32 m_packetsFromUser;
115  UINT32 m_bytesFromUser;
116  UINT32 m_packetsToUser;
117  UINT32 m_bytesToUser;
118  UINT64 m_creationTime;
119  #endif
120 
121  #ifdef DELAY_CHANNELS
122  CAMutex* m_pDelayBucketMutex;
123  SINT32* m_pDelayBucket;
124 
125  SINT32 getDelayBucketInternal();
126  void removeFromDelayBucketInternal(SINT32 a_bytesToRemove);
127  #endif
128 
129  void closeChainInternal();
133 };
134 #endif //__CA_CHAIN__
135 #endif //ONLY_LOCAL_PROXY
signed int SINT32
Definition: basetypedefs.h:132
unsigned char UINT8
Definition: basetypedefs.h:135
unsigned int UINT32
Definition: basetypedefs.h:131
void removeFromSocketGroup(CASocketGroupEpoll *a_socketGroup)
Definition: CAChain.cpp:406
UINT8 * getChainId()
Definition: CAChain.cpp:123
bool isSignaledInSocketGroup(CASocketGroupEpoll *a_socketGroup)
Definition: CAChain.cpp:356
bool m_connectionError
Definition: CAChain.hpp:106
void forceImmediateResponsesInternal()
Definition: CAChain.cpp:581
bool m_downstreamClosed
Definition: CAChain.hpp:107
void addToSocketGroup(CASocketGroupEpoll *a_socketGroup)
Definition: CAChain.cpp:372
CAChain(UINT8 *a_chainId)
Definition: CAChain.cpp:40
UINT8 * getPrintableChainId()
Definition: CAChain.cpp:479
bool m_upstreamClosed
Definition: CAChain.hpp:108
UINT8 * m_chainId
Definition: CAChain.hpp:100
void signalConnectionError()
Definition: CAChain.cpp:465
void setSocket(CASocket *a_socket)
Definition: CAChain.cpp:134
void addChannel(t_lastMixBChannelListEntry *a_channel, bool a_fastResponse)
Definition: CAChain.cpp:485
t_socketGroupEntry * m_firstSocketGroup
Definition: CAChain.hpp:105
void closeChainInternal()
Definition: CAChain.cpp:567
~CAChain(void)
Definition: CAChain.cpp:68
CASocket * m_socket
Definition: CAChain.hpp:102
bool m_unknownChainId
Definition: CAChain.hpp:110
void addDataToUpstreamQueue(UINT8 *a_buffer, UINT32 a_size)
Definition: CAChain.cpp:444
UINT32 sendUpstreamData(UINT32 a_maxLength, CASocketGroupEpoll *a_removedSocketGroup)
Definition: CAChain.cpp:431
void closeUpstream()
Definition: CAChain.cpp:455
void closeDownstream()
Definition: CAChain.cpp:460
void removeFromAllSocketGroupsInternal()
Definition: CAChain.cpp:605
void signalUnknownChain()
Definition: CAChain.cpp:471
t_channelEntry * m_firstChannel
Definition: CAChain.hpp:104
bool m_firstDownstreamPacket
Definition: CAChain.hpp:109
CAQueue * m_upstreamSendQueue
Definition: CAChain.hpp:103
SINT32 m_lastAccessTime
Definition: CAChain.hpp:101
SINT32 processDownstream(CASocketGroupEpoll *a_signalingGroup, MIXPACKET *a_downstreamPacket, UINT32 *a_processedBytes)
Returns: 0, if a packet was created.
Definition: CAChain.cpp:146
UINT32 sendUpstreamDataInternal(UINT32 a_maxLength)
Definition: CAChain.cpp:616
This is a simple FIFO-Queue.
Definition: CAQueue.hpp:50
Definition: CAChain.hpp:49
t_channelEntry * nextChannel
Definition: CAChain.hpp:51
struct t_lastMixBChannelListEntry * channel
Definition: CAChain.hpp:50
Definition: CAChain.hpp:54
t_socketGroupEntry * nextSocketGroup
Definition: CAChain.hpp:60
CASocketGroupEpoll * socketGroup
Definition: CAChain.hpp:56