Mutex locking fix.

This commit is contained in:
Adam Ierymenko 2015-04-07 11:58:41 -07:00
parent 52c3b7c34e
commit eae2c89b09

View file

@ -65,9 +65,8 @@ SelfAwareness::~SelfAwareness()
void SelfAwareness::iam(const InetAddress &reporterPhysicalAddress,const InetAddress &myPhysicalAddress,bool trusted) 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 // 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)) { if ((scope > 0)&&(scope < (unsigned int)InetAddress::IP_SCOPE_LOOPBACK)) {
/* For now only trusted peers are permitted to inform us of changes to /* 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 * our global Internet IP or to changes of NATed IPs. We'll let peers on
@ -76,7 +75,8 @@ void SelfAwareness::iam(const InetAddress &reporterPhysicalAddress,const InetAdd
* attack in which an attacker could force us to reset our connections. */ * 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())) ) if ( (!trusted) && ((scope == (unsigned int)InetAddress::IP_SCOPE_GLOBAL)||(scope != (unsigned int)reporterPhysicalAddress.ipScope())) )
return; return;
else {
Mutex::Lock _l(_lock);
InetAddress &lastPhy = _lastPhysicalAddress[scope - 1]; InetAddress &lastPhy = _lastPhysicalAddress[scope - 1];
if ((lastPhy)&&(lastPhy != myPhysicalAddress)) { if ((lastPhy)&&(lastPhy != myPhysicalAddress)) {
lastPhy = myPhysicalAddress; lastPhy = myPhysicalAddress;
@ -84,8 +84,7 @@ void SelfAwareness::iam(const InetAddress &reporterPhysicalAddress,const InetAdd
RR->topology->eachPeer<_ResetWithinScope &>(rset); RR->topology->eachPeer<_ResetWithinScope &>(rset);
} }
} }
}
Mutex::Lock _l(_lock);
} }
} // namespace ZeroTier } // namespace ZeroTier