From 46a7a2be2e1c4d09d1da2bf26b110a31ec3d0661 Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Wed, 30 May 2018 17:45:29 -0700 Subject: Added VERB_ACK and VERB_QOS_MEASUREMENT, refined notion of path quality --- node/Utils.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'node/Utils.hpp') diff --git a/node/Utils.hpp b/node/Utils.hpp index a24f2c9a..6ce67328 100644 --- a/node/Utils.hpp +++ b/node/Utils.hpp @@ -261,6 +261,14 @@ public: return l; } + static inline float normalize(float value, int64_t bigMin, int64_t bigMax, int32_t targetMin, int32_t targetMax) + { + int64_t bigSpan = bigMax - bigMin; + int64_t smallSpan = targetMax - targetMin; + float valueScaled = (value - (float)bigMin) / (float)bigSpan; + return (float)targetMin + valueScaled * (float)smallSpan; + } + /** * Generate secure random bytes * -- cgit v1.2.3 From 88abd6ffc61b76fc244b9f7e885d6d9d64cb506e Mon Sep 17 00:00:00 2001 From: Dave Cottlehuber Date: Fri, 22 Jun 2018 21:05:53 +0000 Subject: add support for debug flags in FreeBSD --- include/ZeroTierDebug.h | 5 ++++- make-bsd.mk | 2 +- node/Trace.cpp | 1 + node/Utils.hpp | 16 ++++++++++++++-- 4 files changed, 20 insertions(+), 4 deletions(-) (limited to 'node/Utils.hpp') diff --git a/include/ZeroTierDebug.h b/include/ZeroTierDebug.h index 8e5366f0..752c40da 100644 --- a/include/ZeroTierDebug.h +++ b/include/ZeroTierDebug.h @@ -76,6 +76,9 @@ #ifdef __APPLE__ #define ZT_THREAD_ID (long)0 // (long)gettid() #endif +#ifdef __FreeBSD__ + #define ZT_THREAD_ID (long)0 // (long)gettid() +#endif #ifdef _WIN32 #define ZT_THREAD_ID (long)0 // #endif @@ -96,7 +99,7 @@ #define DEBUG_INFO(fmt, ...) fprintf(stderr, ZT_GRN "INFO [%ld]: %17s:%5d:%25s: " fmt "\n" \ ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, __VA_ARGS__) #endif - #if defined(__linux__) or defined(__APPLE__) + #if defined(__linux__) or defined(__APPLE__) or defined(__FreeBSD__) #define DEBUG_INFO(fmt, args ...) fprintf(stderr, ZT_GRN "INFO [%ld]: %17s:%5d:%25s: " fmt "\n" \ ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args) #endif diff --git a/make-bsd.mk b/make-bsd.mk index 713cafc0..d17d5803 100644 --- a/make-bsd.mk +++ b/make-bsd.mk @@ -159,7 +159,7 @@ clean: rm -rf *.a *.o node/*.o controller/*.o osdep/*.o service/*.o ext/http-parser/*.o build-* zerotier-one zerotier-idtool zerotier-selftest zerotier-cli $(ONE_OBJS) $(CORE_OBJS) debug: FORCE - gmake -j 4 ZT_DEBUG=1 + $(MAKE) -j ZT_DEBUG=1 install: one rm -f /usr/local/sbin/zerotier-one diff --git a/node/Trace.cpp b/node/Trace.cpp index 386edaac..451f5806 100644 --- a/node/Trace.cpp +++ b/node/Trace.cpp @@ -40,6 +40,7 @@ #include "Tag.hpp" #include "Capability.hpp" #include "Revocation.hpp" +#include "../include/ZeroTierDebug.h" namespace ZeroTier { diff --git a/node/Utils.hpp b/node/Utils.hpp index a24f2c9a..cb107391 100644 --- a/node/Utils.hpp +++ b/node/Utils.hpp @@ -38,6 +38,10 @@ #include #include +#if defined(__FreeBSD__) +#include +#endif + #include "Constants.hpp" #ifdef __LINUX__ @@ -411,8 +415,12 @@ public: static inline uint64_t hton(uint64_t n) { #if __BYTE_ORDER == __LITTLE_ENDIAN -#if defined(__GNUC__) && (!defined(__OpenBSD__)) +#if defined(__GNUC__) +#if defined(__FreeBSD__) + return bswap64(n); +#elif (!defined(__OpenBSD__)) return __builtin_bswap64(n); +#endif #else return ( ((n & 0x00000000000000FFULL) << 56) | @@ -440,8 +448,12 @@ public: static inline uint64_t ntoh(uint64_t n) { #if __BYTE_ORDER == __LITTLE_ENDIAN -#if defined(__GNUC__) && !defined(__OpenBSD__) +#if defined(__GNUC__) +#if defined(__FreeBSD__) + return bswap64(n); +#elif (!defined(__OpenBSD__)) return __builtin_bswap64(n); +#endif #else return ( ((n & 0x00000000000000FFULL) << 56) | -- cgit v1.2.3