diff --git a/node/Peer.cpp b/node/Peer.cpp index 8a5bf40c2..838136968 100644 --- a/node/Peer.cpp +++ b/node/Peer.cpp @@ -275,7 +275,7 @@ void Peer::recordIncomingPacket(void *tPtr, const SharedPtr &path, const u } } -void Peer::computeAggregateProportionalAllocation(int64_t now) +void Peer::computeAggregateAllocation(int64_t now) { float maxStability = 0; float totalRelativeQuality = 0; @@ -318,7 +318,13 @@ void Peer::computeAggregateProportionalAllocation(int64_t now) // Convert set of relative performances into an allocation set for(uint16_t i=0;iupdateComponentAllocationOfAggregateLink((unsigned char)((_paths[i].p->relativeQuality() / totalRelativeQuality) * 255)); + + if (RR->node->getMultipathMode() == ZT_MULTIPATH_RANDOM) { + _paths[i].p->updateComponentAllocationOfAggregateLink(((float)_pathChoiceHist.countValue(i) / (float)_pathChoiceHist.count()) * 255); + } + if (RR->node->getMultipathMode() == ZT_MULTIPATH_PROPORTIONALLY_BALANCED) { + _paths[i].p->updateComponentAllocationOfAggregateLink((unsigned char)((_paths[i].p->relativeQuality() / totalRelativeQuality) * 255)); + } } } } @@ -415,6 +421,7 @@ SharedPtr Peer::getAppropriatePath(int64_t now, bool includeExpired) int numAlivePaths = 0; int numStalePaths = 0; if (RR->node->getMultipathMode() == ZT_MULTIPATH_RANDOM) { + computeAggregateAllocation(now); /* This call is algorithmically inert but gives us a value to show in the status output */ int alivePaths[ZT_MAX_PEER_NETWORK_PATHS]; int stalePaths[ZT_MAX_PEER_NETWORK_PATHS]; memset(&alivePaths, -1, sizeof(alivePaths)); @@ -434,6 +441,7 @@ SharedPtr Peer::getAppropriatePath(int64_t now, bool includeExpired) unsigned int r = _freeRandomByte; if (numAlivePaths > 0) { int rf = r % numAlivePaths; + _pathChoiceHist.push(alivePaths[rf]); // Record which path we chose return _paths[alivePaths[rf]].p; } else if(numStalePaths > 0) { @@ -449,7 +457,7 @@ SharedPtr Peer::getAppropriatePath(int64_t now, bool includeExpired) if (RR->node->getMultipathMode() == ZT_MULTIPATH_PROPORTIONALLY_BALANCED) { if ((now - _lastAggregateAllocation) >= ZT_PATH_QUALITY_COMPUTE_INTERVAL) { _lastAggregateAllocation = now; - computeAggregateProportionalAllocation(now); + computeAggregateAllocation(now); } // Randomly choose path according to their allocations float rf = _freeRandomByte; diff --git a/node/Peer.hpp b/node/Peer.hpp index b4cbe0572..6d3ce553e 100644 --- a/node/Peer.hpp +++ b/node/Peer.hpp @@ -194,7 +194,7 @@ public: * * @param now Current time */ - void computeAggregateProportionalAllocation(int64_t now); + void computeAggregateAllocation(int64_t now); /** * @return The aggregate link Packet Delay Variance (PDV)