Cleanup. Misc type conversion and signedness fixes
This commit is contained in:
parent
6a2ba4baca
commit
1debe2292d
5 changed files with 30 additions and 33 deletions
|
@ -303,11 +303,11 @@ public:
|
|||
*/
|
||||
inline float computeQuality(const int64_t now)
|
||||
{
|
||||
float latency_contrib = _meanLatency ? 1.0 / _meanLatency : 0;
|
||||
float jitter_contrib = _jitter ? 1.0 / _jitter : 0;
|
||||
float latency_contrib = _meanLatency ? (float)1.0 / _meanLatency : 0;
|
||||
float jitter_contrib = _jitter ? (float)1.0 / _jitter : 0;
|
||||
float throughput_contrib = _meanThroughput ? _meanThroughput / 1000000 : 0; // in Mbps
|
||||
float age_contrib = _meanAge > 0 ? (float)sqrt(_meanAge) : 1;
|
||||
float error_contrib = 1.0 - _meanPacketErrorRatio;
|
||||
float error_contrib = (float)1.0 - _meanPacketErrorRatio;
|
||||
float sum = (latency_contrib + jitter_contrib + throughput_contrib + error_contrib) / age_contrib;
|
||||
_lastComputedQuality = sum * (long)((_ipScope) + 1);
|
||||
return _lastComputedQuality;
|
||||
|
|
|
@ -320,12 +320,12 @@ SharedPtr<Path> Peer::getAppropriatePath(int64_t now, bool includeExpired)
|
|||
Utils::getSecureRandom(&r, 1);
|
||||
if (numAlivePaths > 0) {
|
||||
// pick a random out of the set deemed "alive"
|
||||
int rf = (float)(r %= numAlivePaths);
|
||||
int rf = r % numAlivePaths;
|
||||
return _paths[alivePaths[rf]].p;
|
||||
}
|
||||
else if(numStalePaths > 0) {
|
||||
// resort to trying any non-expired path
|
||||
int rf = (float)(r %= numStalePaths);
|
||||
int rf = r % numStalePaths;
|
||||
return _paths[stalePaths[rf]].p;
|
||||
}
|
||||
}
|
||||
|
@ -366,11 +366,9 @@ SharedPtr<Path> Peer::getAppropriatePath(int64_t now, bool includeExpired)
|
|||
// Compute quality here, going forward we will use lastComputedQuality()
|
||||
currQuality = _paths[i].p->computeQuality(now);
|
||||
if (!_paths[i].p->stale(now)) {
|
||||
alivePaths[i] = currQuality;
|
||||
numAlivePaths++;
|
||||
}
|
||||
else {
|
||||
stalePaths[i] = currQuality;
|
||||
numStalePaths++;
|
||||
}
|
||||
if (currQuality > maxQuality) {
|
||||
|
@ -412,10 +410,10 @@ SharedPtr<Path> Peer::getAppropriatePath(int64_t now, bool includeExpired)
|
|||
// randomly selected for the next packet. If however the path
|
||||
// needs to contribute more to the flow, we should record
|
||||
float imbalance = 0;
|
||||
float qualityScalingFactor = 1.0 / totalRelativeQuality;
|
||||
float qualityScalingFactor = (float)1.0 / totalRelativeQuality;
|
||||
for(uint16_t i=0;i<ZT_MAX_PEER_NETWORK_PATHS;++i) {
|
||||
// Out of the last N packets to this peer, how many were sent by this path?
|
||||
int numPktSentWithinWin = (int)_pathChoiceHist->countValue((float)i);
|
||||
int numPktSentWithinWin = (int)_pathChoiceHist->countValue(i);
|
||||
// Compute traffic allocation for each path in the flow
|
||||
if (_paths[i].p && _paths[i].p->isValidState()) {
|
||||
// Allocation
|
||||
|
@ -442,7 +440,7 @@ SharedPtr<Path> Peer::getAppropriatePath(int64_t now, bool includeExpired)
|
|||
}
|
||||
|
||||
// Compute and record current flow balance
|
||||
float balance = 1.0 - imbalance;
|
||||
float balance = (float)1.0 - imbalance;
|
||||
if (balance >= ZT_MULTIPATH_FLOW_BALANCE_THESHOLD) {
|
||||
if (!_linkBalanceStatus) {
|
||||
_linkBalanceStatus = true;
|
||||
|
|
|
@ -226,34 +226,34 @@ public:
|
|||
/**
|
||||
* @return The arithmetic mean of the contents of the buffer
|
||||
*/
|
||||
T mean()
|
||||
float mean()
|
||||
{
|
||||
size_t iterator = begin;
|
||||
T mean = 0;
|
||||
for (int i=0; i<size; i++) {
|
||||
float mean = 0;
|
||||
for (size_t i=0; i<size; i++) {
|
||||
iterator = (iterator + size - 1) % size;
|
||||
mean += *(buf + iterator);
|
||||
}
|
||||
return count() ? mean / (T)count() : 0;
|
||||
return count() ? mean / (float)count() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The sample standard deviation of the contents of the ring buffer
|
||||
*/
|
||||
T stddev()
|
||||
float stddev()
|
||||
{
|
||||
size_t iterator = begin;
|
||||
T cached_mean = mean();
|
||||
float cached_mean = mean();
|
||||
if (size) {
|
||||
T sum_of_squared_deviations = 0;
|
||||
for (int i=0; i<size; i++) {
|
||||
for (size_t i=0; i<size; i++) {
|
||||
iterator = (iterator + size - 1) % size;
|
||||
T deviation = (buf[i] - cached_mean);
|
||||
T sdev = deviation*deviation;
|
||||
float deviation = (buf[i] - cached_mean);
|
||||
float sdev = deviation*deviation;
|
||||
sum_of_squared_deviations += sdev;
|
||||
}
|
||||
T variance = sum_of_squared_deviations / (size - 1);
|
||||
T sd = sqrt(variance);
|
||||
float variance = sum_of_squared_deviations / (size - 1);
|
||||
float sd = sqrt(variance);
|
||||
return sd;
|
||||
}
|
||||
return 0;
|
||||
|
@ -266,7 +266,7 @@ public:
|
|||
{
|
||||
size_t iterator = begin;
|
||||
size_t zeros = 0;
|
||||
for (int i=0; i<size; i++) {
|
||||
for (size_t i=0; i<size; i++) {
|
||||
iterator = (iterator + size - 1) % size;
|
||||
if (*(buf + iterator) == 0) {
|
||||
zeros++;
|
||||
|
@ -283,7 +283,7 @@ public:
|
|||
{
|
||||
size_t iterator = begin;
|
||||
size_t count = 0;
|
||||
for (int i=0; i<size; i++) {
|
||||
for (size_t i=0; i<size; i++) {
|
||||
iterator = (iterator + size - 1) % size;
|
||||
if (*(buf + iterator) == value) {
|
||||
count++;
|
||||
|
@ -298,7 +298,7 @@ public:
|
|||
void dump()
|
||||
{
|
||||
size_t iterator = begin;
|
||||
for (int i=0; i<size; i++) {
|
||||
for (size_t i=0; i<size; i++) {
|
||||
iterator = (iterator + size - 1) % size;
|
||||
if (typeid(T) == typeid(int)) {
|
||||
// DEBUG_INFO("buf[%2zu]=%2d", iterator, (int)*(buf + iterator));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue