mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 20:43:44 +02:00
Change rate limiter a little...
This commit is contained in:
parent
1bd3cd4225
commit
11774f7d5f
2 changed files with 5 additions and 32 deletions
|
@ -47,7 +47,6 @@
|
||||||
#include "Dictionary.hpp"
|
#include "Dictionary.hpp"
|
||||||
#include "Identity.hpp"
|
#include "Identity.hpp"
|
||||||
#include "InetAddress.hpp"
|
#include "InetAddress.hpp"
|
||||||
#include "RateLimiter.hpp"
|
|
||||||
|
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
|
||||||
|
@ -489,9 +488,6 @@ private:
|
||||||
// Membership certificates supplied by peers
|
// Membership certificates supplied by peers
|
||||||
std::map<Address,Certificate> _membershipCertificates;
|
std::map<Address,Certificate> _membershipCertificates;
|
||||||
|
|
||||||
// Rate limiters for each multicasting peer
|
|
||||||
std::map<Address,RateLimiter> _multicastRateLimiters;
|
|
||||||
|
|
||||||
// Configuration from network master node
|
// Configuration from network master node
|
||||||
Config _configuration;
|
Config _configuration;
|
||||||
Certificate _myCertificate;
|
Certificate _myCertificate;
|
||||||
|
|
|
@ -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
|
* @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()
|
throw()
|
||||||
{
|
{
|
||||||
double lt = _lastTime;
|
double lt = _lastTime;
|
||||||
double now = _lastTime = Utils::nowf();
|
double now = _lastTime = Utils::nowf();
|
||||||
return (_balance = fmin(lim.maxBalance,_balance + (lim.bytesPerSecond * (now - lt))));
|
return (_balance = fmax(lim.minBalance,fmin(lim.maxBalance,(_balance + (lim.bytesPerSecond * (now - lt))) - deduct)));
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Add table
Reference in a new issue