diff --git a/Makefile.linux b/Makefile.linux index 68b2437ef..50978a394 100644 --- a/Makefile.linux +++ b/Makefile.linux @@ -1,7 +1,7 @@ CC=gcc CXX=g++ -INCLUDES=-Iext/bin/libcrypto/include -Iext/jsoncpp/include +INCLUDES=-Iext/bin/libcrypto/include ARCH=$(shell uname -m) DEFS=-DZT_ARCH="$(ARCH)" -DZT_OSNAME="linux" -DZT_TRACE diff --git a/node/BandwidthAccount.hpp b/node/BandwidthAccount.hpp index 42e68bfe8..1f337ca46 100644 --- a/node/BandwidthAccount.hpp +++ b/node/BandwidthAccount.hpp @@ -31,9 +31,6 @@ #include #include -#include -#include - #include "Constants.hpp" #include "Utils.hpp" @@ -66,30 +63,27 @@ public: * Create and initialize * * @param preload Initial balance to place in account - * @param minb Minimum allowed balance (or maximum debt) (<= 0) * @param maxb Maximum allowed balance (> 0) * @param acc Rate of accrual in bytes per second */ - BandwidthAccount(int32_t preload,int32_t minb,int32_t maxb,int32_t acc) + BandwidthAccount(int32_t preload,int32_t maxb,int32_t acc) throw() { - init(preload,minb,maxb,acc); + init(preload,maxb,acc); } /** * Initialize or re-initialize account * * @param preload Initial balance to place in account - * @param minb Minimum allowed balance (or maximum debt) (<= 0) * @param maxb Maximum allowed balance (> 0) * @param acc Rate of accrual in bytes per second */ - inline void init(int32_t preload,int32_t minb,int32_t maxb,int32_t acc) + inline void init(int32_t preload,int32_t maxb,int32_t acc) throw() { _lastTime = Utils::nowf(); _balance = preload; - _minBalance = minb; _maxBalance = maxb; _accrual = acc; } @@ -98,23 +92,22 @@ public: * Update balance by accruing and then deducting * * @param deduct Amount to deduct, or 0.0 to just update - * @return New balance with deduction applied, and whether or not deduction fit + * @return New balance after deduction -- if negative, it didn't fit */ - inline std::pair update(int32_t deduct) + inline int32_t update(int32_t deduct) throw() { double lt = _lastTime; double now = Utils::nowf(); _lastTime = now; int32_t newbal = (int32_t)round((double)_balance + ((double)_accrual * (now - lt))) - deduct; - bool fits = (newbal > 0); - return std::pair((_balance = std::max(_minBalance,std::min(_maxBalance,newbal))),fits); + _balance = std::max((int32_t)0,std::min(_maxBalance,newbal)); + return newbal; } private: double _lastTime; int32_t _balance; - int32_t _minBalance; int32_t _maxBalance; int32_t _accrual; }; diff --git a/node/Network.cpp b/node/Network.cpp index b16daaf3e..3fd0e428f 100644 --- a/node/Network.cpp +++ b/node/Network.cpp @@ -91,7 +91,7 @@ bool Network::Certificate::qualifyMembership(const Network::Certificate &mc) con } // A low default global rate, fast enough for something like ARP -const Network::MulticastRates::Rate Network::MulticastRates::GLOBAL_DEFAULT_RATE(128,-32,128,64); +const Network::MulticastRates::Rate Network::MulticastRates::GLOBAL_DEFAULT_RATE(128,128,64); const char *Network::statusString(const Status s) throw() diff --git a/node/Network.hpp b/node/Network.hpp index 76718a77e..0cf50e1f9 100644 --- a/node/Network.hpp +++ b/node/Network.hpp @@ -166,10 +166,9 @@ public: * Preload and rates of accrual for multicast group bandwidth limits * * Key is multicast group in lower case hex format: MAC (without :s) / - * ADI (hex). Value is a comma-delimited list of: preload, min, max, - * rate of accrual for bandwidth accounts. A key called '*' indicates - * the default for unlisted groups. Values are in hexadecimal and may - * be prefixed with '-' to indicate a negative value. + * ADI (hex). Value is preload, maximum balance, and rate of accrual in + * hex. These are signed hex numbers, so a negative value can be prefixed + * with '-'. */ class MulticastRates : private Dictionary { @@ -180,15 +179,13 @@ public: struct Rate { Rate() {} - Rate(int32_t pl,int32_t minb,int32_t maxb,int32_t acc) + Rate(int32_t pl,int32_t maxb,int32_t acc) { preload = pl; - minBalance = minb; maxBalance = maxb; accrual = acc; } int32_t preload; - int32_t minBalance; int32_t maxBalance; int32_t accrual; }; @@ -234,7 +231,7 @@ public: { char tmp[16384]; Utils::scopy(tmp,sizeof(tmp),s.c_str()); - Rate r(0,0,0,0); + Rate r(0,0,0); char *saveptr = (char *)0; unsigned int fn = 0; for(char *f=Utils::stok(tmp,",",&saveptr);(f);f=Utils::stok((char *)0,",",&saveptr)) { @@ -243,12 +240,9 @@ public: r.preload = (int32_t)Utils::hexStrToLong(f); break; case 1: - r.minBalance = (int32_t)Utils::hexStrToLong(f); - break; - case 2: r.maxBalance = (int32_t)Utils::hexStrToLong(f); break; - case 3: + case 2: r.accrual = (int32_t)Utils::hexStrToLong(f); break; } @@ -577,9 +571,9 @@ public: std::map< std::pair,BandwidthAccount >::iterator bal(_multicastRateAccounts.find(k)); if (bal == _multicastRateAccounts.end()) { MulticastRates::Rate r(_mcRates.get(mg)); - bal = _multicastRateAccounts.insert(std::make_pair(k,BandwidthAccount(r.preload,r.minBalance,r.maxBalance,r.accrual))).first; + bal = _multicastRateAccounts.insert(std::pair< std::pair,BandwidthAccount >(k,BandwidthAccount(r.preload,r.maxBalance,r.accrual))).first; } - return bal->second.update((int32_t)bytes).second; + return (bal->second.update((int32_t)bytes) >= 0); } private: