diff --git a/node/Path.hpp b/node/Path.hpp index 5751d3265..7ce6e0f13 100644 --- a/node/Path.hpp +++ b/node/Path.hpp @@ -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; diff --git a/node/Peer.cpp b/node/Peer.cpp index 862a45294..bbc6d6d25 100644 --- a/node/Peer.cpp +++ b/node/Peer.cpp @@ -320,12 +320,12 @@ SharedPtr 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 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 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;icountValue((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 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; diff --git a/node/RingBuffer.hpp b/node/RingBuffer.hpp index 62f1cf475..cd3847491 100644 --- a/node/RingBuffer.hpp +++ b/node/RingBuffer.hpp @@ -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(s)); #if defined(_WIN32) || defined(_WIN64) - return ((long)::sendto(sws->sock,reinterpret_cast(data),len,0,to,(to->sa_family == AF_INET6) ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in)) == (long)len); + int w = ::sendto(sws->sock,reinterpret_cast(data),len,0,to,(to->sa_family == AF_INET6) ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in)) #else int w = ::sendto(sws->sock,data,len,0,to,(to->sa_family == AF_INET6) ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in)); #endif @@ -380,7 +380,7 @@ public: */ inline void refresh_link_speed_records() { - for(int i=0;iegress_time > ZT_LINK_TEST_TIMEOUT) { PhySocketImpl *sws = (reinterpret_cast(link_test_records[i]->s)); if (sws) { @@ -404,7 +404,7 @@ public: PhySocketImpl *sws = (reinterpret_cast(s)); uint64_t *id = (uint64_t*)data; #if defined(_WIN32) || defined(_WIN64) - return ((long)::sendto(sws->sock,reinterpret_cast(data),len,0,from,(from->sa_family == AF_INET6) ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in)) == (long)len); + int w = ::sendto(sws->sock,reinterpret_cast(id),sizeof(id[0]),0,from,(from->sa_family == AF_INET6) ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in)); #else int w = ::sendto(sws->sock,id,sizeof(id[0]),0,from,(from->sa_family == AF_INET6) ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in)); #endif @@ -424,12 +424,12 @@ public: */ inline bool handle_link_test_response(PhySocket *s,const struct sockaddr *from,void *data,unsigned long len) { uint64_t *id = (uint64_t*)data; - for(int i=0;iid == id[0]) { float rtt = (OSUtils::now()-link_test_records[i]->egress_time) / (float)1000; // s uint32_t sz = (link_test_records[i]->length) * 8; // bits - float transit_time = rtt / 2.0; - int64_t raw = sz / transit_time; + float transit_time = rtt / (float)2.0; + uint64_t raw = (uint64_t)(sz / transit_time); PhySocketImpl *sws = (reinterpret_cast(s)); if (sws) { sws->throughput = raw; diff --git a/service/OneService.cpp b/service/OneService.cpp index 24456f719..27930a52b 100644 --- a/service/OneService.cpp +++ b/service/OneService.cpp @@ -879,7 +879,6 @@ public: lastMultipathModeUpdate = now; _node->setMultipathMode(_multipathMode); } - // Test link speeds // TODO: This logic should eventually find its way into the core or as part of a passive // measure within the protocol. @@ -894,7 +893,7 @@ public: std::vector sockets = _binder.getBoundSockets(); // interfaces for (int i=0; ipeerCount;++j) { + for(size_t j=0;jpeerCount;++j) { for (int k=0; k<(ZT_MAX_PEER_NETWORK_PATHS/4); k++) { Utils::getSecureRandom(pktBuf, 8); // generate one random integer for unique id _phy.test_link_speed(sockets[i], (struct sockaddr*)&(pl->peers[j].paths[k].address), pktBuf, ZT_LINK_TEST_DATAGRAM_SZ); @@ -1554,7 +1553,7 @@ public: _primaryPort = (unsigned int)OSUtils::jsonInt(settings["primaryPort"],(uint64_t)_primaryPort) & 0xffff; _allowTcpFallbackRelay = OSUtils::jsonBool(settings["allowTcpFallbackRelay"],true); - _multipathMode = OSUtils::jsonInt(settings["multipathMode"],0); + _multipathMode = (unsigned int)OSUtils::jsonInt(settings["multipathMode"],0); if (_multipathMode != 0 && _allowTcpFallbackRelay) { fprintf(stderr,"WARNING: multipathMode cannot be used with allowTcpFallbackRelay. Disabling allowTcpFallbackRelay"); _allowTcpFallbackRelay = false;