From a40b8c07f49bd9ad2748430eb9e79680059458fd Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Sat, 7 Sep 2013 15:49:38 -0400 Subject: Apply multicast rate limits to my own multicasts. Will run locally and on a variety of system types to test the result of this. --- node/BandwidthAccount.hpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'node/BandwidthAccount.hpp') diff --git a/node/BandwidthAccount.hpp b/node/BandwidthAccount.hpp index 927037f8..42e68bfe 100644 --- a/node/BandwidthAccount.hpp +++ b/node/BandwidthAccount.hpp @@ -32,6 +32,7 @@ #include #include +#include #include "Constants.hpp" #include "Utils.hpp" @@ -97,15 +98,17 @@ 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 + * @return New balance with deduction applied, and whether or not deduction fit */ - inline int32_t update(int32_t deduct) + inline std::pair update(int32_t deduct) throw() { double lt = _lastTime; double now = Utils::nowf(); _lastTime = now; - return (_balance = std::max(_minBalance,std::min(_maxBalance,(int32_t)round(((double)_balance) + (((double)_accrual) * (now - lt))) - deduct))); + 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); } private: -- cgit v1.2.3