summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile5
-rw-r--r--src/anytun.cpp49
-rw-r--r--src/syncClient.cpp3
-rw-r--r--src/syncClient.h5
-rw-r--r--src/syncQueue.cpp15
-rw-r--r--src/syncQueue.h12
-rw-r--r--src/threadParam.h6
7 files changed, 61 insertions, 34 deletions
diff --git a/src/Makefile b/src/Makefile
index 5d846f1..793f29c 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -68,7 +68,6 @@ OBJS = tunDevice.o \
log.o \
options.o \
seqWindow.o \
- syncQueue.o \
syncCommand.o \
syncRouteCommand.o \
syncConnectionCommand.o \
@@ -76,6 +75,7 @@ OBJS = tunDevice.o \
SYNCOBJS= syncServer.o \
syncClient.o \
+ syncQueue.o \
syncTcpConnection.o
ANYCTROBJS = signalController.o \
@@ -132,6 +132,9 @@ anytun-static: $(OBJS) $(SYNCOBJS) anytun.o
anytun-nosync: $(OBJS) anytun-nosync.o
$(LD) $(OBJS) anytun-nosync.o -o $@ $(LDFLAGS)
+anytun-nosync.o: anytun.cpp anytun.o
+ $(CXX) $(CXXFLAGS) -DANYTUN_NOSYNC $< -c -o anytun-nosync.o
+
anytun-showtables: $(OBJS) $(SYNCOBJS) anytun-showtables.o
$(LD) $(OBJS) $(SYNCOBJS) anytun-showtables.o -o $@ $(LDFLAGS)
diff --git a/src/anytun.cpp b/src/anytun.cpp
index e995fa8..f7f9358 100644
--- a/src/anytun.cpp
+++ b/src/anytun.cpp
@@ -64,10 +64,10 @@
#include "networkAddress.h"
#endif
-#include "syncQueue.h"
-#include "syncCommand.h"
#ifndef ANYTUN_NOSYNC
+#include "syncQueue.h"
+#include "syncCommand.h"
#include "syncServer.h"
#include "syncClient.h"
#include "syncOnConnect.hpp"
@@ -84,7 +84,7 @@
#define SESSION_KEYLEN_ENCR 16 // TODO: hardcoded size
#define SESSION_KEYLEN_SALT 14 // TODO: hardcoded size
-void createConnection(const PacketSourceEndpoint & remote_end, ConnectionList & cl, window_size_t seqSize, SyncQueue & queue, mux_t mux)
+void createConnection(const PacketSourceEndpoint & remote_end, window_size_t seqSize, mux_t mux)
{
SeqWindow * seq= new SeqWindow(seqSize);
seq_nr_t seq_nr_=0;
@@ -93,17 +93,21 @@ void createConnection(const PacketSourceEndpoint & remote_end, ConnectionList &
cLog.msg(Log::PRIO_NOTICE) << "added connection remote host " << remote_end;
ConnectionParam connparam ( (*kd), (*seq), seq_nr_, remote_end);
- cl.addConnection(connparam,mux);
- SyncCommand sc (cl,mux);
- queue.push(sc);
+ gConnectionList.addConnection(connparam,mux);
+#ifndef ANYTUN_NOSYNC
+ SyncCommand sc (gConnectionList,mux);
+ gSyncQueue.push(sc);
+#endif
#ifndef NOROUTING
if (gOpt.getIfconfigParamRemoteNetmask() != "")
{
NetworkAddress addr(gOpt.getIfconfigParamRemoteNetmask());
NetworkPrefix prefix(addr,128);
gRoutingTable.addRoute(prefix,mux);
- SyncCommand sc2 (prefix);
- queue.push(sc2);
+#ifndef ANYTUN_NOSYNC
+ SyncCommand sc2 (prefix);
+ gSyncQueue.push(sc2);
+#endif
}
#endif
}
@@ -158,7 +162,7 @@ void sender(void* p)
else
plain_packet.setPayloadType(0);
- if(param->cl.empty())
+ if(gConnectionList.empty())
continue;
//std::cout << "got Packet for plain "<<plain_packet.getDstAddr().toString();
ConnectionMap::iterator cit;
@@ -167,17 +171,17 @@ void sender(void* p)
{
mux = gRoutingTable.getRoute(plain_packet.getDstAddr());
//std::cout << " -> "<<mux << std::endl;
- cit = param->cl.getConnection(mux);
+ cit = gConnectionList.getConnection(mux);
}
catch (std::exception& e)
{
continue; // no route
}
#else
- cit = param->cl.getBegin();
+ cit = gConnectionList.getBegin();
#endif
- if(cit==param->cl.getEnd())
+ if(cit==gConnectionList.getEnd())
continue; //no connection
ConnectionParam & conn = cit->second;
@@ -298,14 +302,14 @@ void receiver(void* p)
mux_t mux = encrypted_packet.getMux();
// autodetect peer
- if( param->cl.empty() && gOpt.getRemoteAddr() == "")
+ if( gConnectionList.empty() && gOpt.getRemoteAddr() == "")
{
cLog.msg(Log::PRIO_NOTICE) << "autodetected remote host " << remote_end;
- createConnection(remote_end, param->cl, gOpt.getSeqWindowSize(),param->queue,mux);
+ createConnection(remote_end, gOpt.getSeqWindowSize(),mux);
}
- ConnectionMap::iterator cit = param->cl.getConnection(mux);
- if (cit == param->cl.getEnd())
+ ConnectionMap::iterator cit = gConnectionList.getConnection(mux);
+ if (cit == gConnectionList.getEnd())
continue;
ConnectionParam & conn = cit->second;
@@ -327,8 +331,10 @@ void receiver(void* p)
{
cLog.msg(Log::PRIO_NOTICE) << "connection "<< mux << " autodetected remote host ip changed " << remote_end;
conn.remote_end_=remote_end;
- SyncCommand sc (param->cl,mux);
- param->queue.push(sc);
+#ifndef ANYTUN_NOSYNC
+ SyncCommand sc (gConnectionList,mux);
+ gSyncQueue.push(sc);
+#endif
}
// Replay Protection
@@ -404,7 +410,6 @@ int main(int argc, char* argv[])
else
src = new UDPPacketSource(gOpt.getLocalAddr(), gOpt.getLocalPort());
- ConnectionList & cl (gConnectionList);
ConnectToList connect_to = gOpt.getConnectTo();
SyncQueue queue;
@@ -414,7 +419,7 @@ int main(int argc, char* argv[])
UDPPacketSource::proto::resolver resolver(io_service);
UDPPacketSource::proto::resolver::query query(gOpt.getRemoteAddr(), gOpt.getRemotePort());
UDPPacketSource::proto::endpoint endpoint = *resolver.resolve(query);
- createConnection(endpoint,cl,gOpt.getSeqWindowSize(), queue, gOpt.getMux());
+ createConnection(endpoint,gOpt.getSeqWindowSize(), gOpt.getMux());
}
RouteList routes = gOpt.getRoutes();
@@ -456,7 +461,7 @@ int main(int argc, char* argv[])
sig.init();
#endif
- ThreadParam p(dev, *src, cl, queue,*(new OptionConnectTo()));
+ ThreadParam p(dev, *src, *(new OptionConnectTo()));
#ifndef NOCRYPT
// this must be called before any other libgcrypt call
@@ -475,7 +480,7 @@ int main(int argc, char* argv[])
std::list<boost::thread *> connectThreads;
for(ConnectToList::iterator it = connect_to.begin() ;it != connect_to.end(); ++it) {
- ThreadParam * point = new ThreadParam(dev, *src, cl, queue,*it);
+ ThreadParam * point = new ThreadParam(dev, *src, *it);
connectThreads.push_back(new boost::thread(boost::bind(syncConnector,point)));
}
#endif
diff --git a/src/syncClient.cpp b/src/syncClient.cpp
index 2cc1f91..df99b83 100644
--- a/src/syncClient.cpp
+++ b/src/syncClient.cpp
@@ -31,13 +31,14 @@
#include <sstream>
#include <iostream>
#include <string>
+#include "connectionList.h"
+#include "syncCommand.h"
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include "log.h"
-//#include "connectionParam.h"
#include "syncClient.h"
#include "syncTcpConnection.h"
#include "buffer.h"
diff --git a/src/syncClient.h b/src/syncClient.h
index 26c946f..08b3015 100644
--- a/src/syncClient.h
+++ b/src/syncClient.h
@@ -31,12 +31,7 @@
#ifndef _SYNCCLIENT_H
#define _SYNCCLIENT_H
-#include "connectionList.h"
-#include "syncCommand.h"
-#include <sstream>
-#include <iostream>
#include <string>
-//#include <boost/asio.hpp>
#include "syncTcpConnection.h"
class SyncClient
{
diff --git a/src/syncQueue.cpp b/src/syncQueue.cpp
index d90caaf..636107b 100644
--- a/src/syncQueue.cpp
+++ b/src/syncQueue.cpp
@@ -42,6 +42,21 @@
#include "syncQueue.h"
+SyncQueue* SyncQueue::inst = NULL;
+Mutex SyncQueue::instMutex;
+SyncQueue& gSyncQueue = SyncQueue::instance();
+
+
+SyncQueue& SyncQueue::instance()
+{
+ Lock lock(instMutex);
+ static instanceCleaner c;
+ if(!inst)
+ inst = new SyncQueue();
+
+ return *inst;
+}
+
void SyncQueue::push(const SyncCommand & scom )
{
std::ostringstream sout;
diff --git a/src/syncQueue.h b/src/syncQueue.h
index f076b4a..5cb4f6e 100644
--- a/src/syncQueue.h
+++ b/src/syncQueue.h
@@ -46,7 +46,7 @@ class SyncQueue
public:
SyncQueue():syncServer_(NULL) {};
~SyncQueue() {};
-
+ static SyncQueue& instance();
void setSyncServerPtr(SyncServer *);
void push(const std::string & );
void push(const SyncCommand & );
@@ -54,10 +54,20 @@ public:
bool empty();
private:
+ static Mutex instMutex;
+ static SyncQueue* inst;
+ class instanceCleaner {
+ public: ~instanceCleaner() {
+ if(SyncQueue::inst != 0)
+ delete SyncQueue::inst;
+ }
+ };
SyncQueue(const SyncQueue &s);
void operator=(const SyncQueue &s);
Mutex mutex_;
SyncServer * syncServer_;
};
+extern SyncQueue& gSyncQueue;
+
#endif
diff --git a/src/threadParam.h b/src/threadParam.h
index 4861fc6..16a18fe 100644
--- a/src/threadParam.h
+++ b/src/threadParam.h
@@ -41,13 +41,11 @@
class ThreadParam
{
public:
- ThreadParam(TunDevice& dev_,PacketSource& src_,ConnectionList& cl_,SyncQueue & queue_,OptionConnectTo & connto_)
- : dev(dev_),src(src_),cl(cl_),queue(queue_),connto(connto_)
+ ThreadParam(TunDevice& dev_,PacketSource& src_,OptionConnectTo & connto_)
+ : dev(dev_),src(src_),connto(connto_)
{};
TunDevice& dev;
PacketSource& src;
- ConnectionList& cl;
- SyncQueue & queue;
OptionConnectTo & connto;
};