Browse Source

Fix some more multicast stuff (minor)

Adam Ierymenko 6 years ago
parent
commit
f6d747a5a0
2 changed files with 11 additions and 42 deletions
  1. 1 37
      node/MulticastGroup.hpp
  2. 10 5
      root/root.cpp

+ 1 - 37
node/MulticastGroup.hpp

@@ -77,7 +77,7 @@ public:
 	ZT_ALWAYS_INLINE const MAC &mac() const { return _mac; }
 	ZT_ALWAYS_INLINE uint32_t adi() const { return _adi; }
 
-	ZT_ALWAYS_INLINE unsigned long hashCode() const { return (_mac.hashCode() + (unsigned long)_adi); }
+	ZT_ALWAYS_INLINE unsigned long hashCode() const { return (_mac.hashCode() ^ (unsigned long)_adi); }
 
 	ZT_ALWAYS_INLINE bool operator==(const MulticastGroup &g) const { return ((_mac == g._mac)&&(_adi == g._adi)); }
 	ZT_ALWAYS_INLINE bool operator!=(const MulticastGroup &g) const { return ((_mac != g._mac)||(_adi != g._adi)); }
@@ -93,42 +93,6 @@ public:
 	ZT_ALWAYS_INLINE bool operator<=(const MulticastGroup &g) const { return !(g < *this); }
 	ZT_ALWAYS_INLINE bool operator>=(const MulticastGroup &g) const { return !(*this < g); }
 
-	/**
-	 * Compute a 32-bit fnv1a hash of a multicast group and a network ID
-	 *
-	 * @param mg Multicast group
-	 * @param nwid Network ID
-	 * @return 32-bit relatively-unique ID
-	 */
-	static ZT_ALWAYS_INLINE uint32_t id(const MulticastGroup &mg,const uint64_t nwid)
-	{
-		const uint32_t fnv1aPrime = 0x01000193;
-		uint32_t i = 0x811c9dc5;
-		i = (((uint32_t)(nwid >> 56) & 0xff) ^ i) * fnv1aPrime;
-		i = (((uint32_t)(nwid >> 48) & 0xff) ^ i) * fnv1aPrime;
-		i = (((uint32_t)(nwid >> 40) & 0xff) ^ i) * fnv1aPrime;
-		i = (((uint32_t)(nwid >> 32) & 0xff) ^ i) * fnv1aPrime;
-		i = (((uint32_t)(nwid >> 24) & 0xff) ^ i) * fnv1aPrime;
-		i = (((uint32_t)(nwid >> 16) & 0xff) ^ i) * fnv1aPrime;
-		i = (((uint32_t)(nwid >> 8) & 0xff) ^ i) * fnv1aPrime;
-		i = (((uint32_t)nwid & 0xff) ^ i) * fnv1aPrime;
-		const uint64_t mac = mg._mac.toInt();
-		i = (((uint32_t)(mac >> 56) & 0xff) ^ i) * fnv1aPrime;
-		i = (((uint32_t)(mac >> 48) & 0xff) ^ i) * fnv1aPrime;
-		i = (((uint32_t)(mac >> 40) & 0xff) ^ i) * fnv1aPrime;
-		i = (((uint32_t)(mac >> 32) & 0xff) ^ i) * fnv1aPrime;
-		i = (((uint32_t)(mac >> 24) & 0xff) ^ i) * fnv1aPrime;
-		i = (((uint32_t)(mac >> 16) & 0xff) ^ i) * fnv1aPrime;
-		i = (((uint32_t)(mac >> 8) & 0xff) ^ i) * fnv1aPrime;
-		i = (((uint32_t)mac & 0xff) ^ i) * fnv1aPrime;
-		const uint32_t adi = mg._adi;
-		i = (((adi >> 24) & 0xff) ^ i) * fnv1aPrime;
-		i = (((adi >> 16) & 0xff) ^ i) * fnv1aPrime;
-		i = (((adi >> 8) & 0xff) ^ i) * fnv1aPrime;
-		i = ((adi & 0xff) ^ i) * fnv1aPrime;
-		return i;
-	}
-
 private:
 	MAC _mac;
 	uint32_t _adi;

+ 10 - 5
root/root.cpp

@@ -277,14 +277,19 @@ static void handlePacket(const int v4s,const int v6s,const InetAddress *const ip
 								auto forGroup = forNet->second.find(mg);
 								if (forGroup != forNet->second.end()) {
 									pkt.append((uint32_t)forGroup->second.size());
-									pkt.append((uint16_t)std::min(std::min((unsigned int)forGroup->second.size(),(unsigned int)65535),gatherLimit));
-									auto g = forGroup->second.begin();
+									const unsigned int countAt = pkt.size();
+									pkt.addSize(2);
+
 									unsigned int l = 0;
-									for(;((l<gatherLimit)&&(g!=forGroup->second.end()));++l,++g)
-										g->first.appendTo(pkt);
+									for(auto g=forGroup->second.begin();((l<gatherLimit)&&(g!=forGroup->second.end()));++l,++g) {
+										if (g->first != source)
+											g->first.appendTo(pkt);
+									}
+
 									if (l > 0) {
+										pkt.setAt<uint16_t>(countAt,(uint16_t)l);
 										pkt.armor(peer->key,true);
-										sendto(ip->isV4() ? v4s : v6s,pkt.data(),pkt.size(),0,(const struct sockaddr *)ip,(socklen_t)((ip->ss_family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6)));
+										sendto(ip->isV4() ? v4s : v6s,pkt.data(),pkt.size(),0,(const struct sockaddr *)ip,(socklen_t)(ip->isV4() ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6)));
 										//printf("%s %s gathered %u subscribers to %s/%.8lx on network %.16llx" ZT_EOL_S,ip->toString(ipstr),source.toString(astr),l,mg.mac().toString(tmpstr),(unsigned long)mg.adi(),(unsigned long long)nwid);
 									}
 								}