diff options
| author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2013-08-08 17:20:35 -0400 |
|---|---|---|
| committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2013-08-08 17:20:35 -0400 |
| commit | 3af55f4423ab527a7366a56d552a4641560bc6f2 (patch) | |
| tree | 1dfa888032963a036575656832099d630eb33a75 /node/Network.hpp | |
| parent | 95c0790a88711ba1c3821df200e10c6841c3a0a9 (diff) | |
| download | infinitytier-3af55f4423ab527a7366a56d552a4641560bc6f2.tar.gz infinitytier-3af55f4423ab527a7366a56d552a4641560bc6f2.zip | |
Add RateLimiter for rate limiting multicast, not tested yet.
Diffstat (limited to 'node/Network.hpp')
| -rw-r--r-- | node/Network.hpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/node/Network.hpp b/node/Network.hpp index b42e09c1..7945569c 100644 --- a/node/Network.hpp +++ b/node/Network.hpp @@ -47,6 +47,7 @@ #include "Dictionary.hpp" #include "Identity.hpp" #include "InetAddress.hpp" +#include "RateLimiter.hpp" namespace ZeroTier { @@ -426,6 +427,25 @@ public: */ Status status() const; + /** + * Invoke multicast rate limiter gate for a given address + * + * @param addr Address to check + * @param bytes Bytes address wishes to send us / propagate + * @return True if allowed, false if overshot rate limit + */ + inline bool multicastRateGate(const Address &addr,unsigned int bytes) + { + Mutex::Lock _l(_lock); + std::map<Address,RateLimiter>::iterator rl(_multicastRateLimiters.find(addr)); + if (rl == _multicastRateLimiters.end()) { + RateLimiter &newrl = _multicastRateLimiters[addr]; + newrl.init(ZT_MULTICAST_DEFAULT_BYTES_PER_SECOND,ZT_MULTICAST_DEFAULT_RATE_PRELOAD,ZT_MULTICAST_DEFAULT_RATE_MAX); + return newrl.gate((double)bytes); + } + return rl->second.gate((double)bytes); + } + private: static void _CBhandleTapData(void *arg,const MAC &from,const MAC &to,unsigned int etherType,const Buffer<4096> &data); void _restoreState(); @@ -439,6 +459,9 @@ 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; |
