From e778d45128295ddf9bbb00f4a46f103de4bc4c11 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Wed, 1 Feb 2017 12:51:52 -0800 Subject: [PATCH] Still want to send WANT_PEER under two failure modes. --- node/Cluster.cpp | 48 +++++++++++++++++++++++------------------------- node/Switch.cpp | 27 ++++++++++++++------------- 2 files changed, 37 insertions(+), 38 deletions(-) diff --git a/node/Cluster.cpp b/node/Cluster.cpp index a24cf99d0..ef09e8423 100644 --- a/node/Cluster.cpp +++ b/node/Cluster.cpp @@ -536,37 +536,35 @@ int Cluster::prepSendViaCluster(const Address &toPeerAddress,void *peerSecret) } } - if (mostRecentMemberId >= 0) { - const uint64_t ageOfMostRecentHavePeerAnnouncement = now - mostRecentTs; - if (ageOfMostRecentHavePeerAnnouncement >= (ZT_PEER_ACTIVITY_TIMEOUT / 3)) { - if (ageOfMostRecentHavePeerAnnouncement >= ZT_PEER_ACTIVITY_TIMEOUT) - return -1; + const uint64_t ageOfMostRecentHavePeerAnnouncement = now - mostRecentTs; + if (ageOfMostRecentHavePeerAnnouncement >= (ZT_PEER_ACTIVITY_TIMEOUT / 3)) { + if (ageOfMostRecentHavePeerAnnouncement >= ZT_PEER_ACTIVITY_TIMEOUT) + mostRecentMemberId = -1; - bool sendWantPeer = true; - { - Mutex::Lock _l(_remotePeers_m); - _RemotePeer &rp = _remotePeers[std::pair(toPeerAddress,(unsigned int)_id)]; - if ((now - rp.lastSentWantPeer) >= ZT_CLUSTER_WANT_PEER_EVERY) { - rp.lastSentWantPeer = now; - } else { - sendWantPeer = false; // don't flood WANT_PEER - } + bool sendWantPeer = true; + { + Mutex::Lock _l(_remotePeers_m); + _RemotePeer &rp = _remotePeers[std::pair(toPeerAddress,(unsigned int)_id)]; + if ((now - rp.lastSentWantPeer) >= ZT_CLUSTER_WANT_PEER_EVERY) { + rp.lastSentWantPeer = now; + } else { + sendWantPeer = false; // don't flood WANT_PEER } - if (sendWantPeer) { - char tmp[ZT_ADDRESS_LENGTH]; - toPeerAddress.copyTo(tmp,ZT_ADDRESS_LENGTH); - { - Mutex::Lock _l(_memberIds_m); - for(std::vector::const_iterator mid(_memberIds.begin());mid!=_memberIds.end();++mid) { - Mutex::Lock _l2(_members[*mid].lock); - _send(*mid,CLUSTER_MESSAGE_WANT_PEER,tmp,ZT_ADDRESS_LENGTH); - } + } + if (sendWantPeer) { + char tmp[ZT_ADDRESS_LENGTH]; + toPeerAddress.copyTo(tmp,ZT_ADDRESS_LENGTH); + { + Mutex::Lock _l(_memberIds_m); + for(std::vector::const_iterator mid(_memberIds.begin());mid!=_memberIds.end();++mid) { + Mutex::Lock _l2(_members[*mid].lock); + _send(*mid,CLUSTER_MESSAGE_WANT_PEER,tmp,ZT_ADDRESS_LENGTH); } } } + } - return mostRecentMemberId; - } else return -1; + return mostRecentMemberId; } bool Cluster::sendViaCluster(int mostRecentMemberId,const Address &toPeerAddress,const void *data,unsigned int len) diff --git a/node/Switch.cpp b/node/Switch.cpp index d4f477f00..6185037df 100644 --- a/node/Switch.cpp +++ b/node/Switch.cpp @@ -729,24 +729,25 @@ bool Switch::_trySend(Packet &packet,bool encrypt) #endif } } else { - requestWhois(destination); -#ifndef ZT_ENABLE_CLUSTER - return false; // if we are not in cluster mode, there is no way we can send without knowing the peer directly +#ifdef ZT_ENABLE_CLUSTER + if (RR->cluster) + clusterMostRecentMemberId = RR->cluster->prepSendViaCluster(destination,clusterPeerSecret); + if (clusterMostRecentMemberId < 0) { +#else + requestWhois(destination); + return false; // if we are not in cluster mode, there is no way we can send without knowing the peer directly +#endif +#ifdef ZT_ENABLE_CLUSTER + } #endif } -#ifdef ZT_TRACE #ifdef ZT_ENABLE_CLUSTER - if ((!viaPath)&&(clusterMostRecentMemberId < 0)) { - TRACE("BUG: both viaPath and clusterMostRecentMemberId ended up invalid in Switch::_trySend()!"); - abort(); - } + if ((!viaPath)&&(clusterMostRecentMemberId < 0)) + return false; #else - if (!viaPath) { - TRACE("BUG: viaPath ended up NULL in Switch::_trySend()!"); - abort(); - } -#endif + if (!viaPath) + return false; #endif unsigned int chunkSize = std::min(packet.size(),(unsigned int)ZT_UDP_DEFAULT_PAYLOAD_MTU);