From 4083c982656fe3d79168b228aca56cef2de2ea0e Mon Sep 17 00:00:00 2001 From: Othmar Gsenger Date: Wed, 27 Feb 2008 22:43:14 +0000 Subject: added route syncing --- Makefile | 8 ++++++++ syncClientSocket.cpp | 6 +++--- syncCommand.cpp | 19 +++++++++++++++---- syncCommand.h | 28 +++++++++++++++++++++------- syncConnectionCommand.cpp | 16 ++++++++++++++++ syncConnectionCommand.h | 32 ++++++++++++++++++++++++++++++++ syncRouteCommand.cpp | 15 +++++++++++++++ syncRouteCommand.h | 30 ++++++++++++++++++++++++++++++ syncSocket.cpp | 10 +++++++++- 9 files changed, 149 insertions(+), 15 deletions(-) create mode 100644 syncConnectionCommand.cpp create mode 100644 syncConnectionCommand.h create mode 100644 syncRouteCommand.cpp create mode 100644 syncRouteCommand.h 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 #"<second; + //cLog.msg(Log::PRIO_NOTICE) << "sync connection #"< 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 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 +#include + +#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 + 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 +#include + +#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 + 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 #include #include - +#include "routingTable.h" #include #include @@ -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() -- cgit v1.2.3