diff options
-rw-r--r-- | Makefile | 13 | ||||
-rw-r--r-- | anyrtpproxy/Makefile | 1 | ||||
-rw-r--r-- | rtpSession.cpp (renamed from routingTableEntry.cpp) | 6 | ||||
-rw-r--r-- | rtpSession.h (renamed from routingTableEntry.h) | 10 | ||||
-rw-r--r-- | rtpSessionTable.cpp | 140 | ||||
-rw-r--r-- | rtpSessionTable.h | 75 |
6 files changed, 232 insertions, 13 deletions
@@ -56,6 +56,8 @@ OBJS = tunDevice.o \ cipher.o \ authAlgo.o \ keyDerivation.o \ + rtpSessionTable.o \ + rtpSession.o \ mpi.o \ cipherFactory.o \ authAlgoFactory.o \ @@ -67,7 +69,6 @@ OBJS = tunDevice.o \ PracticalSocket.o \ router.o \ routingTable.o \ - routingTableEntry.o \ signalController.o \ syncSocket.o \ syncSocketHandler.o \ @@ -98,7 +99,6 @@ ANYCTROBJS = log.o \ anyctrOptions.o \ router.o \ routingTable.o \ - routingTableEntry.o \ seqWindow.o \ syncSocket.o \ syncSocketHandler.o \ @@ -138,6 +138,12 @@ buffer.o: buffer.cpp buffer.h syncBuffer.o: syncBuffer.cpp syncBuffer.h $(C++) $(CCFLAGS) $< -c +rtpSessionTable.o: rtpSessionTable.cpp rtpSessionTable.h + $(C++) $(CCFLAGS) $< -c + +rtpSession.o: rtpSession.cpp rtpSession.h + $(C++) $(CCFLAGS) $< -c + plainPacket.o: plainPacket.cpp plainPacket.h buffer.h $(C++) $(CCFLAGS) $< -c @@ -177,9 +183,6 @@ keyDerivationFactory.o: keyDerivationFactory.cpp keyDerivationFactory.h keyDeriv routingTable.o: routingTable.cpp routingTable.h $(C++) $(CCFLAGS) $< -c -routingTableEntry.o: routingTableEntry.cpp routingTableEntry.h - $(C++) $(CCFLAGS) $< -c - syncSocket.o: syncSocket.cpp syncSocket.h $(C++) $(CCFLAGS) $< -c diff --git a/anyrtpproxy/Makefile b/anyrtpproxy/Makefile index 952f915..9bb23d4 100644 --- a/anyrtpproxy/Makefile +++ b/anyrtpproxy/Makefile @@ -10,6 +10,7 @@ OBJS = anyrtpproxy.o \ PracticalSocket.o \ log.o \ buffer.o \ + ../rtpSessionTable.o \ options.o EXECUTABLE = anyrtpproxy diff --git a/routingTableEntry.cpp b/rtpSession.cpp index b94ba08..cb8700a 100644 --- a/routingTableEntry.cpp +++ b/rtpSession.cpp @@ -28,12 +28,12 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "routingTableEntry.h" +#include "rtpSession.h" -RoutingTableEntry::RoutingTableEntry() : mutex_() +RtpSession::RtpSession() : mutex_() { } -RoutingTableEntry::RoutingTableEntry(const RoutingTableEntry & src) : mutex_() +RtpSession::RtpSession(const RtpSession & src) : mutex_() { } diff --git a/routingTableEntry.h b/rtpSession.h index 2b7d565..cf1577f 100644 --- a/routingTableEntry.h +++ b/rtpSession.h @@ -28,8 +28,8 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef _ROUTINGTABLEENTRY_H_ -#define _ROUTINGTABLEENTRY_H_ +#ifndef _RTPSESSION_H_ +#define _RTPSESSION_H_ #include "options.h" #include "threadUtils.hpp" @@ -37,11 +37,11 @@ #include <boost/archive/text_oarchive.hpp> #include <boost/archive/text_iarchive.hpp> -class RoutingTableEntry +class RtpSession { public: - RoutingTableEntry(const RoutingTableEntry & src); - RoutingTableEntry(); + RtpSession(const RtpSession & src); + RtpSession(); private: //TODO: check if this is ok diff --git a/rtpSessionTable.cpp b/rtpSessionTable.cpp new file mode 100644 index 0000000..45f99c5 --- /dev/null +++ b/rtpSessionTable.cpp @@ -0,0 +1,140 @@ +/* + * anytun + * + * The secure anycast tunneling protocol (satp) defines a protocol used + * for communication between any combination of unicast and anycast + * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel + * mode and allows tunneling of every ETHER TYPE protocol (e.g. + * ethernet, ip, arp ...). satp directly includes cryptography and + * message authentication based on the methodes used by SRTP. It is + * intended to deliver a generic, scaleable and secure solution for + * tunneling and relaying of packets of any protocol. + * + * + * Copyright (C) 2007 anytun.org <satp@wirdorange.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (see the file COPYING included with this + * distribution); if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include "threadUtils.hpp" +#include "datatypes.h" + +#include "rtpSessionTable.h" + +RtpSessionTable* RtpSessionTable::inst = NULL; +Mutex RtpSessionTable::instMutex; +RtpSessionTable& gRtpSessionTable = RtpSessionTable::instance(); + + +RtpSessionTable& RtpSessionTable::instance() +{ + Lock lock(instMutex); + static instanceCleaner c; + if(!inst) + inst = new RtpSessionTable(); + + return *inst; +} + +RtpSessionTable::RtpSessionTable() +{ +} + +RtpSessionTable::~RtpSessionTable() +{ +} + +void RtpSessionTable::addSession(const std::string & pref, const RtpSession & ses ) +{ + Lock lock(mutex_); + + + std::pair<RtpSessionMap::iterator, bool> ret = map_.insert(RtpSessionMap::value_type(pref,ses)); + if(!ret.second) + { + map_.erase(ret.first); + map_.insert(RtpSessionMap::value_type(pref,ses)); + } +} + + +void RtpSessionTable::delSession(const std::string & pref ) +{ + Lock lock(mutex_); + + map_.erase(map_.find(pref)); +} + +/*u_int16_t RtpSessionTable::getRtpSession(const std::string & addr) +{ + Lock lock(mutex_); + if (map_.empty()) + return 0; + NetworkPrefix prefix(addr,32); + //TODO Routing algorithem isnt working!!! + RoutingMap::iterator it = map_.lower_bound(prefix); +// it--; + if (it!=map_.end()) + return it->second; + it=map_.begin(); + return it->second; +} +*/ + +RtpSession& RtpSessionTable::getOrNewSessionUnlocked(const std::string & addr) +{ + RtpSessionMap::iterator it = map_.find(addr); + if(it!=map_.end()) + return it->second; + + map_.insert(RtpSessionMap::value_type(addr, RtpSession())); + it = map_.find(addr); + return it->second; +} + +uint16_t RtpSessionTable::getCountUnlocked() +{ + RtpSessionMap::iterator it = map_.begin(); + uint16_t routes=0; + for (;it!=map_.end();++it) + routes++; + return routes; +} + +RtpSessionMap::iterator RtpSessionTable::getBeginUnlocked() +{ + return map_.begin(); +} + +RtpSessionMap::iterator RtpSessionTable::getEndUnlocked() +{ + return map_.end(); +} + +void RtpSessionTable::clear() +{ + Lock lock(mutex_); + map_.clear(); +} + +bool RtpSessionTable::empty() +{ + Lock lock(mutex_); + return map_.empty(); +} + +Mutex& RtpSessionTable::getMutex() +{ + return mutex_; +} diff --git a/rtpSessionTable.h b/rtpSessionTable.h new file mode 100644 index 0000000..f127801 --- /dev/null +++ b/rtpSessionTable.h @@ -0,0 +1,75 @@ +/* + * anytun + * + * The secure anycast tunneling protocol (satp) defines a protocol used + * for communication between any combination of unicast and anycast + * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel + * mode and allows tunneling of every ETHER TYPE protocol (e.g. + * ethernet, ip, arp ...). satp directly includes cryptography and + * message authentication based on the methodes used by SRTP. It is + * intended to deliver a generic, scaleable and secure solution for + * tunneling and relaying of packets of any protocol. + * + * + * Copyright (C) 2007 anytun.org <satp@wirdorange.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (see the file COPYING included with this + * distribution); if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _RTPSESSIONTABLE_H +#define _RTPSESSIONTABLE_H + +#include <map> + +#include "threadUtils.hpp" +#include "datatypes.h" +#include "rtpSession.h" +typedef std::map<std::string,RtpSession> RtpSessionMap; + +class RtpSessionTable +{ +public: + static RtpSessionTable& instance(); + RtpSessionTable(); + ~RtpSessionTable(); + void addSession(const std::string & , const RtpSession &); + void delSession(const std::string & ); + //u_int16_t getRoute(const NetworkAddress &); + bool empty(); + void clear(); + Mutex& getMutex(); + RtpSession& getOrNewSessionUnlocked(const std::string & addr); + uint16_t getCountUnlocked(); + RtpSessionMap::iterator getBeginUnlocked(); + RtpSessionMap::iterator getEndUnlocked(); + +private: + static Mutex instMutex; + static RtpSessionTable* inst; + class instanceCleaner { + public: ~instanceCleaner() { + if(RtpSessionTable::inst != 0) + delete RtpSessionTable::inst; + } + }; + RtpSessionTable(const RtpSessionTable &s); + void operator=(const RtpSessionTable &s); + RtpSessionMap map_; + Mutex mutex_; +}; + +extern RtpSessionTable& gRtpSessionTable; + +#endif |