From f057bb63cdc4bebc4608f4f2ed6da4656ddbc8a9 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Thu, 4 Aug 2016 09:02:35 -0700 Subject: More work on tags and capabilities. --- node/Peer.hpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'node/Peer.hpp') diff --git a/node/Peer.hpp b/node/Peer.hpp index d8c44ebe..8b50f429 100644 --- a/node/Peer.hpp +++ b/node/Peer.hpp @@ -40,8 +40,10 @@ #include "SharedPtr.hpp" #include "AtomicCounter.hpp" #include "Hashtable.hpp" +#include "Membership.hpp" #include "Mutex.hpp" #include "NonCopyable.hpp" +#include "LockingPtr.hpp" namespace ZeroTier { @@ -384,6 +386,34 @@ 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(const uint64_t networkId,bool createIfMissing) + { + _memberships_m.lock(); + try { + if (createIfMissing) { + return LockingPtr(&(_memberships[networkId]),&_memberships_m); + } else { + Membership *m = _memberships.get(networkId); + if (m) { + return LockingPtr(m,&_memberships_m); + } else { + _memberships_m.unlock(); + return LockingPtr(); + } + } + } catch ( ... ) { + _memberships_m.unlock(); + throw; + } + } + /** * Find a common set of addresses by which two peers can link, if any * @@ -430,6 +460,9 @@ private: unsigned int _latency; unsigned int _directPathPushCutoffCount; + Hashtable _memberships; + Mutex _memberships_m; + AtomicCounter __refCount; }; -- cgit v1.2.3