Add optional function in DB change listener for member online events.

This commit is contained in:
Adam Ierymenko 2019-08-04 19:55:52 -07:00
parent 818b7e4a2e
commit a77b4ecddb
5 changed files with 38 additions and 21 deletions

View file

@ -384,17 +384,24 @@ void LFDB::eraseMember(const uint64_t networkId,const uint64_t memberId)
void LFDB::nodeIsOnline(const uint64_t networkId,const uint64_t memberId,const InetAddress &physicalAddress)
{
std::lock_guard<std::mutex> l(_state_l);
auto nw = _state.find(networkId);
if (nw != _state.end()) {
auto m = nw->second.members.find(memberId);
if (m != nw->second.members.end()) {
m->second.lastOnlineTime = OSUtils::now();
if (physicalAddress)
m->second.lastOnlineAddress = physicalAddress;
m->second.lastOnlineDirty = true;
{
std::lock_guard<std::mutex> l(_state_l);
auto nw = _state.find(networkId);
if (nw != _state.end()) {
auto m = nw->second.members.find(memberId);
if (m != nw->second.members.end()) {
m->second.lastOnlineTime = OSUtils::now();
if (physicalAddress)
m->second.lastOnlineAddress = physicalAddress;
m->second.lastOnlineDirty = true;
}
}
}
{
std::lock_guard<std::mutex> l2(_changeListeners_l);
for(auto i=_changeListeners.begin();i!=_changeListeners.end();++i)
(*i)->onNetworkMemberOnline(networkId,memberId,physicalAddress);
}
}
} // namespace ZeroTier