mirror of
https://github.com/ZeroTier/ZeroTierOne
synced 2025-07-05 20:41:44 -07:00
clang-format
This commit is contained in:
parent
d45f280cb7
commit
ba2a4a605c
140 changed files with 19214 additions and 17403 deletions
|
@ -14,22 +14,21 @@
|
|||
#ifndef ZT_MULTICASTER_HPP
|
||||
#define ZT_MULTICASTER_HPP
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
#include "Address.hpp"
|
||||
#include "Constants.hpp"
|
||||
#include "Hashtable.hpp"
|
||||
#include "Address.hpp"
|
||||
#include "MAC.hpp"
|
||||
#include "MulticastGroup.hpp"
|
||||
#include "OutboundMulticast.hpp"
|
||||
#include "Utils.hpp"
|
||||
#include "Mutex.hpp"
|
||||
#include "OutboundMulticast.hpp"
|
||||
#include "SharedPtr.hpp"
|
||||
#include "Utils.hpp"
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
|
||||
namespace ZeroTier {
|
||||
|
||||
|
@ -41,10 +40,9 @@ class Network;
|
|||
/**
|
||||
* Database of known multicast peers within a network
|
||||
*/
|
||||
class Multicaster
|
||||
{
|
||||
public:
|
||||
Multicaster(const RuntimeEnvironment *renv);
|
||||
class Multicaster {
|
||||
public:
|
||||
Multicaster(const RuntimeEnvironment* renv);
|
||||
~Multicaster();
|
||||
|
||||
/**
|
||||
|
@ -55,10 +53,10 @@ public:
|
|||
* @param mg Multicast group
|
||||
* @param member New member address
|
||||
*/
|
||||
inline void add(void *tPtr,int64_t now,uint64_t nwid,const MulticastGroup &mg,const Address &member)
|
||||
inline void add(void* tPtr, int64_t now, uint64_t nwid, const MulticastGroup& mg, const Address& member)
|
||||
{
|
||||
Mutex::Lock _l(_groups_m);
|
||||
_add(tPtr,now,nwid,mg,_groups[Multicaster::Key(nwid,mg)],member);
|
||||
_add(tPtr, now, nwid, mg, _groups[Multicaster::Key(nwid, mg)], member);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,7 +72,7 @@ public:
|
|||
* @param count Number of addresses
|
||||
* @param totalKnown Total number of known addresses as reported by peer
|
||||
*/
|
||||
void addMultiple(void *tPtr,int64_t now,uint64_t nwid,const MulticastGroup &mg,const void *addresses,unsigned int count,unsigned int totalKnown);
|
||||
void addMultiple(void* tPtr, int64_t now, uint64_t nwid, const MulticastGroup& mg, const void* addresses, unsigned int count, unsigned int totalKnown);
|
||||
|
||||
/**
|
||||
* Remove a multicast group member (if present)
|
||||
|
@ -83,7 +81,7 @@ public:
|
|||
* @param mg Multicast group
|
||||
* @param member Member to unsubscribe
|
||||
*/
|
||||
void remove(uint64_t nwid,const MulticastGroup &mg,const Address &member);
|
||||
void remove(uint64_t nwid, const MulticastGroup& mg, const Address& member);
|
||||
|
||||
/**
|
||||
* Append gather results to a packet by choosing registered multicast recipients at random
|
||||
|
@ -103,7 +101,7 @@ public:
|
|||
* @return Number of addresses appended
|
||||
* @throws std::out_of_range Buffer overflow writing to packet
|
||||
*/
|
||||
unsigned int gather(const Address &queryingPeer,uint64_t nwid,const MulticastGroup &mg,Buffer<ZT_PROTO_MAX_PACKET_LENGTH> &appendTo,unsigned int limit) const;
|
||||
unsigned int gather(const Address& queryingPeer, uint64_t nwid, const MulticastGroup& mg, Buffer<ZT_PROTO_MAX_PACKET_LENGTH>& appendTo, unsigned int limit) const;
|
||||
|
||||
/**
|
||||
* Get subscribers to a multicast group
|
||||
|
@ -111,7 +109,7 @@ public:
|
|||
* @param nwid Network ID
|
||||
* @param mg Multicast group
|
||||
*/
|
||||
std::vector<Address> getMembers(uint64_t nwid,const MulticastGroup &mg,unsigned int limit) const;
|
||||
std::vector<Address> getMembers(uint64_t nwid, const MulticastGroup& mg, unsigned int limit) const;
|
||||
|
||||
/**
|
||||
* Send a multicast
|
||||
|
@ -126,16 +124,7 @@ public:
|
|||
* @param data Packet data
|
||||
* @param len Length of packet data
|
||||
*/
|
||||
void send(
|
||||
void *tPtr,
|
||||
int64_t now,
|
||||
const SharedPtr<Network> &network,
|
||||
const Address &origin,
|
||||
const MulticastGroup &mg,
|
||||
const MAC &src,
|
||||
unsigned int etherType,
|
||||
const void *data,
|
||||
unsigned int len);
|
||||
void send(void* tPtr, int64_t now, const SharedPtr<Network>& network, const Address& origin, const MulticastGroup& mg, const MAC& src, unsigned int etherType, const void* data, unsigned int len);
|
||||
|
||||
/**
|
||||
* Clean database
|
||||
|
@ -145,53 +134,87 @@ public:
|
|||
*/
|
||||
void clean(int64_t now);
|
||||
|
||||
private:
|
||||
struct Key
|
||||
{
|
||||
Key() : nwid(0),mg() {}
|
||||
Key(uint64_t n,const MulticastGroup &g) : nwid(n),mg(g) {}
|
||||
private:
|
||||
struct Key {
|
||||
Key() : nwid(0), mg()
|
||||
{
|
||||
}
|
||||
Key(uint64_t n, const MulticastGroup& g) : nwid(n), mg(g)
|
||||
{
|
||||
}
|
||||
|
||||
uint64_t nwid;
|
||||
MulticastGroup mg;
|
||||
|
||||
inline bool operator==(const Key &k) const { return ((nwid == k.nwid)&&(mg == k.mg)); }
|
||||
inline bool operator!=(const Key &k) const { return ((nwid != k.nwid)||(mg != k.mg)); }
|
||||
inline unsigned long hashCode() const { return (mg.hashCode() ^ (unsigned long)(nwid ^ (nwid >> 32))); }
|
||||
inline bool operator==(const Key& k) const
|
||||
{
|
||||
return ((nwid == k.nwid) && (mg == k.mg));
|
||||
}
|
||||
inline bool operator!=(const Key& k) const
|
||||
{
|
||||
return ((nwid != k.nwid) || (mg != k.mg));
|
||||
}
|
||||
inline unsigned long hashCode() const
|
||||
{
|
||||
return (mg.hashCode() ^ (unsigned long)(nwid ^ (nwid >> 32)));
|
||||
}
|
||||
};
|
||||
|
||||
struct MulticastGroupMember
|
||||
{
|
||||
MulticastGroupMember() {}
|
||||
MulticastGroupMember(const Address &a,uint64_t ts) : address(a),timestamp(ts) {}
|
||||
struct MulticastGroupMember {
|
||||
MulticastGroupMember()
|
||||
{
|
||||
}
|
||||
MulticastGroupMember(const Address& a, uint64_t ts) : address(a), timestamp(ts)
|
||||
{
|
||||
}
|
||||
|
||||
inline bool operator<(const MulticastGroupMember &a) const { return (address < a.address); }
|
||||
inline bool operator==(const MulticastGroupMember &a) const { return (address == a.address); }
|
||||
inline bool operator!=(const MulticastGroupMember &a) const { return (address != a.address); }
|
||||
inline bool operator<(const Address &a) const { return (address < a); }
|
||||
inline bool operator==(const Address &a) const { return (address == a); }
|
||||
inline bool operator!=(const Address &a) const { return (address != a); }
|
||||
inline bool operator<(const MulticastGroupMember& a) const
|
||||
{
|
||||
return (address < a.address);
|
||||
}
|
||||
inline bool operator==(const MulticastGroupMember& a) const
|
||||
{
|
||||
return (address == a.address);
|
||||
}
|
||||
inline bool operator!=(const MulticastGroupMember& a) const
|
||||
{
|
||||
return (address != a.address);
|
||||
}
|
||||
inline bool operator<(const Address& a) const
|
||||
{
|
||||
return (address < a);
|
||||
}
|
||||
inline bool operator==(const Address& a) const
|
||||
{
|
||||
return (address == a);
|
||||
}
|
||||
inline bool operator!=(const Address& a) const
|
||||
{
|
||||
return (address != a);
|
||||
}
|
||||
|
||||
Address address;
|
||||
int64_t timestamp; // time of last notification
|
||||
int64_t timestamp; // time of last notification
|
||||
};
|
||||
|
||||
struct MulticastGroupStatus
|
||||
{
|
||||
MulticastGroupStatus() : lastExplicitGather(0) {}
|
||||
struct MulticastGroupStatus {
|
||||
MulticastGroupStatus() : lastExplicitGather(0)
|
||||
{
|
||||
}
|
||||
|
||||
int64_t lastExplicitGather;
|
||||
std::list<OutboundMulticast> txQueue; // pending outbound multicasts
|
||||
std::vector<MulticastGroupMember> members; // members of this group
|
||||
std::list<OutboundMulticast> txQueue; // pending outbound multicasts
|
||||
std::vector<MulticastGroupMember> members; // members of this group
|
||||
};
|
||||
|
||||
void _add(void *tPtr,int64_t now,uint64_t nwid,const MulticastGroup &mg,MulticastGroupStatus &gs,const Address &member);
|
||||
void _add(void* tPtr, int64_t now, uint64_t nwid, const MulticastGroup& mg, MulticastGroupStatus& gs, const Address& member);
|
||||
|
||||
const RuntimeEnvironment *const RR;
|
||||
const RuntimeEnvironment* const RR;
|
||||
|
||||
Hashtable<Multicaster::Key,MulticastGroupStatus> _groups;
|
||||
Hashtable<Multicaster::Key, MulticastGroupStatus> _groups;
|
||||
Mutex _groups_m;
|
||||
};
|
||||
|
||||
} // namespace ZeroTier
|
||||
} // namespace ZeroTier
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue