4 * The secure anycast tunneling protocol (satp) defines a protocol used
5 * for communication between any combination of unicast and anycast
6 * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel
7 * mode and allows tunneling of every ETHER TYPE protocol (e.g.
8 * ethernet, ip, arp ...). satp directly includes cryptography and
9 * message authentication based on the methodes used by SRTP. It is
10 * intended to deliver a generic, scaleable and secure solution for
11 * tunneling and relaying of packets of any protocol.
14 * Copyright (C) 2007-2008 Othmar Gsenger, Erwin Nindl,
15 * Christian Pointner <satp@wirdorange.org>
17 * This file is part of Anytun.
19 * Anytun is free software: you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License version 3 as
21 * published by the Free Software Foundation.
23 * Anytun is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with anytun. If not, see <http://www.gnu.org/licenses/>.
35 #include <boost/archive/text_oarchive.hpp>
36 #include <boost/archive/text_iarchive.hpp>
40 //#include "connectionParam.h"
41 #include "Sockets/Utility.h"
42 #include "syncClientSocket.h"
46 SyncClientSocket::SyncClientSocket(ISocketHandler
& h
,ConnectionList
& cl
)
47 :TcpSocket(h
),cl_(cl
),missing_chars(-1),buffer_size_(0)
49 // initial connection timeout setting and number of retries
50 SetConnectTimeout(12);
51 SetConnectionRetry(-1); //infinite reties
53 // Also reconnect broken link
58 bool SyncClientSocket::OnConnectRetry()
64 void SyncClientSocket::OnReconnect()
66 cLog
.msg(Log::PRIO_NOTICE
) << "reconnected with " << GetRemoteHostname() << std::endl
;
68 //Send("Welcome back\r\n");
72 void SyncClientSocket::OnRawData(const char *buf
,size_t len
)
73 //void SyncClientSocket::OnLine(const std::string& line)
75 for(size_t index
=0;index
<len
;index
++)
77 // std::cout << buf[index];
83 // cLog.msg(Log::PRIO_NOTICE) << "buffer size "<< buffer_size_ << " missing_chars " << missing_chars;
84 if(missing_chars
==-1 && buffer_size_
>5)
86 char * buffer
= new char [6+1];
88 std::stringstream tmp
;
91 // cLog.msg(Log::PRIO_NOTICE) << "recieved sync inforamtaion length from " << GetRemoteHostname() <<" "<<tmp.str()<<"bytes of data"<< std::endl;
95 if(missing_chars
>0 && missing_chars
<=buffer_size_
)
97 char * buffer
= new char [missing_chars
+1];
98 iss_
.read(buffer
,missing_chars
);
99 std::stringstream tmp
;
100 tmp
.write(buffer
,missing_chars
);
101 // cLog.msg(Log::PRIO_NOTICE) << "recieved sync inforamtaion from " << GetRemoteHostname() <<" \""<<tmp.str()<<'"'<< std::endl;
102 boost::archive::text_iarchive
ia(tmp
);
103 SyncCommand
scom(cl_
);
105 buffer_size_
-=missing_chars
;
112 //u_int16_t mux = scom.getMux();
113 //const ConnectionParam & conn = cl_.getConnection(mux)->second;
114 //cLog.msg(Log::PRIO_NOTICE) << "sync connection #"<<mux<<" remote host " << conn.remote_host_ << ":" << conn.remote_port_ << std::endl;
117 //void StatusClientSocket::InitSSLServer()
119 // InitializeContext("server.pem", "keypwd", SSLv23_method());
123 //void StatusClientSocket::Init()