|
Mixe for Privacy and Anonymity in the Internet
|
00001 /* 00002 * Copyright (c) 2006, The JAP-Team 00003 * All rights reserved. 00004 * Redistribution and use in source and binary forms, with or without 00005 * modification, are permitted provided that the following conditions are met: 00006 * 00007 * - Redistributions of source code must retain the above copyright notice, 00008 * this list of conditions and the following disclaimer. 00009 * 00010 * - Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 00014 * - Neither the name of the University of Technology Dresden, Germany nor 00015 * the names of its contributors may be used to endorse or promote 00016 * products derived from this software without specific prior written 00017 * permission. 00018 * 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00021 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00022 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00023 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE 00024 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00025 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00026 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00027 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00028 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00029 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00030 * POSSIBILITY OF SUCH DAMAGE 00031 */ 00032 #ifndef __CA_CHAIN__ 00033 #define __CA_CHAIN__ 00034 #include "../doxygen.h" 00035 #ifndef ONLY_LOCAL_PROXY 00036 #include "CALastMixBChannelList.hpp" 00037 #include "../CASocket.hpp" 00038 #include "../CAQueue.hpp" 00039 #ifdef HAVE_EPOLL 00040 #include "../CASocketGroupEpoll.hpp" 00041 #else 00042 #include "../CASocketGroup.hpp" 00043 #endif 00044 #ifdef DELAY_CHANNELS 00045 #include "../CAMutex.hpp" 00046 #endif 00047 00048 00049 struct t_channelEntry { 00050 struct t_lastMixBChannelListEntry* channel; 00051 t_channelEntry* nextChannel; 00052 }; 00053 00054 struct t_socketGroupEntry { 00055 #ifdef HAVE_EPOLL 00056 CASocketGroupEpoll* socketGroup; 00057 #else 00058 CASocketGroup* socketGroup; 00059 #endif 00060 t_socketGroupEntry* nextSocketGroup; 00061 }; 00062 00063 00064 class CAChain { 00065 public: 00066 #ifndef DELAY_CHANNELS 00067 CAChain(UINT8* a_chainId); 00068 #else 00069 CAChain(UINT8* a_chainId, CAMutex* a_delayBucketMutex, SINT32* a_delayBucket); 00070 #endif 00071 ~CAChain(void); 00072 UINT8* getChainId(); 00073 #ifdef LOG_CHAIN_STATISTICS 00074 void setSocket(CASocket* a_socket, UINT32 a_alreadyProcessedPackets, UINT32 a_alreadyProcessedBytes); 00075 #else 00076 void setSocket(CASocket* a_socket); 00077 #endif 00078 void addChannel(t_lastMixBChannelListEntry* a_channel, bool a_fastResponse); 00079 void addDataToUpstreamQueue(UINT8* a_buffer, UINT32 a_size); 00080 void signalConnectionError(); 00081 void signalUnknownChain(); 00082 void closeUpstream(); 00083 void closeDownstream(); 00084 UINT8* getPrintableChainId(); 00085 #ifdef HAVE_EPOLL 00086 void addToSocketGroup(CASocketGroupEpoll* a_socketGroup); 00087 void removeFromSocketGroup(CASocketGroupEpoll* a_socketGroup); 00088 bool isSignaledInSocketGroup(CASocketGroupEpoll* a_socketGroup); 00089 UINT32 sendUpstreamData(UINT32 a_maxLength, CASocketGroupEpoll* a_removedSocketGroup); 00090 SINT32 processDownstream(CASocketGroupEpoll* a_signalingGroup, MIXPACKET* a_downstreamPacket, UINT32* a_processedBytes); 00091 #else 00092 void addToSocketGroup(CASocketGroup* a_socketGroup); 00093 void removeFromSocketGroup(CASocketGroup* a_socketGroup); 00094 bool isSignaledInSocketGroup(CASocketGroup* a_socketGroup); 00095 UINT32 sendUpstreamData(UINT32 a_maxLength, CASocketGroup* a_removedSocketGroup); 00096 SINT32 processDownstream(CASocketGroup* a_signalingGroup, MIXPACKET* a_downstreamPacket, UINT32* a_processedBytes); 00097 #endif 00098 00099 private: 00100 UINT8* m_chainId; 00101 SINT32 m_lastAccessTime; 00102 CASocket* m_socket; 00103 CAQueue* m_upstreamSendQueue; 00104 t_channelEntry* m_firstChannel; 00105 t_socketGroupEntry* m_firstSocketGroup; 00106 bool m_connectionError; 00107 bool m_downstreamClosed; 00108 bool m_upstreamClosed; 00109 bool m_firstDownstreamPacket; 00110 bool m_unknownChainId; 00111 00112 #ifdef LOG_CHAIN_STATISTICS 00113 /* some statistics */ 00114 UINT32 m_packetsFromUser; 00115 UINT32 m_bytesFromUser; 00116 UINT32 m_packetsToUser; 00117 UINT32 m_bytesToUser; 00118 UINT64 m_creationTime; 00119 #endif 00120 00121 #ifdef DELAY_CHANNELS 00122 CAMutex* m_pDelayBucketMutex; 00123 SINT32* m_pDelayBucket; 00124 00125 SINT32 getDelayBucketInternal(); 00126 void removeFromDelayBucketInternal(SINT32 a_bytesToRemove); 00127 #endif 00128 00129 void closeChainInternal(); 00130 void forceImmediateResponsesInternal(); 00131 void removeFromAllSocketGroupsInternal(); 00132 UINT32 sendUpstreamDataInternal(UINT32 a_maxLength); 00133 }; 00134 #endif //__CA_CHAIN__ 00135 #endif //ONLY_LOCAL_PROXY
1.7.6.1