summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--anytun.cpp3
-rw-r--r--syncClientSocket.cpp73
-rw-r--r--syncClientSocket.h25
-rw-r--r--syncSocket.cpp39
-rw-r--r--syncSocket.h6
6 files changed, 104 insertions, 46 deletions
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<Param*>(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 <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 "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;index<len;index++)
+ {
+ std::cout << buf[index];
+ iss << buf[index];
+ }
+ boost::archive::text_iarchive ia(iss);
+ SeqWindow * seq= new SeqWindow(0);
+ seq_nr_t seq_nr_=0;
+ KeyDerivation * kd = new KeyDerivation;
+ kd->init(::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;index<len;index++)
- {
- std::cout << buf[index];
- iss << buf[index];
- }
- boost::archive::text_iarchive ia(iss);
- SeqWindow * seq= new SeqWindow(0);
- seq_nr_t seq_nr_=0;
- KeyDerivation * kd = new KeyDerivation;
- kd->init(::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
};