Refactor MULTICAST_LIKE pushing to eliminate redundant and unnecessary pushes and simplify code.

This commit is contained in:
Adam Ierymenko 2016-09-07 15:15:52 -07:00
parent 1c08f5e857
commit 1908aa55f5
9 changed files with 184 additions and 204 deletions

View file

@ -190,14 +190,6 @@ public:
*/
void multicastUnsubscribe(const MulticastGroup &mg);
/**
* Announce multicast groups to a peer if that peer is authorized on this network
*
* @param peer Peer to try to announce multicast groups to
* @return True if peer was authorized and groups were announced
*/
bool tryAnnounceMulticastGroupsTo(const SharedPtr<Peer> &peer);
/**
* Apply a NetworkConfig to this network
*
@ -272,6 +264,15 @@ public:
*/
void clean();
/**
* Announce multicast groups to all members, anchors, etc.
*/
inline void announceMulticastGroups()
{
Mutex::Lock _l(_lock);
_announceMulticastGroups((const MulticastGroup *)0);
}
/**
* @return Time of last updated configuration or 0 if none
*/
@ -298,23 +299,10 @@ public:
/**
* Get current network config
*
* This returns a const reference to the network config in place, which is safe
* to concurrently access but *may* change during access. Normally this isn't a
* problem, but if it is use configCopy().
*
* @return Network configuration (may be a null config if we don't have one yet)
*/
inline const NetworkConfig &config() const { return _config; }
/**
* @return A thread-safe copy of our NetworkConfig instead of a const reference
*/
inline NetworkConfig configCopy() const
{
Mutex::Lock _l(_lock);
return _config;
}
/**
* @return True if this network has a valid config
*/
@ -323,7 +311,7 @@ public:
/**
* @return Ethernet MAC address for this network's local interface
*/
inline const MAC &mac() const throw() { return _mac; }
inline const MAC &mac() const { return _mac; }
/**
* Find the node on this network that has this MAC behind it (if any)
@ -365,7 +353,7 @@ public:
if (com.networkId() != _id)
return -1;
Mutex::Lock _l(_lock);
return _memberships[com.issuedTo()].addCredential(RR,com);
return _memberships[com.issuedTo()].addCredential(RR,this,com);
}
/**
@ -417,24 +405,18 @@ public:
*/
inline void **userPtr() throw() { return &_uPtr; }
inline bool operator==(const Network &n) const throw() { return (_id == n._id); }
inline bool operator!=(const Network &n) const throw() { return (_id != n._id); }
inline bool operator<(const Network &n) const throw() { return (_id < n._id); }
inline bool operator>(const Network &n) const throw() { return (_id > n._id); }
inline bool operator<=(const Network &n) const throw() { return (_id <= n._id); }
inline bool operator>=(const Network &n) const throw() { return (_id >= n._id); }
private:
ZT_VirtualNetworkStatus _status() const;
void _externalConfig(ZT_VirtualNetworkConfig *ec) const; // assumes _lock is locked
bool _isAllowed(const SharedPtr<Peer> &peer) const;
void _announceMulticastGroups();
void _announceMulticastGroupsTo(const SharedPtr<Peer> &peer,const std::vector<MulticastGroup> &allMulticastGroups);
void _announceMulticastGroups(const MulticastGroup *const onlyThis);
void _announceMulticastGroupsTo(const Address &peer,const std::vector<MulticastGroup> &allMulticastGroups);
std::vector<MulticastGroup> _allMulticastGroups() const;
const RuntimeEnvironment *RR;
void *_uPtr;
uint64_t _id;
uint64_t _lastAnnouncedMulticastGroupsUpstream;
MAC _mac; // local MAC address
volatile bool _portInitialized;