From 9c3bb1aed4b9e8922bc33f4133f9936c992ef93d Mon Sep 17 00:00:00 2001 From: Othmar Gsenger Date: Wed, 27 Feb 2008 20:44:12 +0000 Subject: added routing table support --- anytun.cpp | 5 ++++- routingTable.cpp | 26 ++++++++++++++++++-------- routingTable.h | 23 +++++++++++++++++------ 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/anytun.cpp b/anytun.cpp index df80f79..0b4eaf6 100644 --- a/anytun.cpp +++ b/anytun.cpp @@ -53,6 +53,8 @@ #include "options.h" #include "seqWindow.h" #include "connectionList.h" +#include "routingTable.h" +#include "networkAddress.h" #include "syncQueue.h" #include "syncSocketHandler.h" @@ -153,7 +155,8 @@ void* sender(void* p) if(param->cl.empty()) continue; - + + gRoutingTable.getRoute(NetworkAddress()); ConnectionMap::iterator cit = param->cl.getConnection(mux); if(cit==param->cl.getEnd()) continue; diff --git a/routingTable.cpp b/routingTable.cpp index 24ac106..a6e0917 100644 --- a/routingTable.cpp +++ b/routingTable.cpp @@ -33,6 +33,21 @@ #include "routingTable.h" +RoutingTable* RoutingTable::inst = NULL; +Mutex RoutingTable::instMutex; +RoutingTable& gRoutingTable = RoutingTable::instance(); + + +RoutingTable& RoutingTable::instance() +{ + Lock lock(instMutex); + static instanceCleaner c; + if(!inst) + inst = new RoutingTable(); + + return *inst; +} + RoutingTable::RoutingTable() { } @@ -41,7 +56,7 @@ RoutingTable::~RoutingTable() { } -void RoutingTable::addRoute(const RoutingTableEntry &route ) +void RoutingTable::addRoute(const NetworkPrefix & ,u_int16_t ) { Lock lock(mutex_); @@ -53,16 +68,11 @@ void RoutingTable::addRoute(const RoutingTableEntry &route ) // } } -const RoutingMap::iterator RoutingTable::getEnd() -{ - return routes_.end(); -} - -const RoutingMap::iterator RoutingTable::getRoute() +u_int16_t RoutingTable::getRoute(const NetworkAddress &) { Lock lock(mutex_); RoutingMap::iterator it = routes_.begin(); - return it; + return 0; } void RoutingTable::clear() diff --git a/routingTable.h b/routingTable.h index 9a4ffae..b406b65 100644 --- a/routingTable.h +++ b/routingTable.h @@ -36,27 +36,38 @@ #include "threadUtils.hpp" #include "datatypes.h" -#include "routingTableEntry.h" +//#include "routingTableEntry.h" #include "networkAddress.h" -typedef std::map RoutingMap; +#include "networkPrefix.h" +typedef std::map RoutingMap; class RoutingTable { public: + static RoutingTable& instance(); RoutingTable(); ~RoutingTable(); - void addRoute(const RoutingTableEntry &route); - const RoutingMap::iterator getRoute(); - const RoutingMap::iterator getEnd(); + void addRoute(const NetworkPrefix & ,u_int16_t); + u_int16_t getRoute(const NetworkAddress &); bool empty(); void clear(); Mutex& getMutex(); private: - RoutingTable(const RoutingTable &s); + static Mutex instMutex; + static RoutingTable* inst; + class instanceCleaner { + public: ~instanceCleaner() { + if(RoutingTable::inst != 0) + delete RoutingTable::inst; + } + }; + RoutingTable(const RoutingTable &s); void operator=(const RoutingTable &s); RoutingMap routes_; Mutex mutex_; }; +extern RoutingTable& gRoutingTable; + #endif -- cgit v1.2.3