Fix deadlock in refactored code.

This commit is contained in:
Adam Ierymenko 2014-03-21 14:31:10 -07:00
parent 8d3eb1a258
commit 4e26ade2df

View file

@ -69,23 +69,25 @@ void Peer::receive(
Packet::Verb inReVerb, Packet::Verb inReVerb,
uint64_t now) uint64_t now)
{ {
Mutex::Lock _l(_lock);
if (!hops) { // direct packet if (!hops) { // direct packet
// Update receive time on known paths {
bool havePath = false; Mutex::Lock _l(_lock);
for(std::vector<Path>::iterator p(_paths.begin());p!=_paths.end();++p) {
if ((p->address() == remoteAddr)&&(p->tcp() == (fromSock->type() == Socket::ZT_SOCKET_TYPE_TCP))) {
p->received(now);
havePath = true;
break;
}
}
// Learn new UDP paths (learning TCP would require an explicit mechanism) // Update receive time on known paths
if ((!havePath)&&(fromSock->type() != Socket::ZT_SOCKET_TYPE_TCP)) { bool havePath = false;
_paths.push_back(Path(remoteAddr,false,false)); for(std::vector<Path>::iterator p(_paths.begin());p!=_paths.end();++p) {
_paths.back().received(now); if ((p->address() == remoteAddr)&&(p->tcp() == (fromSock->type() == Socket::ZT_SOCKET_TYPE_TCP))) {
p->received(now);
havePath = true;
break;
}
}
// Learn new UDP paths (learning TCP would require an explicit mechanism)
if ((!havePath)&&(fromSock->type() != Socket::ZT_SOCKET_TYPE_TCP)) {
_paths.push_back(Path(remoteAddr,false,false));
_paths.back().received(now);
}
} }
// Announce multicast LIKEs to peers to whom we have a direct link // Announce multicast LIKEs to peers to whom we have a direct link
@ -95,11 +97,10 @@ void Peer::receive(
} }
} }
if (verb == Packet::VERB_FRAME) { if (verb == Packet::VERB_FRAME)
_lastUnicastFrame = now; _lastUnicastFrame = now;
} else if (verb == Packet::VERB_MULTICAST_FRAME) { else if (verb == Packet::VERB_MULTICAST_FRAME)
_lastMulticastFrame = now; _lastMulticastFrame = now;
}
} }
bool Peer::send(const RuntimeEnvironment *_r,const void *data,unsigned int len,uint64_t now) bool Peer::send(const RuntimeEnvironment *_r,const void *data,unsigned int len,uint64_t now)