summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOthmar Gsenger <otti@anytun.org>2008-02-27 22:43:14 +0000
committerOthmar Gsenger <otti@anytun.org>2008-02-27 22:43:14 +0000
commit4083c982656fe3d79168b228aca56cef2de2ea0e (patch)
tree6574a170eb044ea75dd4f96cd22cb6b4c171d465
parentadded command line parameter for master key and salt (diff)
added route syncing
-rw-r--r--Makefile8
-rw-r--r--syncClientSocket.cpp6
-rw-r--r--syncCommand.cpp19
-rw-r--r--syncCommand.h28
-rw-r--r--syncConnectionCommand.cpp16
-rw-r--r--syncConnectionCommand.h32
-rw-r--r--syncRouteCommand.cpp15
-rw-r--r--syncRouteCommand.h30
-rw-r--r--syncSocket.cpp10
9 files changed, 149 insertions, 15 deletions
diff --git a/Makefile b/Makefile
index a2a14a1..3f5b583 100644
--- a/Makefile
+++ b/Makefile
@@ -50,6 +50,8 @@ OBJS = anytun.o \
buffer.o \
syncBuffer.o \
syncCommand.o \
+ syncRouteCommand.o \
+ syncConnectionCommand.o \
plainPacket.o \
encryptedPacket.o \
cipher.o \
@@ -143,6 +145,12 @@ syncSocketHandler.o: syncSocketHandler.cpp syncSocketHandler.h
syncCommand.o: syncCommand.cpp syncCommand.h
$(C++) $(CCFLAGS) $< -c
+syncRouteCommand.o: syncRouteCommand.cpp syncRouteCommand.h
+ $(C++) $(CCFLAGS) $< -c
+
+syncConnectionCommand.o: syncConnectionCommand.cpp syncConnectionCommand.h
+ $(C++) $(CCFLAGS) $< -c
+
syncClientSocket.o: syncClientSocket.cpp syncClientSocket.h
$(C++) $(CCFLAGS) $< -c
diff --git a/syncClientSocket.cpp b/syncClientSocket.cpp
index 76fd40d..734ff6e 100644
--- a/syncClientSocket.cpp
+++ b/syncClientSocket.cpp
@@ -53,9 +53,9 @@ void SyncClientSocket::OnRawData(const char *buf,size_t len)
boost::archive::text_iarchive ia(iss);
SyncCommand scom(cl_);
ia >> scom;
- u_int16_t mux = scom.getMux();
- const ConnectionParam & conn = cl_.getConnection(mux)->second;
- cLog.msg(Log::PRIO_NOTICE) << "sync connection #"<<mux<<" remote host " << conn.remote_host_ << ":" << conn.remote_port_ << std::endl;
+ //u_int16_t mux = scom.getMux();
+ //const ConnectionParam & conn = cl_.getConnection(mux)->second;
+ //cLog.msg(Log::PRIO_NOTICE) << "sync connection #"<<mux<<" remote host " << conn.remote_host_ << ":" << conn.remote_port_ << std::endl;
}
//void StatusClientSocket::InitSSLServer()
diff --git a/syncCommand.cpp b/syncCommand.cpp
index d5bb8dc..12d32f8 100644
--- a/syncCommand.cpp
+++ b/syncCommand.cpp
@@ -1,16 +1,27 @@
#include "syncCommand.h"
SyncCommand::SyncCommand(ConnectionList & cl )
-:cl_(cl)
{
+ scc_ = new SyncConnectionCommand(cl);
+ src_ = new SyncRouteCommand();
}
SyncCommand::SyncCommand(ConnectionList & cl, u_int16_t mux )
-:cl_(cl),mux_(mux)
{
+ scc_ = new SyncConnectionCommand(cl,mux);
+ src_=NULL;
}
-u_int16_t SyncCommand::getMux() const
+SyncCommand::SyncCommand(u_int16_t mux )
+{
+ scc_ = NULL;
+ src_ = new SyncRouteCommand(mux);
+}
+
+SyncCommand::~SyncCommand()
{
- return mux_;
+ if (scc_)
+ delete scc_;
+ if (src_)
+ delete src_;
}
diff --git a/syncCommand.h b/syncCommand.h
index b2f3fc5..29b063c 100644
--- a/syncCommand.h
+++ b/syncCommand.h
@@ -5,26 +5,40 @@
#include "connectionList.h"
#include "threadUtils.hpp"
+#include "syncConnectionCommand.h"
+#include "syncRouteCommand.h"
+#include <string>
class SyncCommand
{
public:
SyncCommand(ConnectionList & cl );
SyncCommand(ConnectionList & cl ,u_int16_t mux);
- u_int16_t getMux() const;
+ SyncCommand(u_int16_t mux);
+ ~SyncCommand();
private:
SyncCommand(const SyncCommand &);
- ConnectionList & cl_;
- u_int16_t mux_;
+ SyncConnectionCommand * scc_;
+ SyncRouteCommand * src_;
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
- Lock lock(cl_.getMutex());
- ar & mux_;
- ConnectionParam & conn = cl_.getOrNewConnectionUnlocked(mux_);
- ar & conn;
+ std::string syncstr;
+ if (scc_)
+ {
+ syncstr = "connection";
+ }
+ if ( src_)
+ {
+ syncstr = "route";
+ }
+ ar & syncstr;
+ if (syncstr == "connection")
+ ar & *scc_;
+ if (syncstr == "route")
+ ar & *src_;
}
};
diff --git a/syncConnectionCommand.cpp b/syncConnectionCommand.cpp
new file mode 100644
index 0000000..7f6f503
--- /dev/null
+++ b/syncConnectionCommand.cpp
@@ -0,0 +1,16 @@
+#include "syncConnectionCommand.h"
+
+SyncConnectionCommand::SyncConnectionCommand(ConnectionList & cl )
+:cl_(cl)
+{
+}
+
+SyncConnectionCommand::SyncConnectionCommand(ConnectionList & cl, u_int16_t mux )
+:cl_(cl),mux_(mux)
+{
+}
+
+u_int16_t SyncConnectionCommand::getMux() const
+{
+ return mux_;
+}
diff --git a/syncConnectionCommand.h b/syncConnectionCommand.h
new file mode 100644
index 0000000..225ec9c
--- /dev/null
+++ b/syncConnectionCommand.h
@@ -0,0 +1,32 @@
+#ifndef _SYNCCONNECTIONCOMMAND_H
+#define _SYNCCONNECTIONCOMMAND_H
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+
+#include "connectionList.h"
+#include "threadUtils.hpp"
+
+class SyncConnectionCommand
+{
+public:
+ SyncConnectionCommand(ConnectionList & cl );
+ SyncConnectionCommand(ConnectionList & cl ,u_int16_t mux);
+ u_int16_t getMux() const;
+
+private:
+ SyncConnectionCommand(const SyncConnectionCommand &);
+ ConnectionList & cl_;
+ u_int16_t mux_;
+ friend class boost::serialization::access;
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int version)
+ {
+ Lock lock(cl_.getMutex());
+ ar & mux_;
+ ConnectionParam & conn = cl_.getOrNewConnectionUnlocked(mux_);
+ ar & conn;
+ }
+};
+
+
+#endif // _SYNCCOMMAND_H
diff --git a/syncRouteCommand.cpp b/syncRouteCommand.cpp
new file mode 100644
index 0000000..7ba6a18
--- /dev/null
+++ b/syncRouteCommand.cpp
@@ -0,0 +1,15 @@
+#include "syncRouteCommand.h"
+
+SyncRouteCommand::SyncRouteCommand()
+{
+}
+
+SyncRouteCommand::SyncRouteCommand( u_int16_t mux )
+:mux_(mux)
+{
+}
+
+u_int16_t SyncRouteCommand::getMux() const
+{
+ return mux_;
+}
diff --git a/syncRouteCommand.h b/syncRouteCommand.h
new file mode 100644
index 0000000..913673c
--- /dev/null
+++ b/syncRouteCommand.h
@@ -0,0 +1,30 @@
+#ifndef _SYNCROUTECOMMAND_H
+#define _SYNCROUTECOMMAND_H
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+
+#include "threadUtils.hpp"
+
+class SyncRouteCommand
+{
+public:
+ SyncRouteCommand(u_int16_t mux);
+ SyncRouteCommand();
+ u_int16_t getMux() const;
+
+private:
+ SyncRouteCommand(const SyncRouteCommand &);
+ u_int16_t mux_;
+ friend class boost::serialization::access;
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int version)
+ {
+ //Lock lock(gRoutingTable.getMutex());
+ ar & mux_;
+ // ConnectionParam & conn = cl_.getOrNewConnectionUnlocked(mux_);
+ // ar & conn;
+ }
+};
+
+
+#endif // _SYNCCOMMAND_H
diff --git a/syncSocket.cpp b/syncSocket.cpp
index 6476441..29d1ca8 100644
--- a/syncSocket.cpp
+++ b/syncSocket.cpp
@@ -1,7 +1,7 @@
#include <sstream>
#include <iostream>
#include <string>
-
+#include "routingTable.h"
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
@@ -35,6 +35,14 @@ void SyncSocket::OnAccept()
oa << scom;
Send(sout.str());
}
+ if( ! gRoutingTable.empty())
+ {
+ std::ostringstream sout;
+ boost::archive::text_oarchive oa(sout);
+ const SyncCommand scom(0);
+ oa << scom;
+ Send(sout.str());
+ }
}
//void StatusSocket::InitSSLServer()