summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Henry <josephjah@gmail.com>2018-05-02 11:22:07 -0700
committerJoseph Henry <josephjah@gmail.com>2018-05-02 11:22:07 -0700
commit1debe2292d85e2d377064f74246244ac607046bf (patch)
treed2d17652451c4d0d92b17f65bd9de66638389bc0
parent6a2ba4baca326272c45930208b70cfedf8cb1638 (diff)
downloadinfinitytier-1debe2292d85e2d377064f74246244ac607046bf.tar.gz
infinitytier-1debe2292d85e2d377064f74246244ac607046bf.zip
Cleanup. Misc type conversion and signedness fixes
-rw-r--r--node/Path.hpp6
-rw-r--r--node/Peer.cpp12
-rw-r--r--node/RingBuffer.hpp28
-rw-r--r--osdep/Phy.hpp12
-rw-r--r--service/OneService.cpp5
5 files changed, 30 insertions, 33 deletions
diff --git a/node/Path.hpp b/node/Path.hpp
index 5751d326..7ce6e0f1 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 862a4529..bbc6d6d2 100644
--- a/node/Peer.cpp
+++ b/node/Peer.cpp
@@ -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;
diff --git a/node/RingBuffer.hpp b/node/RingBuffer.hpp
index 62f1cf47..cd384749 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<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));
diff --git a/osdep/Phy.hpp b/osdep/Phy.hpp
index d4f68681..2e276a2a 100644
--- a/osdep/Phy.hpp
+++ b/osdep/Phy.hpp
@@ -365,7 +365,7 @@ public:
uint64_t egress_time = OSUtils::now();
PhySocketImpl *sws = (reinterpret_cast<PhySocketImpl *>(s));
#if defined(_WIN32) || defined(_WIN64)
- return ((long)::sendto(sws->sock,reinterpret_cast<const char *>(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<const char *>(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;i<link_test_records.size();i++) {
+ for(size_t i=0;i<link_test_records.size();i++) {
if(OSUtils::now() - link_test_records[i]->egress_time > ZT_LINK_TEST_TIMEOUT) {
PhySocketImpl *sws = (reinterpret_cast<PhySocketImpl *>(link_test_records[i]->s));
if (sws) {
@@ -404,7 +404,7 @@ public:
PhySocketImpl *sws = (reinterpret_cast<PhySocketImpl *>(s));
uint64_t *id = (uint64_t*)data;
#if defined(_WIN32) || defined(_WIN64)
- return ((long)::sendto(sws->sock,reinterpret_cast<const char *>(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<const char *>(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;i<link_test_records.size();i++) {
+ for(size_t i=0;i<link_test_records.size();i++) {
if(link_test_records[i]->id == 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<PhySocketImpl *>(s));
if (sws) {
sws->throughput = raw;
diff --git a/service/OneService.cpp b/service/OneService.cpp
index 24456f71..27930a52 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<PhySocket*> sockets = _binder.getBoundSockets();
// interfaces
for (int i=0; i<ZT_BINDER_MAX_BINDINGS; i++) {
- for(int j=0;j<pl->peerCount;++j) {
+ for(size_t j=0;j<pl->peerCount;++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;