From d44e1349d8e83b875b1a102b2b1ce31613a10924 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Tue, 10 Jun 2014 17:18:59 -0700 Subject: Bridge routing table - GitHub issue #68 --- node/Network.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'node/Network.cpp') diff --git a/node/Network.cpp b/node/Network.cpp index d55101c2..3091638a 100644 --- a/node/Network.cpp +++ b/node/Network.cpp @@ -333,6 +333,31 @@ void Network::threadMain() } } +void Network::learnBridgeRoute(const MAC &mac,const Address &addr) +{ + Mutex::Lock _l(_lock); + _bridgeRoutes[mac] = addr; + + // If _bridgeRoutes exceeds sanity limit, trim worst offenders until below -- denial of service circuit breaker + while (_bridgeRoutes.size() > ZT_MAX_BRIDGE_ROUTES) { + std::map counts; + Address maxAddr; + unsigned long maxCount = 0; + for(std::map::iterator br(_bridgeRoutes.begin());br!=_bridgeRoutes.end();++br) { + unsigned long c = ++counts[br->second]; + if (c > maxCount) { + maxCount = c; + maxAddr = br->second; + } + } + for(std::map::iterator br(_bridgeRoutes.begin());br!=_bridgeRoutes.end();) { + if (br->second == maxAddr) + _bridgeRoutes.erase(br++); + else ++br; + } + } +} + void Network::_restoreState() { if (!_id) -- cgit v1.2.3