summaryrefslogtreecommitdiff
path: root/node
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2017-02-01 13:52:53 -0800
committerAdam Ierymenko <adam.ierymenko@gmail.com>2017-02-01 13:52:53 -0800
commit60ff280dcb213a3e50eb410184493ace1d4c2736 (patch)
treef6c4195c28955909d740a60f9afa3c92e0433e53 /node
parentb378f5dcd761b5ad76469708c98bf923ec1d7896 (diff)
downloadinfinitytier-60ff280dcb213a3e50eb410184493ace1d4c2736.tar.gz
infinitytier-60ff280dcb213a3e50eb410184493ace1d4c2736.zip
Another tweak to cluster I/O rules.
Diffstat (limited to 'node')
-rw-r--r--node/Cluster.cpp2
-rw-r--r--node/Cluster.hpp2
-rw-r--r--node/Peer.hpp2
-rw-r--r--node/Switch.cpp47
4 files changed, 25 insertions, 28 deletions
diff --git a/node/Cluster.cpp b/node/Cluster.cpp
index 75a9f29b..3e33d802 100644
--- a/node/Cluster.cpp
+++ b/node/Cluster.cpp
@@ -516,7 +516,7 @@ void Cluster::broadcastNetworkConfigChunk(const void *chunk,unsigned int len)
}
}
-int Cluster::prepSendViaCluster(const Address &toPeerAddress,uint64_t &mostRecentTs,void *peerSecret)
+int Cluster::checkSendViaCluster(const Address &toPeerAddress,uint64_t &mostRecentTs,void *peerSecret)
{
const uint64_t now = RR->node->now();
mostRecentTs = 0;
diff --git a/node/Cluster.hpp b/node/Cluster.hpp
index 72fcd04d..cd6a3bb9 100644
--- a/node/Cluster.hpp
+++ b/node/Cluster.hpp
@@ -289,7 +289,7 @@ public:
* @param peerSecret Result: Buffer to fill with peer secret on valid return value, must be at least ZT_PEER_SECRET_KEY_LENGTH bytes
* @return -1 if cluster does not know this peer, or a member ID to pass to sendViaCluster()
*/
- int prepSendViaCluster(const Address &toPeerAddress,uint64_t &mostRecentTs,void *peerSecret);
+ int checkSendViaCluster(const Address &toPeerAddress,uint64_t &mostRecentTs,void *peerSecret);
/**
* Send data via cluster front plane (packet head or fragment)
diff --git a/node/Peer.hpp b/node/Peer.hpp
index 78b345b9..06abde3f 100644
--- a/node/Peer.hpp
+++ b/node/Peer.hpp
@@ -137,7 +137,7 @@ public:
* Get the best current direct path
*
* @param now Current time
- * @param includeDead If true, include even expired paths
+ * @param includeExpired If true, include even expired paths
* @return Best current path or NULL if none
*/
SharedPtr<Path> getBestPath(uint64_t now,bool includeExpired);
diff --git a/node/Switch.cpp b/node/Switch.cpp
index 1d9f6436..6860b865 100644
--- a/node/Switch.cpp
+++ b/node/Switch.cpp
@@ -691,10 +691,13 @@ bool Switch::_trySend(Packet &packet,bool encrypt)
SharedPtr<Path> viaPath;
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];
+ if (RR->cluster)
+ clusterMostRecentMemberId = RR->cluster->checkSendViaCluster(destination,clusterMostRecentTs,clusterPeerSecret);
#endif
const SharedPtr<Peer> peer(RR->topology->getPeer(destination));
@@ -708,37 +711,40 @@ bool Switch::_trySend(Packet &packet,bool encrypt)
viaPath = peer->getBestPath(now,false);
if ( (viaPath) && (!viaPath->alive(now)) && (!RR->topology->isUpstream(peer->identity())) ) {
- if ((now - viaPath->lastOut()) > std::max((now - viaPath->lastIn()) * 4,(uint64_t)ZT_PATH_MIN_REACTIVATE_INTERVAL))
- peer->attemptToContactAt(viaPath->localAddress(),viaPath->address(),now);
+#ifdef ZT_ENABLE_CLUSTER
+ if ((clusterMostRecentMemberId < 0)||(viaPath->lastIn() > clusterMostRecentTs)) {
+#endif
+ if ((now - viaPath->lastOut()) > std::max((now - viaPath->lastIn()) * 4,(uint64_t)ZT_PATH_MIN_REACTIVATE_INTERVAL)) {
+ peer->attemptToContactAt(viaPath->localAddress(),viaPath->address(),now);
+ viaPath->sent(now);
+ }
+#ifdef ZT_ENABLE_CLUSTER
+ }
+#endif
viaPath.zero();
}
- 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,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) {
+#endif
peer->tryMemorizedPath(now); // periodically attempt memorized or statically defined paths, if any are known
- return false;
+ const SharedPtr<Peer> relay(RR->topology->getUpstreamPeer());
+ if ( (!relay) || (!(viaPath = relay->getBestPath(now,false))) ) {
+ if (!(viaPath = peer->getBestPath(now,true)))
+ return false;
+ }
+#ifdef ZT_ENABLE_CLUSTER
+ }
+#else
}
#endif
} else {
#ifdef ZT_ENABLE_CLUSTER
- if (RR->cluster)
- clusterMostRecentMemberId = RR->cluster->prepSendViaCluster(destination,clusterMostRecentTs,clusterPeerSecret);
if (clusterMostRecentMemberId < 0) {
#else
requestWhois(destination);
@@ -749,15 +755,6 @@ bool Switch::_trySend(Packet &packet,bool encrypt)
#endif
}
- // Sanity checks
-#ifdef ZT_ENABLE_CLUSTER
- if ((!viaPath)&&(clusterMostRecentMemberId < 0))
- return false;
-#else
- if (!viaPath)
- return false;
-#endif
-
unsigned int chunkSize = std::min(packet.size(),(unsigned int)ZT_UDP_DEFAULT_PAYLOAD_MTU);
packet.setFragmented(chunkSize < packet.size());