From 2a634c97aac517cb36bbd7345eaff3d361b5514d Mon Sep 17 00:00:00 2001 From: Othmar Gsenger Date: Sat, 8 Mar 2008 17:50:24 +0000 Subject: added RtpSessionTable --- Makefile | 13 +++-- anyrtpproxy/Makefile | 1 + routingTableEntry.cpp | 39 -------------- routingTableEntry.h | 57 -------------------- rtpSession.cpp | 39 ++++++++++++++ rtpSession.h | 57 ++++++++++++++++++++ rtpSessionTable.cpp | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++ rtpSessionTable.h | 75 +++++++++++++++++++++++++++ 8 files changed, 320 insertions(+), 101 deletions(-) delete mode 100644 routingTableEntry.cpp delete mode 100644 routingTableEntry.h create mode 100644 rtpSession.cpp create mode 100644 rtpSession.h create mode 100644 rtpSessionTable.cpp create mode 100644 rtpSessionTable.h diff --git a/Makefile b/Makefile index e68e5e9..9ca8206 100644 --- a/Makefile +++ b/Makefile @@ -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/routingTableEntry.cpp deleted file mode 100644 index b94ba08..0000000 --- a/routingTableEntry.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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 - * - * 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 "routingTableEntry.h" - -RoutingTableEntry::RoutingTableEntry() : mutex_() -{ -} - -RoutingTableEntry::RoutingTableEntry(const RoutingTableEntry & src) : mutex_() -{ -} diff --git a/routingTableEntry.h b/routingTableEntry.h deleted file mode 100644 index 2b7d565..0000000 --- a/routingTableEntry.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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 - * - * 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 _ROUTINGTABLEENTRY_H_ -#define _ROUTINGTABLEENTRY_H_ - -#include "options.h" -#include "threadUtils.hpp" - -#include -#include - -class RoutingTableEntry -{ -public: - RoutingTableEntry(const RoutingTableEntry & src); - RoutingTableEntry(); - -private: - //TODO: check if this is ok - Mutex mutex_; - friend class boost::serialization::access; - template - void serialize(Archive & ar, const unsigned int version) - { - Lock lock(mutex_); - } -}; - -#endif diff --git a/rtpSession.cpp b/rtpSession.cpp new file mode 100644 index 0000000..cb8700a --- /dev/null +++ b/rtpSession.cpp @@ -0,0 +1,39 @@ +/* + * 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 + * + * 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 "rtpSession.h" + +RtpSession::RtpSession() : mutex_() +{ +} + +RtpSession::RtpSession(const RtpSession & src) : mutex_() +{ +} diff --git a/rtpSession.h b/rtpSession.h new file mode 100644 index 0000000..cf1577f --- /dev/null +++ b/rtpSession.h @@ -0,0 +1,57 @@ +/* + * 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 + * + * 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 _RTPSESSION_H_ +#define _RTPSESSION_H_ + +#include "options.h" +#include "threadUtils.hpp" + +#include +#include + +class RtpSession +{ +public: + RtpSession(const RtpSession & src); + RtpSession(); + +private: + //TODO: check if this is ok + Mutex mutex_; + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int version) + { + Lock lock(mutex_); + } +}; + +#endif 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 + * + * 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 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 + * + * 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 + +#include "threadUtils.hpp" +#include "datatypes.h" +#include "rtpSession.h" +typedef std::map 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 -- cgit v1.2.3