mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-07 19:24:13 +00:00
Apply multicast rate limits to my own multicasts. Will run locally and on a variety of system types to test the result of this.
This commit is contained in:
parent
cdb96726df
commit
a40b8c07f4
@ -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:
|
||||
|
@ -91,7 +91,7 @@ bool Network::Certificate::qualifyMembership(const Network::Certificate &mc) con
|
||||
}
|
||||
|
||||
// A low default global rate, fast enough for something like ARP
|
||||
const Network::MulticastRates::Rate Network::MulticastRates::GLOBAL_DEFAULT_RATE(256.0,-32.0,256.0,64.0);
|
||||
const Network::MulticastRates::Rate Network::MulticastRates::GLOBAL_DEFAULT_RATE(128,-32,128,64);
|
||||
|
||||
const char *Network::statusString(const Status s)
|
||||
throw()
|
||||
@ -154,6 +154,7 @@ void Network::setConfiguration(const Network::Config &conf)
|
||||
//TRACE("network %.16llx got netconf:\n%s",(unsigned long long)_id,conf.toString().c_str());
|
||||
_configuration = conf;
|
||||
_myCertificate = conf.certificateOfMembership();
|
||||
_mcRates = conf.multicastRates();
|
||||
_lastConfigUpdate = Utils::now();
|
||||
|
||||
_tap->setIps(conf.staticAddresses());
|
||||
|
@ -553,7 +553,7 @@ public:
|
||||
MulticastRates::Rate r(_mcRates.get(mg));
|
||||
bal = _multicastRateAccounts.insert(std::make_pair(k,BandwidthAccount(r.preload,r.minBalance,r.maxBalance,r.accrual))).first;
|
||||
}
|
||||
return (bal->second.update((int32_t)bytes) < (int32_t)bytes);
|
||||
return bal->second.update((int32_t)bytes).second;
|
||||
}
|
||||
|
||||
private:
|
||||
@ -574,8 +574,8 @@ private:
|
||||
|
||||
// Configuration from network master node
|
||||
Config _configuration;
|
||||
Certificate _myCertificate;
|
||||
MulticastRates _mcRates;
|
||||
Certificate _myCertificate; // memoized from _configuration
|
||||
MulticastRates _mcRates; // memoized from _configuration
|
||||
|
||||
// Ethertype whitelist bit field, set from config, for really fast lookup
|
||||
unsigned char _etWhitelist[65536 / 8];
|
||||
|
@ -100,13 +100,18 @@ void Switch::onLocalEthernet(const SharedPtr<Network> &network,const MAC &from,c
|
||||
MulticastGroup mg(to,0);
|
||||
|
||||
if (to.isBroadcast()) {
|
||||
// Handle broadcast special cases
|
||||
|
||||
// Cram IPv4 IP into ADI field to make IPv4 ARP broadcast channel specific and scalable
|
||||
if ((etherType == ZT_ETHERTYPE_ARP)&&(data.size() == 28)&&(data[2] == 0x08)&&(data[3] == 0x00)&&(data[4] == 6)&&(data[5] == 4)&&(data[7] == 0x01))
|
||||
mg = MulticastGroup::deriveMulticastGroupForAddressResolution(InetAddress(data.field(24,4),4,0));
|
||||
}
|
||||
|
||||
// Check our own multicasts against the global rate for this network
|
||||
// just to be polite.
|
||||
if (!network->updateAndCheckMulticastBalance(_r->identity.address(),mg,data.size())) {
|
||||
LOG("didn't send local multicast %u byte multicast packet to network %.16llx: not within budget for multicast group %s",(unsigned int)data.size(),(unsigned long long)network->id(),mg.toString().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
Multicaster::MulticastBloomFilter bloom;
|
||||
SharedPtr<Peer> propPeers[ZT_MULTICAST_PROPAGATION_BREADTH];
|
||||
unsigned int np = _r->multicaster->pickSocialPropagationPeers(
|
||||
|
Loading…
x
Reference in New Issue
Block a user