summaryrefslogtreecommitdiff
path: root/node/Multicaster.hpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2014-09-30 16:28:25 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2014-09-30 16:28:25 -0700
commit2659427864aee89977a58440705f7069c0e6c639 (patch)
tree21cd30ae78ed7b1df414f877d55a9243cfa342e8 /node/Multicaster.hpp
parent8607aa7c3c0a24c3161b605e5195bfd5a7ad1258 (diff)
downloadinfinitytier-2659427864aee89977a58440705f7069c0e6c639.tar.gz
infinitytier-2659427864aee89977a58440705f7069c0e6c639.zip
Multicaster needs to be global, not per-network, and a bunch of other stuff.
Diffstat (limited to 'node/Multicaster.hpp')
-rw-r--r--node/Multicaster.hpp38
1 files changed, 29 insertions, 9 deletions
diff --git a/node/Multicaster.hpp b/node/Multicaster.hpp
index 9abf9c30..5c858093 100644
--- a/node/Multicaster.hpp
+++ b/node/Multicaster.hpp
@@ -47,6 +47,7 @@ namespace ZeroTier {
class RuntimeEnvironment;
class CertificateOfMembership;
+class Packet;
/**
* Database of known multicast peers within a network
@@ -82,21 +83,41 @@ public:
~Multicaster();
/**
- * Add or update a member in a multicast group and send any pending multicasts
+ * Add or update a member in a multicast group
*
- * @param RR Runtime environment
* @param now Current time
+ * @param nwid Network ID
* @param mg Multicast group
* @param learnedFrom Address from which we learned this member or NULL/0 Address if direct
* @param member New member address
*/
- inline void add(const RuntimeEnvironment *RR,uint64_t now,const MulticastGroup &mg,const Address &learnedFrom,const Address &member)
+ inline void subscribe(uint64_t now,uint64_t nwid,const MulticastGroup &mg,const Address &learnedFrom,const Address &member)
{
Mutex::Lock _l(_groups_m);
- _add(RR,now,_groups[mg],learnedFrom,member);
+ _add(now,_groups[std::pair<uint64_t,MulticastGroup>(nwid,mg)],learnedFrom,member);
}
/**
+ * Append gather results to a packet by choosing registered multicast recipients at random
+ *
+ * This appends the following fields to the packet:
+ * <[4] 32-bit total number of known members in this multicast group>
+ * <[2] 16-bit number of members enumerated in this packet>
+ * <[...] series of 5-byte ZeroTier addresses of enumerated members>
+ *
+ * If zero is returned, the first two fields will still have been appended.
+ *
+ * @param RR Runtime environment
+ * @param nwid Network ID
+ * @param mg Multicast group
+ * @param appendTo Packet to append to
+ * @param limit Maximum number of 5-byte addresses to append
+ * @return Number of addresses appended
+ * @throws std::out_of_range Buffer overflow writing to packet
+ */
+ unsigned int gather(const RuntimeEnvironment *RR,uint64_t nwid,MulticastGroup &mg,Packet &appendTo,unsigned int limit) const;
+
+ /**
* Send a multicast
*
* @param RR Runtime environment
@@ -112,10 +133,10 @@ public:
*/
void send(
const RuntimeEnvironment *RR,
- uint64_t nwid,
const CertificateOfMembership *com,
unsigned int limit,
uint64_t now,
+ uint64_t nwid,
const MulticastGroup &mg,
const MAC &src,
unsigned int etherType,
@@ -127,14 +148,13 @@ public:
*
* @param RR Runtime environment
* @param now Current time
- * @param limit Multicast limit
*/
- void clean(const RuntimeEnvironment *RR,uint64_t now,unsigned int limit);
+ void clean(const RuntimeEnvironment *RR,uint64_t now);
private:
- void _add(const RuntimeEnvironment *RR,uint64_t now,MulticastGroupStatus &gs,const Address &learnedFrom,const Address &member);
+ void _add(uint64_t now,MulticastGroupStatus &gs,const Address &learnedFrom,const Address &member);
- std::map< MulticastGroup,MulticastGroupStatus > _groups;
+ std::map< std::pair<uint64_t,MulticastGroup>,MulticastGroupStatus > _groups;
Mutex _groups_m;
};