summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOthmar Gsenger <otti@anytun.org>2007-12-23 11:18:11 +0000
committerOthmar Gsenger <otti@anytun.org>2007-12-23 11:18:11 +0000
commitc20c54ce8fef7f0edbafda26e9a202377f0ac895 (patch)
treee9f2f216e0566455058082f3b9bed934b02b5dd7
parentfixed sender (no packets error) (diff)
added SyncQueue and SyncSocketHandler
-rw-r--r--Makefile8
-rw-r--r--anytun.cpp9
-rw-r--r--syncQueue.cpp54
-rw-r--r--syncQueue.h58
-rw-r--r--syncSocketHandler.cpp37
-rw-r--r--syncSocketHandler.h23
6 files changed, 186 insertions, 3 deletions
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<Param*>(p);
- SOCKETS_NAMESPACE::SocketHandler h;
+ SyncSocketHandler h(param->queue);
SyncListenSocket<SyncSocket,ConnectionList> 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 <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 "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 <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 _SYNC_QUEUE_H
+#define _SYNC_QUEUE_H
+
+#include <deque>
+#include <queue>
+
+#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<std::string> 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 <sstream>
+//#include <iostream>
+//#include <string>
+//
+//#include <boost/archive/text_oarchive.hpp>
+//#include <boost/archive/text_iarchive.hpp>
+
+
+//#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<TcpSocket *>(p);
+ //SyncListenSocket<SyncSocket,ConnectionList> *p4 = dynamic_cast<SyncListenSocket<SyncSocket,ConnectionList> *>(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