diff --git a/node/Constants.hpp b/node/Constants.hpp
index 9aa16ddf3..b085d446b 100644
--- a/node/Constants.hpp
+++ b/node/Constants.hpp
@@ -228,37 +228,20 @@
#define ZT_RELAY_MAX_HOPS 3
/**
- * Size of multicast deduplication ring buffer in 64-bit ints
+ * Expire time for multicast 'likes' and indirect multicast memberships in ms
*/
-#define ZT_MULTICAST_DEDUP_HISTORY_LENGTH 512
-
-/**
- * Default number of bits in multicast propagation prefix
- */
-#define ZT_DEFAULT_MULTICAST_PREFIX_BITS 2
-
-/**
- * Default max depth (TTL) for multicast propagation
- */
-#define ZT_DEFAULT_MULTICAST_DEPTH 32
-
-/**
- * Global maximum for multicast propagation depth
- *
- * This is kind of an insane value, meant as a sanity check.
- */
-#define ZT_MULTICAST_GLOBAL_MAX_DEPTH 500
-
-/**
- * Expire time for multicast 'likes' in ms
- */
-#define ZT_MULTICAST_LIKE_EXPIRE 120000
+#define ZT_MULTICAST_LIKE_EXPIRE 600000
/**
* Time between polls of local tap devices for multicast membership changes
*/
#define ZT_MULTICAST_LOCAL_POLL_PERIOD 10000
+/**
+ * Minimum delay between attempts to gather multicast topology info if members > 0
+ */
+#define ZT_MULTICAST_TOPOLOGY_RESEARCH_RATE_THROTTLE 120000
+
/**
* Delay between scans of the topology active peer DB for peers that need ping
*/
diff --git a/node/MulticastTopology.cpp b/node/MulticastTopology.cpp
new file mode 100644
index 000000000..a594d33e2
--- /dev/null
+++ b/node/MulticastTopology.cpp
@@ -0,0 +1,88 @@
+/*
+ * ZeroTier One - Global Peer to Peer Ethernet
+ * Copyright (C) 2011-2014 ZeroTier Networks LLC
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ * --
+ *
+ * ZeroTier may be used and distributed under the terms of the GPLv3, which
+ * are available at: http://www.gnu.org/licenses/gpl-3.0.html
+ *
+ * If you would like to embed ZeroTier into a commercial application or
+ * redistribute it in a modified binary form, please contact ZeroTier Networks
+ * LLC. Start here: http://www.zerotier.com/
+ */
+
+#include
+
+#include "Constants.hpp"
+#include "MulticastTopology.hpp"
+#include "Topology.hpp"
+
+namespace ZeroTier {
+
+MulticastTopology::MulticastTopology()
+{
+}
+
+MulticastTopology::~MulticastTopology()
+{
+}
+
+void MulticastTopology::clean(const Topology &topology)
+{
+ uint64_t now = Utils::now();
+
+ for(std::map< MulticastGroup,std::vector >::iterator mm(_members.begin());mm!=_members.end();) {
+ std::vector::iterator reader(mm->second.begin());
+ std::vector::iterator writer(mm->second.begin());
+ unsigned long count = 0;
+ while (reader != mm->second.end()) {
+ if ((now - reader->timestamp) < ZT_MULTICAST_LIKE_EXPIRE) {
+ *writer = *reader;
+
+ /* We sort in ascending order of most recent relevant activity. For peers we've learned
+ * about by direct LIKEs, we do this in order of their own activity. For indirectly
+ * acquired peers we do this minus a constant to place these categorically below directly
+ * learned peers. For peers with no active Peer record, we use the time we last learned
+ * about them minus one day (a large constant) to put these at the bottom of the list.
+ * List is sorted in ascending order of rank and multicasts are sent last-to-first. */
+ if (writer->learnedFrom) {
+ SharedPtr p(topology.getPeer(writer->learnedFrom));
+ if (p)
+ writer->rank = p->lastUnicastFrame() - ZT_MULTICAST_LIKE_EXPIRE;
+ else writer->rank = writer->timestamp - 86400000;
+ } else {
+ SharedPtr p(topology.getPeer(writer->address));
+ if (p)
+ writer->rank = p->lastUnicastFrame();
+ else writer->rank = writer->timestamp - 86400000;
+ }
+
+ ++writer;
+ ++count;
+ }
+ ++reader;
+ }
+
+ if (count) {
+ mm->second.resize(count);
+ std::sort(mm->second.begin(),mm->second.end()); // sorts in ascending order of rank
+ ++mm;
+ } else _members.erase(mm++);
+ }
+}
+
+} // namespace ZeroTier
diff --git a/node/MulticastTopology.hpp b/node/MulticastTopology.hpp
new file mode 100644
index 000000000..fc49dbd33
--- /dev/null
+++ b/node/MulticastTopology.hpp
@@ -0,0 +1,162 @@
+/*
+ * ZeroTier One - Global Peer to Peer Ethernet
+ * Copyright (C) 2011-2014 ZeroTier Networks LLC
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ * --
+ *
+ * ZeroTier may be used and distributed under the terms of the GPLv3, which
+ * are available at: http://www.gnu.org/licenses/gpl-3.0.html
+ *
+ * If you would like to embed ZeroTier into a commercial application or
+ * redistribute it in a modified binary form, please contact ZeroTier Networks
+ * LLC. Start here: http://www.zerotier.com/
+ */
+
+#ifndef ZT_MULTICASTTOPOLOGY_HPP
+#define ZT_MULTICASTTOPOLOGY_HPP
+
+#include
+#include
+
+#include