From c20c54ce8fef7f0edbafda26e9a202377f0ac895 Mon Sep 17 00:00:00 2001 From: Othmar Gsenger Date: Sun, 23 Dec 2007 11:18:11 +0000 Subject: added SyncQueue and SyncSocketHandler --- Makefile | 8 +++++++ anytun.cpp | 9 +++++--- syncQueue.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++ syncQueue.h | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ syncSocketHandler.cpp | 37 ++++++++++++++++++++++++++++++++ syncSocketHandler.h | 23 ++++++++++++++++++++ 6 files changed, 186 insertions(+), 3 deletions(-) create mode 100644 syncQueue.cpp create mode 100644 syncQueue.h create mode 100644 syncSocketHandler.cpp create mode 100644 syncSocketHandler.h diff --git a/Makefile b/Makefile index 47d9409..c643e07 100644 --- a/Makefile +++ b/Makefile @@ -64,7 +64,9 @@ OBJS = anytun.o \ router.o \ signalController.o \ syncSocket.o \ + syncSocketHandler.o \ syncClientSocket.o \ + syncQueue.o \ log.o \ options.o \ seqWindow.o \ @@ -114,12 +116,18 @@ mpi.o: mpi.cpp mpi.h syncSocket.o: syncSocket.cpp syncSocket.h $(C++) $(CCFLAGS) $< -c +syncSocketHandler.o: syncSocketHandler.cpp syncSocketHandler.h + $(C++) $(CCFLAGS) $< -c + syncCommand.o: syncCommand.cpp syncCommand.h $(C++) $(CCFLAGS) $< -c syncClientSocket.o: syncClientSocket.cpp syncClientSocket.h $(C++) $(CCFLAGS) $< -c +syncQueue.o: syncQueue.cpp syncQueue.h + $(C++) $(CCFLAGS) $< -c + signalController.o: signalController.cpp signalController.h $(C++) $(CCFLAGS) $< -c diff --git a/anytun.cpp b/anytun.cpp index 69d4a9a..5a0578a 100644 --- a/anytun.cpp +++ b/anytun.cpp @@ -49,7 +49,8 @@ #include "seqWindow.h" #include "connectionList.h" -#include "Sockets/SocketHandler.h" +#include "syncQueue.h" +#include "syncSocketHandler.h" #include "syncListenSocket.h" #include "syncSocket.h" @@ -68,6 +69,7 @@ struct Param TunDevice& dev; PacketSource& src; ConnectionList& cl; + SyncQueue & queue; }; uint8_t key[] = { @@ -236,7 +238,7 @@ void* syncListener(void* p ) { Param* param = reinterpret_cast(p); - SOCKETS_NAMESPACE::SocketHandler h; + SyncSocketHandler h(param->queue); SyncListenSocket l(h,param->cl); if (l.Bind(param->opt.getLocalSyncPort())) @@ -343,8 +345,9 @@ int main(int argc, char* argv[]) if(opt.getRemoteAddr() != "") createConnection(opt.getRemoteAddr(),opt.getRemotePort(),cl,opt.getSeqWindowSize()); + SyncQueue queue; - struct Param p = {opt, dev, *src, cl}; + struct Param p = {opt, dev, *src, cl, queue}; cLog.msg(Log::PRIO_NOTICE) << "dev created (opened)"; cLog.msg(Log::PRIO_NOTICE) << "dev opened - actual name is '" << p.dev.getActualName() << "'"; diff --git a/syncQueue.cpp b/syncQueue.cpp new file mode 100644 index 0000000..ba858ee --- /dev/null +++ b/syncQueue.cpp @@ -0,0 +1,54 @@ +/* + * 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 "syncQueue.h" + +void SyncQueue::push(const std::string & str ) +{ + Lock lock(mutex_); + queue_.push(str); +} + +std::string SyncQueue::pop() +{ + Lock lock(mutex_); + std::string tmp = queue_.front(); + queue_.pop(); + return tmp; +} + +bool SyncQueue::empty() +{ + Lock lock(mutex_); + return queue_.empty(); +} diff --git a/syncQueue.h b/syncQueue.h new file mode 100644 index 0000000..d76565b --- /dev/null +++ b/syncQueue.h @@ -0,0 +1,58 @@ +/* + * 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 _SYNC_QUEUE_H +#define _SYNC_QUEUE_H + +#include +#include + +#include "threadUtils.hpp" +#include "datatypes.h" + +class SyncQueue +{ +public: + SyncQueue() {}; + ~SyncQueue() {}; + + void push(const std::string & ); + std::string pop(); + bool empty(); + +private: + SyncQueue(const SyncQueue &s); + void operator=(const SyncQueue &s); + typedef std::queue StringQueue; + StringQueue queue_; + Mutex mutex_; +}; + +#endif diff --git a/syncSocketHandler.cpp b/syncSocketHandler.cpp new file mode 100644 index 0000000..e5bd6c7 --- /dev/null +++ b/syncSocketHandler.cpp @@ -0,0 +1,37 @@ +//#include +//#include +//#include +// +//#include +//#include + + +//#include "connectionParam.h" +//#include "Sockets/Utility.h" +#include "syncSocketHandler.h" +#include "syncListenSocket.h" +#include "syncSocket.h" +#include "connectionList.h" +//#include "buffer.h" +//#include "log.h" + +SyncSocketHandler::SyncSocketHandler(SyncQueue & queue) +:SocketHandler(),queue_(queue) +{ +} + +int SyncSocketHandler::Select(long sec,long usec) +{ + if(!queue_.empty()) + { + std::string sendstr = queue_.pop(); + for (socket_m::iterator it = m_sockets.begin(); it != m_sockets.end(); it++) + { + Socket *p = (*it).second; + TcpSocket *p3 = dynamic_cast(p); + //SyncListenSocket *p4 = dynamic_cast *>(p); + p3->Send(sendstr); + } + } + return SocketHandler::Select(sec,usec); +} diff --git a/syncSocketHandler.h b/syncSocketHandler.h new file mode 100644 index 0000000..6a666e1 --- /dev/null +++ b/syncSocketHandler.h @@ -0,0 +1,23 @@ +#ifndef _SYNCSOCKETHANDLER_H +#define _SYNCSOCKETHANDLER_H + +#include "Sockets/TcpSocket.h" +#include "Sockets/SocketHandler.h" +#include "syncQueue.h" + +//#ifdef SOCKETS_NAMESPACE +//using namespace SOCKETS_NAMESPACE; +//#endif // SOCKETS_NAMESPACE + +class SyncSocketHandler : public SOCKETS_NAMESPACE::SocketHandler +{ +public: + SyncSocketHandler(SyncQueue & ); + int Select(long sec,long usec); + +private: + SyncQueue & queue_; +}; + + +#endif // _SYNCSOCKET_H -- cgit v1.2.3