From 43424d46fbb74958cd5fc358d57c757b53436585 Mon Sep 17 00:00:00 2001 From: Othmar Gsenger Date: Mon, 12 Jan 2009 20:53:14 +0000 Subject: moved rtp stuff to anyrtpproxy and removed it from anytun --- src/Makefile | 13 +-- src/anyrtpproxy/Makefile | 15 +--- src/anyrtpproxy/anyrtpproxy.cpp | 10 +-- src/anyrtpproxy/commandHandler.cpp | 8 +- src/anyrtpproxy/rtpSession.cpp | 154 ++++++++++++++++++++++++++++++++++++ src/anyrtpproxy/rtpSession.h | 133 +++++++++++++++++++++++++++++++ src/anyrtpproxy/rtpSessionTable.cpp | 123 ++++++++++++++++++++++++++++ src/anyrtpproxy/rtpSessionTable.h | 75 ++++++++++++++++++ src/anyrtpproxy/syncRtpCommand.cpp | 46 +++++++++++ src/anyrtpproxy/syncRtpCommand.h | 61 ++++++++++++++ src/rtpSession.cpp | 154 ------------------------------------ src/rtpSession.h | 133 ------------------------------- src/rtpSessionTable.cpp | 123 ---------------------------- src/rtpSessionTable.h | 75 ------------------ src/syncCommand.cpp | 12 --- src/syncCommand.h | 9 --- src/syncOnConnect.hpp | 14 +--- src/syncRtpCommand.cpp | 46 ----------- src/syncRtpCommand.h | 61 -------------- src/syncTcpConnection.cpp | 41 +++++++--- 20 files changed, 637 insertions(+), 669 deletions(-) create mode 100644 src/anyrtpproxy/rtpSession.cpp create mode 100644 src/anyrtpproxy/rtpSession.h create mode 100644 src/anyrtpproxy/rtpSessionTable.cpp create mode 100644 src/anyrtpproxy/rtpSessionTable.h create mode 100644 src/anyrtpproxy/syncRtpCommand.cpp create mode 100644 src/anyrtpproxy/syncRtpCommand.h delete mode 100644 src/rtpSession.cpp delete mode 100644 src/rtpSession.h delete mode 100644 src/rtpSessionTable.cpp delete mode 100644 src/rtpSessionTable.h delete mode 100644 src/syncRtpCommand.cpp delete mode 100644 src/syncRtpCommand.h diff --git a/src/Makefile b/src/Makefile index 588e876..5d846f1 100644 --- a/src/Makefile +++ b/src/Makefile @@ -71,12 +71,8 @@ OBJS = tunDevice.o \ syncQueue.o \ syncCommand.o \ syncRouteCommand.o \ - syncRtpCommand.o \ syncConnectionCommand.o \ - rtpSessionTable.o \ - rtpSession.o \ routingTreeNode.o \ - anyrtpproxy/callIdQueue.o SYNCOBJS= syncServer.o \ syncClient.o \ @@ -97,11 +93,7 @@ ANYCONFOBJS = log.o \ networkPrefix.o \ connectionList.o \ connectionParam.o \ - rtpSessionTable.o \ - rtpSession.o \ routingTreeNode.o \ - anyrtpproxy/callIdQueue.o \ - syncRtpCommand.o \ anyConfOptions.o \ routingTable.o \ seqWindow.o \ @@ -123,7 +115,7 @@ DEPENDFILE = .depend .PHONY: dep distclean cleanall clean ctags -all: dep $(EXECUTABLE) #libAnysync.a #anyrtpproxy +all: dep $(EXECUTABLE) #libAnysync.a dep: $(SRCS) $(SYNCSRCS) $(ANYCTRSRCS) $(ANYCONFSRCS) $(CC) -MM $(SRCS) $(SYNCSRCS) $(ANYCTRSRCS) $(ANYCONFSRCS) > $(DEPENDFILE) @@ -149,9 +141,6 @@ anytun-config: $(ANYCONFOBJS) anytun-config.o anytun-controld: $(ANYCTROBJS) anytun-controld.o $(LD) $(ANYCTROBJS) anytun-controld.o -o $@ $(LDFLAGS) -anyrtpproxy/callIdQueue.o: - $(MAKE) --directory=$(CURDIR)/anyrtpproxy callIdQueue.o - %.o: %.cpp $(CXX) $(CXXFLAGS) $< -c diff --git a/src/anyrtpproxy/Makefile b/src/anyrtpproxy/Makefile index 90b4645..40ca273 100644 --- a/src/anyrtpproxy/Makefile +++ b/src/anyrtpproxy/Makefile @@ -39,23 +39,14 @@ OBJS = anyrtpproxy.o \ ../signalController.o \ ../log.o \ ../buffer.o \ - ../rtpSessionTable.o \ - ../rtpSession.o \ + rtpSessionTable.o \ + rtpSession.o \ connectionList.o \ ../syncServer.o \ ../syncClient.o \ ../syncTcpConnection.o \ ../syncQueue.o \ - ../seqWindow.o \ - ../connectionParam.o \ - ../routingTable.o \ - ../syncBuffer.o \ - ../syncCommand.o \ - ../syncRouteCommand.o \ - ../syncRtpCommand.o \ - ../syncConnectionCommand.o \ - ../networkAddress.o \ - ../networkPrefix.o \ + syncRtpCommand.o \ commandHandler.o \ portWindow.o \ callIdQueue.o \ diff --git a/src/anyrtpproxy/anyrtpproxy.cpp b/src/anyrtpproxy/anyrtpproxy.cpp index 43b4ef9..fdb809e 100644 --- a/src/anyrtpproxy/anyrtpproxy.cpp +++ b/src/anyrtpproxy/anyrtpproxy.cpp @@ -43,11 +43,11 @@ #include "../signalController.h" #include "../buffer.h" #include "connectionList.h" -#include "../rtpSessionTable.h" -#include "../syncCommand.h" +#include "rtpSessionTable.h" +#include "syncRtpCommand.h" #include "../syncQueue.h" #include "../syncClient.h" -//#include "../syncOnConnect.h" +#include "syncOnConnect.hpp" #include "../threadUtils.hpp" @@ -104,7 +104,7 @@ void listener(RtpSession::proto::socket* sock1, RtpSession::proto::socket* sock2 session.setRemoteEnd2(remote_end); if(!gOpt.getNat()) { // with nat enabled sync is not needed - SyncCommand sc(call_id); + SyncRtpCommand sc(call_id); queue->push(sc); } } @@ -296,7 +296,7 @@ void syncListener(SyncQueue * queue) SyncServer server(io_service,e); -// server.onConnect=boost::bind(syncOnConnect,_1); + server.onConnect=boost::bind(syncOnConnect,_1); queue->setSyncServerPtr(&server); io_service.run(); } diff --git a/src/anyrtpproxy/commandHandler.cpp b/src/anyrtpproxy/commandHandler.cpp index c8604d6..01613ec 100644 --- a/src/anyrtpproxy/commandHandler.cpp +++ b/src/anyrtpproxy/commandHandler.cpp @@ -42,8 +42,8 @@ #include "../buffer.h" #include "../log.h" #include "../syncQueue.h" -#include "../syncCommand.h" -#include "../rtpSessionTable.h" +#include "syncRtpCommand.h" +#include "rtpSessionTable.h" #include "callIdQueue.h" #include "options.h" @@ -231,7 +231,7 @@ string CommandHandler::handleResponse(string modifiers, string call_id, string a RtpSession::proto::resolver::query query(addr,port); session.setRemoteEnd2(*resolver.resolve(query)); session.isComplete(true); - SyncCommand sc(call_id); + SyncRtpCommand sc(call_id); queue_.push(sc); ostringstream oss; @@ -252,7 +252,7 @@ string CommandHandler::handleDelete(string call_id, string from_tag, string to_t { RtpSession& session = gRtpSessionTable.getSession(call_id); session.isDead(true); - SyncCommand sc(call_id); + SyncRtpCommand sc(call_id); queue_.push(sc); return RET_OK; diff --git a/src/anyrtpproxy/rtpSession.cpp b/src/anyrtpproxy/rtpSession.cpp new file mode 100644 index 0000000..a3551e3 --- /dev/null +++ b/src/anyrtpproxy/rtpSession.cpp @@ -0,0 +1,154 @@ +/* + * 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-2008 Othmar Gsenger, Erwin Nindl, + * Christian Pointner + * + * This file is part of Anytun. + * + * Anytun is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * Anytun 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 anytun. If not, see . + */ + +#include "rtpSession.h" + +#include "callIdQueue.h" + +RtpSession::RtpSession(const std::string& call_id) : in_sync_(false), call_id_(call_id) , dead_(false), complete_(false), + seen1_(false), seen2_(false) +{ +} + +void RtpSession::reinit() +{ + gCallIdQueue.push(call_id_); +} + +bool RtpSession::isDead() +{ + Lock lock(mutex_); + return (dead_ && in_sync_); +} + +bool RtpSession::isDead(bool d) +{ + Lock Lock(mutex_); + return dead_ = d; +} + +bool RtpSession::isComplete() +{ + Lock lock(mutex_); + return complete_; +} + +bool RtpSession::isComplete(bool c) +{ + Lock lock(mutex_); + return complete_ = c; +} + +bool RtpSession::getSeen1() +{ + Lock lock(mutex_); + return seen1_; +} + +RtpSession& RtpSession::setSeen1() +{ + Lock lock(mutex_); + //in_sync_ = false; + seen1_ = true; + return *this; +} + +bool RtpSession::getSeen2() +{ + Lock lock(mutex_); + return seen2_; +} + +RtpSession& RtpSession::setSeen2() +{ + Lock lock(mutex_); + //in_sync_ = false; + seen2_ = true; + return *this; +} + +RtpSession::proto::endpoint RtpSession::getLocalEnd1() +{ + Lock lock(mutex_); + return local_end1_; +} + +RtpSession& RtpSession::setLocalEnd1(RtpSession::proto::endpoint e) +{ + Lock lock(mutex_); + in_sync_ = false; + local_end1_ = e; + return *this; +} + +RtpSession::proto::endpoint RtpSession::getLocalEnd2() +{ + Lock lock(mutex_); + return local_end2_; +} + +RtpSession& RtpSession::setLocalEnd2(RtpSession::proto::endpoint e) +{ + Lock lock(mutex_); + in_sync_ = false; + local_end2_ = e; + return *this; +} + +RtpSession::proto::endpoint RtpSession::getRemoteEnd1() +{ + Lock lock(mutex_); + return remote_end1_; +} + +RtpSession& RtpSession::setRemoteEnd1(RtpSession::proto::endpoint e) +{ + Lock lock(mutex_); + in_sync_ = false; + remote_end1_ = e; + return *this; +} + +RtpSession::proto::endpoint RtpSession::getRemoteEnd2() +{ + Lock lock(mutex_); + return remote_end2_; +} + +RtpSession& RtpSession::setRemoteEnd2(RtpSession::proto::endpoint e) +{ + Lock lock(mutex_); + in_sync_ = false; + remote_end2_ = e; + return *this; +} + + diff --git a/src/anyrtpproxy/rtpSession.h b/src/anyrtpproxy/rtpSession.h new file mode 100644 index 0000000..3716c9b --- /dev/null +++ b/src/anyrtpproxy/rtpSession.h @@ -0,0 +1,133 @@ +/* + * 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-2008 Othmar Gsenger, Erwin Nindl, + * Christian Pointner + * + * This file is part of Anytun. + * + * Anytun is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * Anytun 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 anytun. If not, see . + */ + +#ifndef _RTPSESSION_H_ +#define _RTPSESSION_H_ + +#include + +#include "../threadUtils.hpp" + +#include +#include + +class RtpSession +{ +public: + typedef boost::asio::ip::udp proto; + + RtpSession(const std::string& call_id); + + bool isDead(); + bool isDead(bool d); + + bool isComplete(); + bool isComplete(bool c); + + proto::endpoint getLocalEnd1(); + RtpSession& setLocalEnd1(proto::endpoint e); + proto::endpoint getLocalEnd2(); + RtpSession& setLocalEnd2(proto::endpoint e); + + proto::endpoint getRemoteEnd1(); + RtpSession& setRemoteEnd1(proto::endpoint e); + proto::endpoint getRemoteEnd2(); + RtpSession& setRemoteEnd2(proto::endpoint e); + + RtpSession& setSeen1(); + bool getSeen1(); + + RtpSession& setSeen2(); + bool getSeen2(); + +private: + RtpSession(const RtpSession & src); + + void reinit(); + + //TODO: check if this is ok + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int version) + { + Lock lock(mutex_); + + // address of local_end1 and local_end2 are always equal + std::string local_addr(local_end1_.address().to_string()); + u_int16_t local_port1 = local_end1_.port(); + u_int16_t local_port2 = local_end2_.port(); + + std::string remote_addr1(remote_end1_.address().to_string()); + u_int16_t remote_port1 = remote_end1_.port(); + std::string remote_addr2(remote_end2_.address().to_string()); + u_int16_t remote_port2 = remote_end2_.port(); + + ar & dead_; + ar & complete_; + ar & local_addr; + ar & local_port1; + ar & local_port2; + ar & remote_addr1; + ar & remote_port1; + ar & remote_addr2; + ar & remote_port2; + ar & seen1_; + ar & seen2_; + + proto::endpoint local_end1(boost::asio::ip::address::from_string(local_addr), local_port1); + local_end1_ = local_end1; + proto::endpoint local_end2(boost::asio::ip::address::from_string(local_addr), local_port2); + local_end2_ = local_end2; + + proto::endpoint remote_end1(boost::asio::ip::address::from_string(remote_addr1), remote_port1); + remote_end1_ = remote_end1; + proto::endpoint remote_end2(boost::asio::ip::address::from_string(remote_addr2), remote_port2); + remote_end2_ = remote_end2; + + if(complete_ && !dead_) + reinit(); + + in_sync_ = true; + } + + bool in_sync_; + ::Mutex mutex_; + + const std::string& call_id_; + bool dead_; + bool complete_; + proto::endpoint local_end1_, local_end2_; + proto::endpoint remote_end1_, remote_end2_; + bool seen1_,seen2_; //has at least 1 packet been recieved? +}; + + +#endif diff --git a/src/anyrtpproxy/rtpSessionTable.cpp b/src/anyrtpproxy/rtpSessionTable.cpp new file mode 100644 index 0000000..9237866 --- /dev/null +++ b/src/anyrtpproxy/rtpSessionTable.cpp @@ -0,0 +1,123 @@ +/* + * 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-2008 Othmar Gsenger, Erwin Nindl, + * Christian Pointner + * + * This file is part of Anytun. + * + * Anytun is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * Anytun 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 anytun. If not, see . + */ +#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::delSession(const std::string & call_id) +{ + Lock lock(mutex_); + + RtpSessionMap::iterator it = map_.find(call_id); + if(it!=map_.end()) + delete it->second; + + map_.erase(it); +} + +RtpSession& RtpSessionTable::getOrNewSession(const std::string & call_id, bool& is_new) +{ + Lock lock(mutex_); + return getOrNewSessionUnlocked(call_id, is_new); +} + +RtpSession& RtpSessionTable::getOrNewSessionUnlocked(const std::string & call_id, bool& is_new) +{ + is_new = false; + RtpSessionMap::iterator it = map_.find(call_id); + if(it!=map_.end()) + return *(it->second); + + is_new = true; + std::pair ret = map_.insert(RtpSessionMap::value_type(call_id, NULL)); + ret.first->second = new RtpSession(ret.first->first); + return *(ret.first->second); +} + +RtpSession& RtpSessionTable::getSession(const std::string & call_id) +{ + RtpSessionMap::iterator it = map_.find(call_id); + if(it!=map_.end()) + return *(it->second); + + throw std::runtime_error("session not found"); +} + +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/src/anyrtpproxy/rtpSessionTable.h b/src/anyrtpproxy/rtpSessionTable.h new file mode 100644 index 0000000..a37318d --- /dev/null +++ b/src/anyrtpproxy/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-2008 Othmar Gsenger, Erwin Nindl, + * Christian Pointner + * + * This file is part of Anytun. + * + * Anytun is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * Anytun 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 anytun. If not, see . + */ + +#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 delSession(const std::string & call_id); + bool empty(); + void clear(); + ::Mutex& getMutex(); + RtpSessionMap::iterator getBeginUnlocked(); + RtpSessionMap::iterator getEndUnlocked(); + RtpSession& getOrNewSession(const std::string & call_id, bool& isnew); + RtpSession& getOrNewSessionUnlocked(const std::string & call_id, bool& isnew); + RtpSession& getSession(const std::string & call_id); + +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 diff --git a/src/anyrtpproxy/syncRtpCommand.cpp b/src/anyrtpproxy/syncRtpCommand.cpp new file mode 100644 index 0000000..f612c8a --- /dev/null +++ b/src/anyrtpproxy/syncRtpCommand.cpp @@ -0,0 +1,46 @@ +/* + * 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-2008 Othmar Gsenger, Erwin Nindl, + * Christian Pointner + * + * This file is part of Anytun. + * + * Anytun is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * Anytun 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 anytun. If not, see . + */ +#include "syncRtpCommand.h" + +SyncRtpCommand::SyncRtpCommand() +{ +} + +SyncRtpCommand::SyncRtpCommand( const std::string & addr ) +:callid_(addr) +{ +} + + +std::string SyncRtpCommand::getCallId() const +{ + return callid_; +} diff --git a/src/anyrtpproxy/syncRtpCommand.h b/src/anyrtpproxy/syncRtpCommand.h new file mode 100644 index 0000000..282243b --- /dev/null +++ b/src/anyrtpproxy/syncRtpCommand.h @@ -0,0 +1,61 @@ +/* + * 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-2008 Othmar Gsenger, Erwin Nindl, + * Christian Pointner + * + * This file is part of Anytun. + * + * Anytun is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * Anytun 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 anytun. If not, see . + */ +#ifndef _SYNCRTPCOMMAND_H +#define _SYNCRTPCOMMAND_H +#include +#include + +#include "../threadUtils.hpp" +#include "rtpSessionTable.h" + +class SyncRtpCommand +{ +public: + SyncRtpCommand(const std::string & ); + SyncRtpCommand(); + std::string getCallId() const; + +private: + SyncRtpCommand(const SyncRtpCommand &); + std::string callid_; + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int version) + { + Lock lock(gRtpSessionTable.getMutex()); + ar & callid_; + bool is_new; + ar & gRtpSessionTable.getOrNewSessionUnlocked(callid_, is_new); + }; +}; + + +#endif // _SYNCCOMMAND_H diff --git a/src/rtpSession.cpp b/src/rtpSession.cpp deleted file mode 100644 index b3e688b..0000000 --- a/src/rtpSession.cpp +++ /dev/null @@ -1,154 +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-2008 Othmar Gsenger, Erwin Nindl, - * Christian Pointner - * - * This file is part of Anytun. - * - * Anytun is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 3 as - * published by the Free Software Foundation. - * - * Anytun 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 anytun. If not, see . - */ - -#include "rtpSession.h" - -#include "anyrtpproxy/callIdQueue.h" - -RtpSession::RtpSession(const std::string& call_id) : in_sync_(false), call_id_(call_id) , dead_(false), complete_(false), - seen1_(false), seen2_(false) -{ -} - -void RtpSession::reinit() -{ - gCallIdQueue.push(call_id_); -} - -bool RtpSession::isDead() -{ - Lock lock(mutex_); - return (dead_ && in_sync_); -} - -bool RtpSession::isDead(bool d) -{ - Lock Lock(mutex_); - return dead_ = d; -} - -bool RtpSession::isComplete() -{ - Lock lock(mutex_); - return complete_; -} - -bool RtpSession::isComplete(bool c) -{ - Lock lock(mutex_); - return complete_ = c; -} - -bool RtpSession::getSeen1() -{ - Lock lock(mutex_); - return seen1_; -} - -RtpSession& RtpSession::setSeen1() -{ - Lock lock(mutex_); - //in_sync_ = false; - seen1_ = true; - return *this; -} - -bool RtpSession::getSeen2() -{ - Lock lock(mutex_); - return seen2_; -} - -RtpSession& RtpSession::setSeen2() -{ - Lock lock(mutex_); - //in_sync_ = false; - seen2_ = true; - return *this; -} - -RtpSession::proto::endpoint RtpSession::getLocalEnd1() -{ - Lock lock(mutex_); - return local_end1_; -} - -RtpSession& RtpSession::setLocalEnd1(RtpSession::proto::endpoint e) -{ - Lock lock(mutex_); - in_sync_ = false; - local_end1_ = e; - return *this; -} - -RtpSession::proto::endpoint RtpSession::getLocalEnd2() -{ - Lock lock(mutex_); - return local_end2_; -} - -RtpSession& RtpSession::setLocalEnd2(RtpSession::proto::endpoint e) -{ - Lock lock(mutex_); - in_sync_ = false; - local_end2_ = e; - return *this; -} - -RtpSession::proto::endpoint RtpSession::getRemoteEnd1() -{ - Lock lock(mutex_); - return remote_end1_; -} - -RtpSession& RtpSession::setRemoteEnd1(RtpSession::proto::endpoint e) -{ - Lock lock(mutex_); - in_sync_ = false; - remote_end1_ = e; - return *this; -} - -RtpSession::proto::endpoint RtpSession::getRemoteEnd2() -{ - Lock lock(mutex_); - return remote_end2_; -} - -RtpSession& RtpSession::setRemoteEnd2(RtpSession::proto::endpoint e) -{ - Lock lock(mutex_); - in_sync_ = false; - remote_end2_ = e; - return *this; -} - - diff --git a/src/rtpSession.h b/src/rtpSession.h deleted file mode 100644 index 1aec46f..0000000 --- a/src/rtpSession.h +++ /dev/null @@ -1,133 +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-2008 Othmar Gsenger, Erwin Nindl, - * Christian Pointner - * - * This file is part of Anytun. - * - * Anytun is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 3 as - * published by the Free Software Foundation. - * - * Anytun 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 anytun. If not, see . - */ - -#ifndef _RTPSESSION_H_ -#define _RTPSESSION_H_ - -#include - -#include "threadUtils.hpp" - -#include -#include - -class RtpSession -{ -public: - typedef boost::asio::ip::udp proto; - - RtpSession(const std::string& call_id); - - bool isDead(); - bool isDead(bool d); - - bool isComplete(); - bool isComplete(bool c); - - proto::endpoint getLocalEnd1(); - RtpSession& setLocalEnd1(proto::endpoint e); - proto::endpoint getLocalEnd2(); - RtpSession& setLocalEnd2(proto::endpoint e); - - proto::endpoint getRemoteEnd1(); - RtpSession& setRemoteEnd1(proto::endpoint e); - proto::endpoint getRemoteEnd2(); - RtpSession& setRemoteEnd2(proto::endpoint e); - - RtpSession& setSeen1(); - bool getSeen1(); - - RtpSession& setSeen2(); - bool getSeen2(); - -private: - RtpSession(const RtpSession & src); - - void reinit(); - - //TODO: check if this is ok - friend class boost::serialization::access; - template - void serialize(Archive & ar, const unsigned int version) - { - Lock lock(mutex_); - - // address of local_end1 and local_end2 are always equal - std::string local_addr(local_end1_.address().to_string()); - u_int16_t local_port1 = local_end1_.port(); - u_int16_t local_port2 = local_end2_.port(); - - std::string remote_addr1(remote_end1_.address().to_string()); - u_int16_t remote_port1 = remote_end1_.port(); - std::string remote_addr2(remote_end2_.address().to_string()); - u_int16_t remote_port2 = remote_end2_.port(); - - ar & dead_; - ar & complete_; - ar & local_addr; - ar & local_port1; - ar & local_port2; - ar & remote_addr1; - ar & remote_port1; - ar & remote_addr2; - ar & remote_port2; - ar & seen1_; - ar & seen2_; - - proto::endpoint local_end1(boost::asio::ip::address::from_string(local_addr), local_port1); - local_end1_ = local_end1; - proto::endpoint local_end2(boost::asio::ip::address::from_string(local_addr), local_port2); - local_end2_ = local_end2; - - proto::endpoint remote_end1(boost::asio::ip::address::from_string(remote_addr1), remote_port1); - remote_end1_ = remote_end1; - proto::endpoint remote_end2(boost::asio::ip::address::from_string(remote_addr2), remote_port2); - remote_end2_ = remote_end2; - - if(complete_ && !dead_) - reinit(); - - in_sync_ = true; - } - - bool in_sync_; - ::Mutex mutex_; - - const std::string& call_id_; - bool dead_; - bool complete_; - proto::endpoint local_end1_, local_end2_; - proto::endpoint remote_end1_, remote_end2_; - bool seen1_,seen2_; //has at least 1 packet been recieved? -}; - - -#endif diff --git a/src/rtpSessionTable.cpp b/src/rtpSessionTable.cpp deleted file mode 100644 index b751a50..0000000 --- a/src/rtpSessionTable.cpp +++ /dev/null @@ -1,123 +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-2008 Othmar Gsenger, Erwin Nindl, - * Christian Pointner - * - * This file is part of Anytun. - * - * Anytun is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 3 as - * published by the Free Software Foundation. - * - * Anytun 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 anytun. If not, see . - */ -#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::delSession(const std::string & call_id) -{ - Lock lock(mutex_); - - RtpSessionMap::iterator it = map_.find(call_id); - if(it!=map_.end()) - delete it->second; - - map_.erase(it); -} - -RtpSession& RtpSessionTable::getOrNewSession(const std::string & call_id, bool& is_new) -{ - Lock lock(mutex_); - return getOrNewSessionUnlocked(call_id, is_new); -} - -RtpSession& RtpSessionTable::getOrNewSessionUnlocked(const std::string & call_id, bool& is_new) -{ - is_new = false; - RtpSessionMap::iterator it = map_.find(call_id); - if(it!=map_.end()) - return *(it->second); - - is_new = true; - std::pair ret = map_.insert(RtpSessionMap::value_type(call_id, NULL)); - ret.first->second = new RtpSession(ret.first->first); - return *(ret.first->second); -} - -RtpSession& RtpSessionTable::getSession(const std::string & call_id) -{ - RtpSessionMap::iterator it = map_.find(call_id); - if(it!=map_.end()) - return *(it->second); - - throw std::runtime_error("session not found"); -} - -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/src/rtpSessionTable.h b/src/rtpSessionTable.h deleted file mode 100644 index 3574723..0000000 --- a/src/rtpSessionTable.h +++ /dev/null @@ -1,75 +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-2008 Othmar Gsenger, Erwin Nindl, - * Christian Pointner - * - * This file is part of Anytun. - * - * Anytun is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 3 as - * published by the Free Software Foundation. - * - * Anytun 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 anytun. If not, see . - */ - -#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 delSession(const std::string & call_id); - bool empty(); - void clear(); - ::Mutex& getMutex(); - RtpSessionMap::iterator getBeginUnlocked(); - RtpSessionMap::iterator getEndUnlocked(); - RtpSession& getOrNewSession(const std::string & call_id, bool& isnew); - RtpSession& getOrNewSessionUnlocked(const std::string & call_id, bool& isnew); - RtpSession& getSession(const std::string & call_id); - -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 diff --git a/src/syncCommand.cpp b/src/syncCommand.cpp index 94f295c..48bed3a 100644 --- a/src/syncCommand.cpp +++ b/src/syncCommand.cpp @@ -34,28 +34,18 @@ SyncCommand::SyncCommand(ConnectionList & cl ) { scc_ = new SyncConnectionCommand(cl); src_ = new SyncRouteCommand(); - srtpc_ = new SyncRtpCommand(); } SyncCommand::SyncCommand(ConnectionList & cl, u_int16_t mux ) { scc_ = new SyncConnectionCommand(cl,mux); src_=NULL; - srtpc_=NULL; } SyncCommand::SyncCommand(NetworkPrefix np ) { scc_ = NULL; src_ = new SyncRouteCommand(np); - srtpc_=NULL; -} - -SyncCommand::SyncCommand(const std::string & callid ) -{ - scc_ = NULL; - src_ = NULL; - srtpc_= new SyncRtpCommand(callid); } SyncCommand::~SyncCommand() @@ -64,6 +54,4 @@ SyncCommand::~SyncCommand() delete scc_; if (src_) delete src_; - if (srtpc_) - delete srtpc_; } diff --git a/src/syncCommand.h b/src/syncCommand.h index 5059693..9f0ef2a 100644 --- a/src/syncCommand.h +++ b/src/syncCommand.h @@ -37,7 +37,6 @@ #include "threadUtils.hpp" #include "syncConnectionCommand.h" #include "syncRouteCommand.h" -#include "syncRtpCommand.h" #include "networkPrefix.h" #include @@ -46,7 +45,6 @@ class SyncCommand public: SyncCommand(ConnectionList & cl ); SyncCommand(ConnectionList & cl ,u_int16_t mux); - SyncCommand(const std::string &); SyncCommand(NetworkPrefix); ~SyncCommand(); @@ -54,7 +52,6 @@ private: SyncCommand(const SyncCommand &); SyncConnectionCommand * scc_; SyncRouteCommand * src_; - SyncRtpCommand * srtpc_; friend class boost::serialization::access; template void serialize(Archive & ar, const unsigned int version) @@ -68,18 +65,12 @@ private: { syncstr = "route"; } - if ( srtpc_) - { - syncstr = "rtp"; - } ar & syncstr; // std::cout << "syncstr received " <Send(sout.str()); } } - //TODO Locking here - RtpSessionMap::iterator rit = gRtpSessionTable.getBeginUnlocked(); - for (;rit!=gRtpSessionTable.getEndUnlocked();++rit) - { - std::ostringstream sout; - boost::archive::text_oarchive oa(sout); - const SyncCommand scom(rit->first); - oa << scom; - std::stringstream lengthout; - lengthout << std::setw(5) << std::setfill('0') << sout.str().size()<< ' '; - connptr->Send(lengthout.str()); - connptr->Send(sout.str()); - } } diff --git a/src/syncRtpCommand.cpp b/src/syncRtpCommand.cpp deleted file mode 100644 index f612c8a..0000000 --- a/src/syncRtpCommand.cpp +++ /dev/null @@ -1,46 +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-2008 Othmar Gsenger, Erwin Nindl, - * Christian Pointner - * - * This file is part of Anytun. - * - * Anytun is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 3 as - * published by the Free Software Foundation. - * - * Anytun 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 anytun. If not, see . - */ -#include "syncRtpCommand.h" - -SyncRtpCommand::SyncRtpCommand() -{ -} - -SyncRtpCommand::SyncRtpCommand( const std::string & addr ) -:callid_(addr) -{ -} - - -std::string SyncRtpCommand::getCallId() const -{ - return callid_; -} diff --git a/src/syncRtpCommand.h b/src/syncRtpCommand.h deleted file mode 100644 index d178e00..0000000 --- a/src/syncRtpCommand.h +++ /dev/null @@ -1,61 +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-2008 Othmar Gsenger, Erwin Nindl, - * Christian Pointner - * - * This file is part of Anytun. - * - * Anytun is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 3 as - * published by the Free Software Foundation. - * - * Anytun 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 anytun. If not, see . - */ -#ifndef _SYNCRTPCOMMAND_H -#define _SYNCRTPCOMMAND_H -#include -#include - -#include "threadUtils.hpp" -#include "rtpSessionTable.h" - -class SyncRtpCommand -{ -public: - SyncRtpCommand(const std::string & ); - SyncRtpCommand(); - std::string getCallId() const; - -private: - SyncRtpCommand(const SyncRtpCommand &); - std::string callid_; - friend class boost::serialization::access; - template - void serialize(Archive & ar, const unsigned int version) - { - Lock lock(gRtpSessionTable.getMutex()); - ar & callid_; - bool is_new; - ar & gRtpSessionTable.getOrNewSessionUnlocked(callid_, is_new); - }; -}; - - -#endif // _SYNCCOMMAND_H diff --git a/src/syncTcpConnection.cpp b/src/syncTcpConnection.cpp index df6f59f..17d3ddd 100644 --- a/src/syncTcpConnection.cpp +++ b/src/syncTcpConnection.cpp @@ -1,18 +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-2008 Othmar Gsenger, Erwin Nindl, + * Christian Pointner + * + * This file is part of Anytun. + * + * Anytun is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * Anytun 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 anytun. If not, see . + */ + #include "syncTcpConnection.h" #include #include -#include -#include #include -#include "routingTable.h" -#include "rtpSessionTable.h" -#include -#include - - -#include "syncCommand.h" -#include "buffer.h" SyncTcpConnection::proto::socket& SyncTcpConnection::socket() { -- cgit v1.2.3