00001 /* 00002 * Copyright (C) 2009, Edmundo Albuquerque de Souza e Silva. 00003 * 00004 * This file may be distributed under the terms of the Q Public License 00005 * as defined by Trolltech AS of Norway and appearing in the file 00006 * LICENSE.QPL included in the packaging of this file. 00007 * 00008 * THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING 00009 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00010 * PURPOSE. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, 00011 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING 00012 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 00013 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 00014 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 00015 * 00016 * Thanks: Jose Renato Santos 00017 * 00018 */ 00019 00020 //////////////////////////////////////////////////////////////////////////////// 00021 // NATMap.h: Declaration of the NATData and NATMap structures 00022 //////////////////////////////////////////////////////////////////////////////// 00023 00024 #ifndef __NATMAP_H_ 00025 #define __NATMAP_H_ 00026 00027 00028 // Funcoes da STL 00029 #include <utility> 00030 #include <map> 00031 00032 // Funcoes da biblioteca padrao 00033 #include <pthread.h> 00034 00035 using namespace std; 00036 00037 struct NATData 00038 { 00039 public: 00040 int nat_addr; 00041 int nat_port; 00042 NATData(); 00043 NATData( int addr, int port ); 00044 }; 00045 00046 bool operator<( const NATData d1, const NATData d2 ); 00047 00048 class NATMap 00049 { 00050 // Mapa com os mapeamentos de enderecos IP, porta. 00051 map<pair<NATData, int>, NATData> nat_map; 00052 // Mutex para garantir o acesso exclusivo ao mapa. 00053 pthread_mutex_t m_Mutex; 00054 public: 00055 NATMap(); 00056 ~NATMap(); 00057 void insertElement( NATData server_map, int stor_id, NATData storage_map ); 00058 NATData getElement( NATData server_map, int stor_id ); 00059 void removeElement( NATData server_map, int stor_id ); 00060 // TODO: Remover a funcao quando a RioNeti e a NetMgr nao forem mais usadas. 00061 bool findElement( NATData server_map, int stor_id ); 00062 #ifdef RIO_DEBUG2 00063 void printMapping( void ); 00064 #endif 00065 }; 00066 00067 #endif