diff options
Diffstat (limited to 'node')
-rw-r--r-- | node/Network.hpp | 4 | ||||
-rw-r--r-- | node/RateLimiter.hpp | 33 |
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: |