summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--node/BandwidthAccount.hpp9
-rw-r--r--node/Network.cpp3
-rw-r--r--node/Network.hpp6
-rw-r--r--node/Switch.cpp9
4 files changed, 18 insertions, 9 deletions
diff --git a/node/BandwidthAccount.hpp b/node/BandwidthAccount.hpp
index 927037f8..42e68bfe 100644
--- a/node/BandwidthAccount.hpp
+++ b/node/BandwidthAccount.hpp
@@ -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:
diff --git a/node/Network.cpp b/node/Network.cpp
index 60f87f92..b16daaf3 100644
--- a/node/Network.cpp
+++ b/node/Network.cpp
@@ -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());
diff --git a/node/Network.hpp b/node/Network.hpp
index 88035586..2d90dac7 100644
--- a/node/Network.hpp
+++ b/node/Network.hpp
@@ -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];
diff --git a/node/Switch.cpp b/node/Switch.cpp
index 157ecec8..5ba56555 100644
--- a/node/Switch.cpp
+++ b/node/Switch.cpp
@@ -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(