Browse Source

Apply multicast rate limits on a network to ourselves and do not send multicasts that would exceed limits, for GitHub issue #55

Adam Ierymenko 11 years ago
parent
commit
ab5a460177
2 changed files with 6 additions and 1 deletions
  1. 1 1
      node/Network.hpp
  2. 5 0
      node/Switch.cpp

+ 1 - 1
node/Network.hpp

@@ -280,7 +280,7 @@ public:
 	/**
 	/**
 	 * Update multicast balance for an address and multicast group, return whether packet is allowed
 	 * Update multicast balance for an address and multicast group, return whether packet is allowed
 	 *
 	 *
-	 * @param a Address that wants to send/relay packet
+	 * @param a Originating address of multicast packet
 	 * @param mg Multicast group
 	 * @param mg Multicast group
 	 * @param bytes Size of packet
 	 * @param bytes Size of packet
 	 * @return True if packet is within budget
 	 * @return True if packet is within budget

+ 5 - 0
node/Switch.cpp

@@ -108,6 +108,11 @@ void Switch::onLocalEthernet(const SharedPtr<Network> &network,const MAC &from,c
 				mg = MulticastGroup::deriveMulticastGroupForAddressResolution(InetAddress(data.field(24,4),4,0));
 				mg = MulticastGroup::deriveMulticastGroupForAddressResolution(InetAddress(data.field(24,4),4,0));
 		}
 		}
 
 
+		if (!network->updateAndCheckMulticastBalance(_r->identity.address(),mg,data.size())) {
+			TRACE("%s: didn't multicast %d bytes, quota exceeded for multicast group %s",network->tapDeviceName().c_str(),(int)data.size(),mg.toString().c_str());
+			return;
+		}
+
 		const unsigned int mcid = ++_multicastIdCounter & 0xffffff;
 		const unsigned int mcid = ++_multicastIdCounter & 0xffffff;
 		const uint16_t bloomNonce = (uint16_t)(_r->prng->next32() & 0xffff); // doesn't need to be cryptographically strong
 		const uint16_t bloomNonce = (uint16_t)(_r->prng->next32() & 0xffff); // doesn't need to be cryptographically strong
 		unsigned char bloom[ZT_PROTO_VERB_MULTICAST_FRAME_LEN_PROPAGATION_BLOOM];
 		unsigned char bloom[ZT_PROTO_VERB_MULTICAST_FRAME_LEN_PROPAGATION_BLOOM];