diff options
author | Othmar Gsenger <otti@anytun.org> | 2007-12-13 16:22:02 +0000 |
---|---|---|
committer | Othmar Gsenger <otti@anytun.org> | 2007-12-13 16:22:02 +0000 |
commit | f2474da8648b95340456a2695fc2c90e043dabec (patch) | |
tree | 08e29164bde8fb4a98b2720f3dcb75732905ed87 | |
parent | added mux_type (diff) |
added Synccommand / now connection updates work / sync is multi connection capable
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | anytun.cpp | 10 | ||||
-rw-r--r-- | connectionList.cpp | 31 | ||||
-rw-r--r-- | connectionList.h | 8 | ||||
-rw-r--r-- | connectionParam.cpp | 4 | ||||
-rw-r--r-- | router.cpp | 6 | ||||
-rw-r--r-- | router.h | 2 | ||||
-rw-r--r-- | syncClientSocket.cpp | 16 | ||||
-rw-r--r-- | syncClientSocket.h | 1 | ||||
-rw-r--r-- | syncSocket.cpp | 5 |
10 files changed, 61 insertions, 26 deletions
@@ -49,6 +49,7 @@ OBJS = anytun.o \ packetSource.o \ buffer.o \ syncBuffer.o \ + syncCommand.o \ packet.o \ plainPacket.o \ cypher.o \ @@ -113,6 +114,9 @@ mpi.o: mpi.cpp mpi.h syncSocket.o: syncSocket.cpp syncSocket.h $(C++) $(CCFLAGS) $< -c +syncCommand.o: syncCommand.cpp syncCommand.h + $(C++) $(CCFLAGS) $< -c + syncClientSocket.o: syncClientSocket.cpp syncClientSocket.h $(C++) $(CCFLAGS) $< -c @@ -90,7 +90,7 @@ void createConnection(const std::string & remote_host , u_int16_t remote_port, C kd->init(Buffer(key, sizeof(key)), Buffer(salt, sizeof(salt))); cLog.msg(Log::PRIO_NOTICE) << "added connection remote host " << remote_host << ":" << remote_port; ConnectionParam connparam ( (*kd), (*seq), seq_nr_, remote_host, remote_port); - cl.addConnection(connparam,std::string("default")); + cl.addConnection(connparam,0); } @@ -192,7 +192,11 @@ void* sender(void* p) if( param->cl.empty()) continue; - ConnectionParam & conn = param->cl.getConnection(); + //TODO replace 0 with mux + ConnectionMap::iterator cit = param->cl.getConnection(0); + if(cit!=param->cl.getEnd()) + continue; + ConnectionParam & conn = cit->second; // add payload type if(param->dev.getType() == TunDevice::TYPE_TUN) pack.addPayloadType(PAYLOAD_TYPE_TUN); @@ -276,7 +280,7 @@ void* receiver(void* p) } //TODO Add multi connection support here - ConnectionParam & conn = param->cl.getConnection(); + ConnectionParam & conn = param->cl.getConnection(0)->second; if (!checkPacketAuthTag(pack, c, conn)) continue; diff --git a/connectionList.cpp b/connectionList.cpp index 1186263..3b1c528 100644 --- a/connectionList.cpp +++ b/connectionList.cpp @@ -41,22 +41,43 @@ ConnectionList::~ConnectionList() { } -void ConnectionList::addConnection(ConnectionParam &conn, const std::string &name) +void ConnectionList::addConnection(ConnectionParam &conn, u_int16_t mux ) { Lock lock(mutex_); - std::pair<ConnectionMap::iterator, bool> ret = connections_.insert(ConnectionMap::value_type(name, conn)); + std::pair<ConnectionMap::iterator, bool> ret = connections_.insert(ConnectionMap::value_type(mux, conn)); if(!ret.second) { connections_.erase(ret.first); - connections_.insert(ConnectionMap::value_type(name, conn)); + connections_.insert(ConnectionMap::value_type(mux, conn)); } } -ConnectionParam & ConnectionList::getConnection() +const ConnectionMap::iterator ConnectionList::getEnd() +{ + return connections_.end(); +} + +const ConnectionMap::iterator ConnectionList::getConnection(u_int16_t mux) +{ + Lock lock(mutex_); + ConnectionMap::iterator it = connections_.find(mux); + return it; +} + + +ConnectionParam & ConnectionList::getOrNewConnection(u_int16_t mux) { Lock lock(mutex_); - ConnectionMap::iterator it = connections_.begin(); + ConnectionMap::iterator it = connections_.find(mux); + if(it!=connections_.end()) + return it->second; + SeqWindow * seq= new SeqWindow(0); + seq_nr_t seq_nr_=0; + KeyDerivation * kd = new KeyDerivation; + ConnectionParam conn ( (*kd), (*seq), seq_nr_, "", 0); + connections_.insert(ConnectionMap::value_type(mux, conn)); + it = connections_.find(mux); return it->second; } diff --git a/connectionList.h b/connectionList.h index e12ccff..670f077 100644 --- a/connectionList.h +++ b/connectionList.h @@ -38,21 +38,23 @@ #include "datatypes.h" #include "connectionParam.h" #include "networkAddress.h" +typedef std::map<u_int16_t, ConnectionParam> ConnectionMap; class ConnectionList { public: ConnectionList(); ~ConnectionList(); - void addConnection(ConnectionParam &conn, const std::string &name); - ConnectionParam & getConnection(); + void addConnection(ConnectionParam &conn, u_int16_t mux); + const ConnectionMap::iterator getConnection(u_int16_t mux); + const ConnectionMap::iterator getEnd(); + ConnectionParam & getOrNewConnection(u_int16_t mux); bool empty(); void clear(); private: ConnectionList(const ConnectionList &s); void operator=(const ConnectionList &s); - typedef std::map<std::string, ConnectionParam> ConnectionMap; ConnectionMap connections_; Mutex mutex_; }; diff --git a/connectionParam.cpp b/connectionParam.cpp index fbc9a92..6c03f61 100644 --- a/connectionParam.cpp +++ b/connectionParam.cpp @@ -30,6 +30,10 @@ #include "connectionParam.h" +//ConnectionParam::ConnectionParam():kd_(*(new KeyDerivation)),seq_window_(*(new SeqWindow(0))),seq_nr_(0),remote_host_(""),remote_port_(0) +//{ +//} + ConnectionParam::ConnectionParam(KeyDerivation& kd, SeqWindow& seq_window,seq_nr_t seq_nr, std::string remote_host, u_int16_t remote_port) : kd_(kd),seq_window_(seq_window),seq_nr_(seq_nr),remote_host_(remote_host), remote_port_(remote_port) { } @@ -41,13 +41,13 @@ Router::~Router() { } -void Router::addConnection(ConnectionParam &conn,const std::string &name) +void Router::addConnection(ConnectionParam &conn,u_int16_t mux) { - con_list_.addConnection(conn,name); + con_list_.addConnection(conn,mux); } ConnectionParam Router::getRoute() { Lock lock(mutex_); - return con_list_.getConnection(); + return con_list_.getConnection(0)->second; } @@ -41,7 +41,7 @@ class Router public: Router(ConnectionList& cl); ~Router(); - void addConnection(ConnectionParam &conn,const std::string &name); + void addConnection(ConnectionParam &conn,u_int16_t mux); ConnectionParam getRoute(); private: diff --git a/syncClientSocket.cpp b/syncClientSocket.cpp index 864d574..1403ed4 100644 --- a/syncClientSocket.cpp +++ b/syncClientSocket.cpp @@ -49,17 +49,15 @@ void SyncClientSocket::OnRawData(const char *buf,size_t len) 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")); + SyncCommand scom(cl_); + ia >> scom; + u_int16_t mux = scom.getMux(); + const ConnectionParam & conn = cl_.getConnection(mux)->second; + std::cout << "sync connection #"<<mux<<" remote host " << conn.remote_host_ << ":" << conn.remote_port_ << std::endl; } + //void StatusClientSocket::InitSSLServer() //{ // InitializeContext("server.pem", "keypwd", SSLv23_method()); diff --git a/syncClientSocket.h b/syncClientSocket.h index 4288c02..17dd518 100644 --- a/syncClientSocket.h +++ b/syncClientSocket.h @@ -4,6 +4,7 @@ #include "Sockets/TcpSocket.h" #include "Sockets/ISocketHandler.h" #include "connectionList.h" +#include "syncCommand.h" #ifdef SOCKETS_NAMESPACE using namespace SOCKETS_NAMESPACE; diff --git a/syncSocket.cpp b/syncSocket.cpp index c1ce2f2..6476441 100644 --- a/syncSocket.cpp +++ b/syncSocket.cpp @@ -9,6 +9,7 @@ //#include "connectionParam.h" #include "Sockets/Utility.h" #include "syncSocket.h" +#include "syncCommand.h" #include "buffer.h" //#include "log.h" @@ -30,8 +31,8 @@ void SyncSocket::OnAccept() { std::ostringstream sout; boost::archive::text_oarchive oa(sout); - const ConnectionParam conn = cl_.getConnection(); - oa << conn; + const SyncCommand scom(cl_,0); + oa << scom; Send(sout.str()); } } |