summaryrefslogtreecommitdiff
path: root/node/BandwidthAccount.hpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2013-09-07 15:49:38 -0400
committerAdam Ierymenko <adam.ierymenko@gmail.com>2013-09-07 15:49:38 -0400
commita40b8c07f49bd9ad2748430eb9e79680059458fd (patch)
tree107b2d5819126342bb18543350264f4ffdb5e39d /node/BandwidthAccount.hpp
parentcdb96726df0f383c20bc83448a4e2427317371c0 (diff)
downloadinfinitytier-a40b8c07f49bd9ad2748430eb9e79680059458fd.tar.gz
infinitytier-a40b8c07f49bd9ad2748430eb9e79680059458fd.zip
Apply multicast rate limits to my own multicasts. Will run locally and on a variety of system types to test the result of this.
Diffstat (limited to 'node/BandwidthAccount.hpp')
-rw-r--r--node/BandwidthAccount.hpp9
1 files changed, 6 insertions, 3 deletions
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 <math.h>
#include <algorithm>
+#include <utility>
#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<int32_t,bool> 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<int32_t,bool>((_balance = std::max(_minBalance,std::min(_maxBalance,newbal))),fits);
}
private: