mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-05 03:53:44 +02:00
Another std::map<> dies.
This commit is contained in:
parent
3a959a7763
commit
7b8ce16057
4 changed files with 50 additions and 10 deletions
|
@ -199,6 +199,26 @@ public:
|
||||||
return k;
|
return k;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append all keys (in unspecified order) to the supplied vector or list
|
||||||
|
*
|
||||||
|
* @param v Vector, list, or other compliant container
|
||||||
|
* @tparam Type of V (generally inferred)
|
||||||
|
*/
|
||||||
|
template<typename C>
|
||||||
|
inline void appendKeys(C &v) const
|
||||||
|
{
|
||||||
|
if (_s) {
|
||||||
|
for(unsigned long i=0;i<_bc;++i) {
|
||||||
|
_Bucket *b = _t[i];
|
||||||
|
while (b) {
|
||||||
|
v.push_back(b->k);
|
||||||
|
b = b->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Vector of all entries (pairs of K,V)
|
* @return Vector of all entries (pairs of K,V)
|
||||||
*/
|
*/
|
||||||
|
@ -234,6 +254,21 @@ public:
|
||||||
}
|
}
|
||||||
inline const V *get(const K &k) const { return const_cast<Hashtable *>(this)->get(k); }
|
inline const V *get(const K &k) const { return const_cast<Hashtable *>(this)->get(k); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param k Key to check
|
||||||
|
* @return True if key is present
|
||||||
|
*/
|
||||||
|
inline bool contains(const K &k) const
|
||||||
|
{
|
||||||
|
_Bucket *b = _t[_hc(k) % _bc];
|
||||||
|
while (b) {
|
||||||
|
if (b->k == k)
|
||||||
|
return true;
|
||||||
|
b = b->next;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param k Key
|
* @param k Key
|
||||||
* @return True if value was present
|
* @return True if value was present
|
||||||
|
|
|
@ -147,7 +147,7 @@ bool Network::subscribedToMulticastGroup(const MulticastGroup &mg,bool includeBr
|
||||||
if (std::binary_search(_myMulticastGroups.begin(),_myMulticastGroups.end(),mg))
|
if (std::binary_search(_myMulticastGroups.begin(),_myMulticastGroups.end(),mg))
|
||||||
return true;
|
return true;
|
||||||
else if (includeBridgedGroups)
|
else if (includeBridgedGroups)
|
||||||
return (_multicastGroupsBehindMe.find(mg) != _multicastGroupsBehindMe.end());
|
return _multicastGroupsBehindMe.contains(mg);
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,10 +373,14 @@ void Network::clean()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean learned multicast groups if we haven't heard from them in a while
|
// Clean learned multicast groups if we haven't heard from them in a while
|
||||||
for(std::map<MulticastGroup,uint64_t>::iterator mg(_multicastGroupsBehindMe.begin());mg!=_multicastGroupsBehindMe.end();) {
|
{
|
||||||
if ((now - mg->second) > (ZT_MULTICAST_LIKE_EXPIRE * 2))
|
Hashtable< MulticastGroup,uint64_t >::Iterator i(_multicastGroupsBehindMe);
|
||||||
_multicastGroupsBehindMe.erase(mg++);
|
MulticastGroup *mg = (MulticastGroup *)0;
|
||||||
else ++mg;
|
uint64_t *ts = (uint64_t *)0;
|
||||||
|
while (i.next(mg,ts)) {
|
||||||
|
if ((now - *ts) > (ZT_MULTICAST_LIKE_EXPIRE * 2))
|
||||||
|
_multicastGroupsBehindMe.erase(*mg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -408,8 +412,8 @@ void Network::learnBridgeRoute(const MAC &mac,const Address &addr)
|
||||||
void Network::learnBridgedMulticastGroup(const MulticastGroup &mg,uint64_t now)
|
void Network::learnBridgedMulticastGroup(const MulticastGroup &mg,uint64_t now)
|
||||||
{
|
{
|
||||||
Mutex::Lock _l(_lock);
|
Mutex::Lock _l(_lock);
|
||||||
unsigned long tmp = (unsigned long)_multicastGroupsBehindMe.size();
|
const unsigned long tmp = (unsigned long)_multicastGroupsBehindMe.size();
|
||||||
_multicastGroupsBehindMe[mg] = now;
|
_multicastGroupsBehindMe.set(mg,now);
|
||||||
if (tmp != _multicastGroupsBehindMe.size())
|
if (tmp != _multicastGroupsBehindMe.size())
|
||||||
_announceMulticastGroups();
|
_announceMulticastGroups();
|
||||||
}
|
}
|
||||||
|
@ -510,8 +514,7 @@ std::vector<MulticastGroup> Network::_allMulticastGroups() const
|
||||||
std::vector<MulticastGroup> mgs;
|
std::vector<MulticastGroup> mgs;
|
||||||
mgs.reserve(_myMulticastGroups.size() + _multicastGroupsBehindMe.size() + 1);
|
mgs.reserve(_myMulticastGroups.size() + _multicastGroupsBehindMe.size() + 1);
|
||||||
mgs.insert(mgs.end(),_myMulticastGroups.begin(),_myMulticastGroups.end());
|
mgs.insert(mgs.end(),_myMulticastGroups.begin(),_myMulticastGroups.end());
|
||||||
for(std::map< MulticastGroup,uint64_t >::const_iterator i(_multicastGroupsBehindMe.begin());i!=_multicastGroupsBehindMe.end();++i)
|
_multicastGroupsBehindMe.appendKeys(mgs);
|
||||||
mgs.push_back(i->first);
|
|
||||||
if ((_config)&&(_config->enableBroadcast()))
|
if ((_config)&&(_config->enableBroadcast()))
|
||||||
mgs.push_back(Network::BROADCAST);
|
mgs.push_back(Network::BROADCAST);
|
||||||
std::sort(mgs.begin(),mgs.end());
|
std::sort(mgs.begin(),mgs.end());
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
|
|
||||||
#include "Constants.hpp"
|
#include "Constants.hpp"
|
||||||
#include "NonCopyable.hpp"
|
#include "NonCopyable.hpp"
|
||||||
|
#include "Hashtable.hpp"
|
||||||
#include "Address.hpp"
|
#include "Address.hpp"
|
||||||
#include "Mutex.hpp"
|
#include "Mutex.hpp"
|
||||||
#include "SharedPtr.hpp"
|
#include "SharedPtr.hpp"
|
||||||
|
@ -359,7 +360,7 @@ private:
|
||||||
volatile bool _portInitialized;
|
volatile bool _portInitialized;
|
||||||
|
|
||||||
std::vector< MulticastGroup > _myMulticastGroups; // multicast groups that we belong to including those behind us (updated periodically)
|
std::vector< MulticastGroup > _myMulticastGroups; // multicast groups that we belong to including those behind us (updated periodically)
|
||||||
std::map< MulticastGroup,uint64_t > _multicastGroupsBehindMe; // multicast groups bridged to us and when we last saw activity on each
|
Hashtable< MulticastGroup,uint64_t > _multicastGroupsBehindMe; // multicast groups bridged to us and when we last saw activity on each
|
||||||
|
|
||||||
std::map<MAC,Address> _remoteBridgeRoutes; // remote addresses where given MACs are reachable
|
std::map<MAC,Address> _remoteBridgeRoutes; // remote addresses where given MACs are reachable
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include "../include/ZeroTierOne.h"
|
#include "../include/ZeroTierOne.h"
|
||||||
|
|
||||||
#include "RuntimeEnvironment.hpp"
|
#include "RuntimeEnvironment.hpp"
|
||||||
|
#include "CertificateOfMembership.hpp"
|
||||||
#include "RemotePath.hpp"
|
#include "RemotePath.hpp"
|
||||||
#include "Address.hpp"
|
#include "Address.hpp"
|
||||||
#include "Utils.hpp"
|
#include "Utils.hpp"
|
||||||
|
|
Loading…
Add table
Reference in a new issue