From cf7d42e10e3a2025df7857e180c07fcea404a05d Mon Sep 17 00:00:00 2001 From: Othmar Gsenger Date: Thu, 13 Dec 2007 12:56:50 +0000 Subject: splitten SyncSocket to SyncSocket and SyncClientSocket --- Makefile | 4 +++ anytun.cpp | 3 ++- syncClientSocket.cpp | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ syncClientSocket.h | 25 ++++++++++++++++++ syncSocket.cpp | 39 ---------------------------- syncSocket.h | 6 ----- 6 files changed, 104 insertions(+), 46 deletions(-) create mode 100644 syncClientSocket.cpp create mode 100644 syncClientSocket.h diff --git a/Makefile b/Makefile index db3f4c7..f0bcf10 100644 --- a/Makefile +++ b/Makefile @@ -62,6 +62,7 @@ OBJS = anytun.o \ router.o \ signalController.o \ syncSocket.o \ + syncClientSocket.o \ log.o \ options.o \ seqWindow.o \ @@ -108,6 +109,9 @@ mpi.o: mpi.cpp mpi.h syncSocket.o: syncSocket.cpp syncSocket.h $(C++) $(CCFLAGS) $< -c +syncClientSocket.o: syncClientSocket.cpp syncClientSocket.h + $(C++) $(CCFLAGS) $< -c + signalController.o: signalController.cpp signalController.h $(C++) $(CCFLAGS) $< -c diff --git a/anytun.cpp b/anytun.cpp index f853b9c..d9c7b1e 100644 --- a/anytun.cpp +++ b/anytun.cpp @@ -53,6 +53,7 @@ #include "syncListenSocket.h" #include "syncSocket.h" +#include "syncClientSocket.h" #define PAYLOAD_TYPE_TAP 0x6558 #define PAYLOAD_TYPE_TUN 0x0800 @@ -221,7 +222,7 @@ void* syncConnector(void* p ) Param* param = reinterpret_cast(p); SocketHandler h; - SyncSocket sock(h,param->cl); + SyncClientSocket sock(h,param->cl); // sock.EnableSSL(); sock.Open( param->opt.getRemoteSyncAddr(), param->opt.getRemoteSyncPort()); h.Add(&sock); diff --git a/syncClientSocket.cpp b/syncClientSocket.cpp new file mode 100644 index 0000000..7dbbf67 --- /dev/null +++ b/syncClientSocket.cpp @@ -0,0 +1,73 @@ +#include +#include +#include + +#include +#include + + +//#include "connectionParam.h" +#include "Sockets/Utility.h" +#include "syncClientSocket.h" +#include "buffer.h" +//#include "log.h" + +SyncClientSocket::SyncClientSocket(ISocketHandler& h,ConnectionList & cl) +:TcpSocket(h),cl_(cl) +{ + // initial connection timeout setting and number of retries + SetConnectTimeout(12); + SetConnectionRetry(-1); //infinite reties + + // Also reconnect broken link + SetReconnect(true); +} + + +bool SyncClientSocket::OnConnectRetry() +{ + std::cout << "SyncClientSocket::OnConnectRetry" << std::endl; + return true; +} + + +void SyncClientSocket::OnReconnect() +{ + std::cout << "SyncClientSocket::OnReconnect" << std::endl; + // ... + //Send("Welcome back\r\n"); +} + + +void SyncClientSocket::OnRawData(const char *buf,size_t len) +//void SyncClientSocket::OnLine(const std::string& line) +{ + return; + std::stringstream iss; + std::cout << "recieved sync inforamtaion:"<< std::endl; + for(size_t index=0;indexinit(::Buffer(20), ::Buffer(14)); + ConnectionParam conn ( (*kd), (*seq), seq_nr_, "", 0); + ia >> conn; + std::cout << "sync connection remote host " << conn.remote_host_ << ":" << conn.remote_port_ << std::endl; + cl_.clear(); + cl_.addConnection(conn,std::string("default")); +} +//void StatusClientSocket::InitSSLServer() +//{ +// InitializeContext("server.pem", "keypwd", SSLv23_method()); +//} +// +// +//void StatusClientSocket::Init() +//{ +// EnableSSL(); +//} diff --git a/syncClientSocket.h b/syncClientSocket.h new file mode 100644 index 0000000..4288c02 --- /dev/null +++ b/syncClientSocket.h @@ -0,0 +1,25 @@ +#ifndef _SYNCCLIENTSOCKET_H +#define _SYNCCLIENTSOCKET_H + +#include "Sockets/TcpSocket.h" +#include "Sockets/ISocketHandler.h" +#include "connectionList.h" + +#ifdef SOCKETS_NAMESPACE +using namespace SOCKETS_NAMESPACE; +#endif // SOCKETS_NAMESPACE + +class SyncClientSocket : public TcpSocket +{ +public: + SyncClientSocket(ISocketHandler&,ConnectionList & ); + + bool OnConnectRetry(); + void OnReconnect(); + void OnRawData(const char *buf,size_t len); +private: + ConnectionList & cl_; +}; + + +#endif // _SYNCSOCKET_H diff --git a/syncSocket.cpp b/syncSocket.cpp index b6682ce..c1ce2f2 100644 --- a/syncSocket.cpp +++ b/syncSocket.cpp @@ -15,27 +15,10 @@ SyncSocket::SyncSocket(ISocketHandler& h,ConnectionList & cl) :TcpSocket(h),cl_(cl) { - // initial connection timeout setting and number of retries SetConnectTimeout(12); - SetConnectionRetry(5); - - // Also reconnect broken link -// SetReconnect(true); } -bool SyncSocket::OnConnectRetry() -{ -// return true; - return false; -} - - -void SyncSocket::OnReconnect() -{ - // ... - //Send("Welcome back\r\n"); -} void SyncSocket::OnAccept() { @@ -53,28 +36,6 @@ void SyncSocket::OnAccept() } } -void SyncSocket::OnRawData(const char *buf,size_t len) -//void SyncSocket::OnLine(const std::string& line) -{ - return; - std::stringstream iss; - std::cout << "recieved sync inforamtaion:"<< std::endl; - for(size_t index=0;indexinit(::Buffer(20), ::Buffer(14)); - ConnectionParam conn ( (*kd), (*seq), seq_nr_, "", 0); - ia >> conn; - std::cout << "sync connection remote host " << conn.remote_host_ << ":" << conn.remote_port_ << std::endl; - cl_.clear(); - cl_.addConnection(conn,std::string("default")); -} //void StatusSocket::InitSSLServer() //{ // InitializeContext("server.pem", "keypwd", SSLv23_method()); diff --git a/syncSocket.h b/syncSocket.h index 19d6ef5..e1d0f9b 100644 --- a/syncSocket.h +++ b/syncSocket.h @@ -15,17 +15,11 @@ public: SyncSocket(ISocketHandler&,ConnectionList & ); void OnAccept(); - - bool OnConnectRetry(); - void OnReconnect(); -// void OnLine(const std::string& line); - void OnRawData(const char *buf,size_t len); // void Init(); // void InitSSLServer(); private: ConnectionList & cl_; -// ResumeSocket2& operator=(const ResumeSocket2& ) { return *this; } // assignment operator }; -- cgit v1.2.3