summaryrefslogtreecommitdiff
path: root/node
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2013-08-30 14:15:24 -0400
committerAdam Ierymenko <adam.ierymenko@gmail.com>2013-08-30 14:15:24 -0400
commit11774f7d5fe14226e99118f95346deda51baa254 (patch)
tree721bc92f81a874ca07188576e593d63e07bfd3bc /node
parent1bd3cd422512d7d5fc562950cfaa6dee22a3c0a4 (diff)
downloadinfinitytier-11774f7d5fe14226e99118f95346deda51baa254.tar.gz
infinitytier-11774f7d5fe14226e99118f95346deda51baa254.zip
Change rate limiter a little...
Diffstat (limited to 'node')
-rw-r--r--node/Network.hpp4
-rw-r--r--node/RateLimiter.hpp33
2 files changed, 5 insertions, 32 deletions
diff --git a/node/Network.hpp b/node/Network.hpp
index 47e6430c..0cb542bf 100644
--- a/node/Network.hpp
+++ b/node/Network.hpp
@@ -47,7 +47,6 @@
#include "Dictionary.hpp"
#include "Identity.hpp"
#include "InetAddress.hpp"
-#include "RateLimiter.hpp"
namespace ZeroTier {
@@ -489,9 +488,6 @@ private:
// Membership certificates supplied by peers
std::map<Address,Certificate> _membershipCertificates;
- // Rate limiters for each multicasting peer
- std::map<Address,RateLimiter> _multicastRateLimiters;
-
// Configuration from network master node
Config _configuration;
Certificate _myCertificate;
diff --git a/node/RateLimiter.hpp b/node/RateLimiter.hpp
index e5403717..2526da48 100644
--- a/node/RateLimiter.hpp
+++ b/node/RateLimiter.hpp
@@ -107,41 +107,18 @@ public:
}
/**
- * Update balance based on current clock and supplied Limits bytesPerSecond and maxBalance
+ * Update balance based on current clock and supplied Limit
*
* @param lim Current limits in effect
- * @return New balance
+ * @param deduct Amount to deduct, or 0.0 to just update
+ * @return New balance with deduction applied
*/
- inline double updateBalance(const Limit &lim)
+ inline double update(const Limit &lim,double deduct)
throw()
{
double lt = _lastTime;
double now = _lastTime = Utils::nowf();
- return (_balance = fmin(lim.maxBalance,_balance + (lim.bytesPerSecond * (now - lt))));
- }
-
- /**
- * Update balance and test if a block of 'bytes' should be permitted to be transferred
- *
- * @param lim Current limits in effect
- * @param bytes Number of bytes that we wish to transfer
- * @return True if balance was sufficient
- */
- inline bool gate(const Limit &lim,double bytes)
- throw()
- {
- bool allow = (updateBalance(lim) >= bytes);
- _balance = fmax(lim.minBalance,_balance - bytes);
- return allow;
- }
-
- /**
- * @return Current balance
- */
- inline double balance() const
- throw()
- {
- return _balance;
+ return (_balance = fmax(lim.minBalance,fmin(lim.maxBalance,(_balance + (lim.bytesPerSecond * (now - lt))) - deduct)));
}
private: