Browse Source

Make multicast gathering a bit smarter.

Adam Ierymenko 11 years ago
parent
commit
49dc47ff38
5 changed files with 26 additions and 32 deletions
  1. 0 5
      node/Constants.hpp
  2. 1 1
      node/IncomingPacket.cpp
  3. 24 22
      node/Multicaster.cpp
  4. 1 3
      node/Multicaster.hpp
  5. 0 1
      node/Switch.cpp

+ 0 - 5
node/Constants.hpp

@@ -250,11 +250,6 @@
  */
 #define ZT_MULTICAST_TRANSMIT_TIMEOUT 5000
 
-/**
- * Default number of endpoints to implicitly gather from peers with each multicast frame
- */
-#define ZT_MULTICAST_DEFAULT_IMPLICIT_GATHER 8
-
 /**
  * Default maximum number of peers to address with a single multicast (if unspecified in network)
  */

+ 1 - 1
node/IncomingPacket.cpp

@@ -796,7 +796,7 @@ bool IncomingPacket::_doMULTICAST_LIKE(const RuntimeEnvironment *RR,const Shared
 
 		// Iterate through 18-byte network,MAC,ADI tuples
 		for(unsigned int ptr=ZT_PACKET_IDX_PAYLOAD;ptr<size();ptr+=18)
-			RR->mc->subscribe(now,at<uint64_t>(ptr),MulticastGroup(MAC(field(ptr + 8,6),6),at<uint32_t>(ptr + 14)),Address(),src);
+			RR->mc->add(now,at<uint64_t>(ptr),MulticastGroup(MAC(field(ptr + 8,6),6),at<uint32_t>(ptr + 14)),Address(),src);
 
 		peer->receive(RR,_fromSock,_remoteAddress,hops(),packetId(),Packet::VERB_MULTICAST_LIKE,0,Packet::VERB_NOP,now);
 	} catch (std::exception &ex) {

+ 24 - 22
node/Multicaster.cpp

@@ -107,7 +107,6 @@ restart_member_scan:
 void Multicaster::send(
 	const CertificateOfMembership *com,
 	unsigned int limit,
-	unsigned int gatherLimit,
 	uint64_t now,
 	uint64_t nwid,
 	const MulticastGroup &mg,
@@ -129,7 +128,7 @@ void Multicaster::send(
 			nwid,
 			com,
 			limit,
-			gatherLimit,
+			0,
 			src,
 			mg,
 			etherType,
@@ -143,25 +142,7 @@ void Multicaster::send(
 				break;
 		}
 	} else {
-		// If we don't already have enough members, send to the ones we have and then gather (if allowed within gather rate limit delay)
-		gs.txQueue.push_back(OutboundMulticast());
-		OutboundMulticast &out = gs.txQueue.back();
-
-		out.init(
-			now,
-			RR->identity.address(),
-			nwid,
-			com,
-			limit,
-			gatherLimit,
-			src,
-			mg,
-			etherType,
-			data,
-			len);
-
-		for(std::vector<MulticastGroupMember>::const_reverse_iterator m(gs.members.rbegin());m!=gs.members.rend();++m)
-			out.sendAndLog(*(RR->sw),m->address);
+		unsigned int gatherLimit = (limit - (unsigned int)gs.members.size()) + 1;
 
 		if ((now - gs.lastExplicitGather) >= ZT_MULTICAST_GATHER_DELAY) {
 			gs.lastExplicitGather = now;
@@ -178,11 +159,32 @@ void Multicaster::send(
 				outp.append((uint8_t)0);
 				mg.mac().appendTo(outp);
 				outp.append((uint32_t)mg.adi());
-				outp.append((uint32_t)((limit - (unsigned int)gs.members.size()) + 1)); // +1 just means we'll have an extra in the queue if available
+				outp.append((uint32_t)gatherLimit); // +1 just means we'll have an extra in the queue if available
 				outp.armor(sn->key(),true);
 				sn->send(RR,outp.data(),outp.size(),now);
 			}
+
+			gatherLimit = 0; // once we've done this we don't need to do it implicitly
 		}
+
+		gs.txQueue.push_back(OutboundMulticast());
+		OutboundMulticast &out = gs.txQueue.back();
+
+		out.init(
+			now,
+			RR->identity.address(),
+			nwid,
+			com,
+			limit,
+			gatherLimit,
+			src,
+			mg,
+			etherType,
+			data,
+			len);
+
+		for(std::vector<MulticastGroupMember>::const_reverse_iterator m(gs.members.rbegin());m!=gs.members.rend();++m)
+			out.sendAndLog(*(RR->sw),m->address);
 	}
 }
 

+ 1 - 3
node/Multicaster.hpp

@@ -92,7 +92,7 @@ public:
 	 * @param learnedFrom Address from which we learned this member or NULL/0 Address if direct
 	 * @param member New member address
 	 */
-	inline void subscribe(uint64_t now,uint64_t nwid,const MulticastGroup &mg,const Address &learnedFrom,const Address &member)
+	inline void add(uint64_t now,uint64_t nwid,const MulticastGroup &mg,const Address &learnedFrom,const Address &member)
 	{
 		Mutex::Lock _l(_groups_m);
 		_add(now,nwid,_groups[std::pair<uint64_t,MulticastGroup>(nwid,mg)],learnedFrom,member);
@@ -124,7 +124,6 @@ public:
 	 * @param nwid Network ID
 	 * @param com Certificate of membership to include or NULL for none
 	 * @param limit Multicast limit
-	 * @param gatherLimit Limit to pass for implicit gather with MULTICAST_FRAME
 	 * @param now Current time
 	 * @param mg Multicast group
 	 * @param from Source Ethernet MAC address
@@ -135,7 +134,6 @@ public:
 	void send(
 		const CertificateOfMembership *com,
 		unsigned int limit,
-		unsigned int gatherLimit,
 		uint64_t now,
 		uint64_t nwid,
 		const MulticastGroup &mg,

+ 0 - 1
node/Switch.cpp

@@ -153,7 +153,6 @@ void Switch::onLocalEthernet(const SharedPtr<Network> &network,const MAC &from,c
 		RR->mc->send(
 			((!nconf->isPublic())&&(nconf->com())) ? &(nconf->com()) : (const CertificateOfMembership *)0,
 			nconf->multicastLimit(),
-			network->wantMulticastGroup(mg) ? ZT_MULTICAST_DEFAULT_IMPLICIT_GATHER : 0,
 			now,
 			network->id(),
 			mg,