diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-04-07 11:58:41 -0700 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-04-07 11:58:41 -0700 |
commit | eae2c89b0902d1ea626f17cfd87e5951698a554a (patch) | |
tree | db0e8298c7c5b490a1045b84053b7fcbb3158923 | |
parent | 52c3b7c34e52534ab4f3c92b28d65f8713cda299 (diff) | |
download | infinitytier-eae2c89b0902d1ea626f17cfd87e5951698a554a.tar.gz infinitytier-eae2c89b0902d1ea626f17cfd87e5951698a554a.zip |
Mutex locking fix.
-rw-r--r-- | node/SelfAwareness.cpp | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/node/SelfAwareness.cpp b/node/SelfAwareness.cpp index 74c9f182..951c65e8 100644 --- a/node/SelfAwareness.cpp +++ b/node/SelfAwareness.cpp @@ -65,9 +65,8 @@ SelfAwareness::~SelfAwareness() void SelfAwareness::iam(const InetAddress &reporterPhysicalAddress,const InetAddress &myPhysicalAddress,bool trusted) { - const unsigned int scope = (unsigned int)myPhysicalAddress.ipScope(); - // This code depends on the numeric values assigned to scopes in InetAddress.hpp + const unsigned int scope = (unsigned int)myPhysicalAddress.ipScope(); if ((scope > 0)&&(scope < (unsigned int)InetAddress::IP_SCOPE_LOOPBACK)) { /* For now only trusted peers are permitted to inform us of changes to * our global Internet IP or to changes of NATed IPs. We'll let peers on @@ -76,16 +75,16 @@ void SelfAwareness::iam(const InetAddress &reporterPhysicalAddress,const InetAdd * attack in which an attacker could force us to reset our connections. */ if ( (!trusted) && ((scope == (unsigned int)InetAddress::IP_SCOPE_GLOBAL)||(scope != (unsigned int)reporterPhysicalAddress.ipScope())) ) return; - - InetAddress &lastPhy = _lastPhysicalAddress[scope - 1]; - if ((lastPhy)&&(lastPhy != myPhysicalAddress)) { - lastPhy = myPhysicalAddress; - _ResetWithinScope rset(RR,RR->node->now(),(InetAddress::IpScope)scope); - RR->topology->eachPeer<_ResetWithinScope &>(rset); + else { + Mutex::Lock _l(_lock); + InetAddress &lastPhy = _lastPhysicalAddress[scope - 1]; + if ((lastPhy)&&(lastPhy != myPhysicalAddress)) { + lastPhy = myPhysicalAddress; + _ResetWithinScope rset(RR,RR->node->now(),(InetAddress::IpScope)scope); + RR->topology->eachPeer<_ResetWithinScope &>(rset); + } } } - - Mutex::Lock _l(_lock); } } // namespace ZeroTier |