diff options
| author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2017-02-01 13:20:51 -0800 |
|---|---|---|
| committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2017-02-01 13:20:51 -0800 |
| commit | b378f5dcd761b5ad76469708c98bf923ec1d7896 (patch) | |
| tree | 996cd3a4f1ee8f5516dd18a1e4a2951ec5c96416 /node/Switch.cpp | |
| parent | e778d45128295ddf9bbb00f4a46f103de4bc4c11 (diff) | |
| download | infinitytier-b378f5dcd761b5ad76469708c98bf923ec1d7896.tar.gz infinitytier-b378f5dcd761b5ad76469708c98bf923ec1d7896.zip | |
Take 3
Diffstat (limited to 'node/Switch.cpp')
| -rw-r--r-- | node/Switch.cpp | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/node/Switch.cpp b/node/Switch.cpp index 6185037d..1d9f6436 100644 --- a/node/Switch.cpp +++ b/node/Switch.cpp @@ -692,6 +692,7 @@ bool Switch::_trySend(Packet &packet,bool encrypt) const uint64_t now = RR->node->now(); const Address destination(packet.destination()); #ifdef ZT_ENABLE_CLUSTER + uint64_t clusterMostRecentTs = 0; int clusterMostRecentMemberId = -1; uint8_t clusterPeerSecret[ZT_PEER_SECRET_KEY_LENGTH]; #endif @@ -713,25 +714,31 @@ bool Switch::_trySend(Packet &packet,bool encrypt) } if (!viaPath) { + const SharedPtr<Peer> relay(RR->topology->getUpstreamPeer()); + if ( (!relay) || (!(viaPath = relay->getBestPath(now,false))) ) + viaPath = peer->getBestPath(now,true); + } + #ifdef ZT_ENABLE_CLUSTER - if (RR->cluster) - clusterMostRecentMemberId = RR->cluster->prepSendViaCluster(destination,clusterPeerSecret); - if (clusterMostRecentMemberId < 0) { -#endif - peer->tryMemorizedPath(now); // periodically attempt memorized or statically defined paths, if any are known - const SharedPtr<Peer> relay(RR->topology->getUpstreamPeer()); - if ( (!relay) || (!(viaPath = relay->getBestPath(now,false))) ) { - if (!(viaPath = peer->getBestPath(now,true))) // last resort: try an expired path... we usually can never get here - return false; - } -#ifdef ZT_ENABLE_CLUSTER - } -#endif + if (RR->cluster) + clusterMostRecentMemberId = RR->cluster->prepSendViaCluster(destination,clusterMostRecentTs,clusterPeerSecret); + if (clusterMostRecentMemberId >= 0) { + if ((viaPath)&&(viaPath->lastIn() < clusterMostRecentTs)) + viaPath.zero(); + } else if (!viaPath) { + peer->tryMemorizedPath(now); // periodically attempt memorized or statically defined paths, if any are known + return false; } +#else + if (!viaPath) { + peer->tryMemorizedPath(now); // periodically attempt memorized or statically defined paths, if any are known + return false; + } +#endif } else { #ifdef ZT_ENABLE_CLUSTER if (RR->cluster) - clusterMostRecentMemberId = RR->cluster->prepSendViaCluster(destination,clusterPeerSecret); + clusterMostRecentMemberId = RR->cluster->prepSendViaCluster(destination,clusterMostRecentTs,clusterPeerSecret); if (clusterMostRecentMemberId < 0) { #else requestWhois(destination); @@ -742,6 +749,7 @@ bool Switch::_trySend(Packet &packet,bool encrypt) #endif } + // Sanity checks #ifdef ZT_ENABLE_CLUSTER if ((!viaPath)&&(clusterMostRecentMemberId < 0)) return false; |
