summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2014-03-21 14:31:10 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2014-03-21 14:31:10 -0700
commit4e26ade2df364b7149b1cd720f9e225542684e06 (patch)
tree63f8cd5e7a4e6492e730b9d577ccc9939ef41224
parent8d3eb1a2582ddfa7e1eba9f4e1a1dd4cdef3195e (diff)
downloadinfinitytier-4e26ade2df364b7149b1cd720f9e225542684e06.tar.gz
infinitytier-4e26ade2df364b7149b1cd720f9e225542684e06.zip
Fix deadlock in refactored code.
-rw-r--r--node/Peer.cpp35
1 files changed, 18 insertions, 17 deletions
diff --git a/node/Peer.cpp b/node/Peer.cpp
index dd6499c6..b9b9b0c7 100644
--- a/node/Peer.cpp
+++ b/node/Peer.cpp
@@ -69,23 +69,25 @@ void Peer::receive(
Packet::Verb inReVerb,
uint64_t now)
{
- Mutex::Lock _l(_lock);
-
if (!hops) { // direct packet
- // Update receive time on known paths
- bool havePath = false;
- 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;
+ {
+ Mutex::Lock _l(_lock);
+
+ // Update receive time on known paths
+ bool havePath = false;
+ 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)
- if ((!havePath)&&(fromSock->type() != Socket::ZT_SOCKET_TYPE_TCP)) {
- _paths.push_back(Path(remoteAddr,false,false));
- _paths.back().received(now);
+ // 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
@@ -95,11 +97,10 @@ void Peer::receive(
}
}
- if (verb == Packet::VERB_FRAME) {
+ if (verb == Packet::VERB_FRAME)
_lastUnicastFrame = now;
- } else if (verb == Packet::VERB_MULTICAST_FRAME) {
+ else if (verb == Packet::VERB_MULTICAST_FRAME)
_lastMulticastFrame = now;
- }
}
bool Peer::send(const RuntimeEnvironment *_r,const void *data,unsigned int len,uint64_t now)