This commit is contained in:
Adam Ierymenko 2016-08-05 15:02:01 -07:00
parent 4d9b74b171
commit e2f783ebbd
13 changed files with 561 additions and 144 deletions

View file

@ -40,10 +40,8 @@
#include "SharedPtr.hpp"
#include "AtomicCounter.hpp"
#include "Hashtable.hpp"
#include "Membership.hpp"
#include "Mutex.hpp"
#include "NonCopyable.hpp"
#include "LockingPtr.hpp"
namespace ZeroTier {
@ -386,34 +384,6 @@ public:
return (_directPathPushCutoffCount < ZT_PUSH_DIRECT_PATHS_CUTOFF_LIMIT);
}
/**
* Get the membership record for this network, possibly creating if missing
*
* @param networkId Network ID
* @param createIfMissing If true, create a Membership record if there isn't one
* @return Single-scope locking pointer (see LockingPtr.hpp) to Membership or NULL if not found and createIfMissing is false
*/
inline LockingPtr<Membership> membership(const uint64_t networkId,bool createIfMissing)
{
_memberships_m.lock();
try {
if (createIfMissing) {
return LockingPtr<Membership>(&(_memberships[networkId]),&_memberships_m);
} else {
Membership *m = _memberships.get(networkId);
if (m) {
return LockingPtr<Membership>(m,&_memberships_m);
} else {
_memberships_m.unlock();
return LockingPtr<Membership>();
}
}
} catch ( ... ) {
_memberships_m.unlock();
throw;
}
}
/**
* Find a common set of addresses by which two peers can link, if any
*
@ -460,9 +430,6 @@ private:
unsigned int _latency;
unsigned int _directPathPushCutoffCount;
Hashtable<uint64_t,Membership> _memberships;
Mutex _memberships_m;
AtomicCounter __refCount;
};