mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-01 23:10:52 +00:00
Return self in GATHER requests if self is a member of multicast group, and reinstate legacy support.
This commit is contained in:
parent
4941c8a1f3
commit
56f8f8aa24
@ -79,7 +79,7 @@ bool IncomingPacket::tryDecode(const RuntimeEnvironment *RR)
|
|||||||
case Packet::VERB_RENDEZVOUS: return _doRENDEZVOUS(RR,peer);
|
case Packet::VERB_RENDEZVOUS: return _doRENDEZVOUS(RR,peer);
|
||||||
case Packet::VERB_FRAME: return _doFRAME(RR,peer);
|
case Packet::VERB_FRAME: return _doFRAME(RR,peer);
|
||||||
case Packet::VERB_EXT_FRAME: return _doEXT_FRAME(RR,peer);
|
case Packet::VERB_EXT_FRAME: return _doEXT_FRAME(RR,peer);
|
||||||
//case Packet::VERB_P5_MULTICAST_FRAME: return _doP5_MULTICAST_FRAME(RR,peer);
|
case Packet::VERB_P5_MULTICAST_FRAME: return _doP5_MULTICAST_FRAME(RR,peer);
|
||||||
case Packet::VERB_MULTICAST_LIKE: return _doMULTICAST_LIKE(RR,peer);
|
case Packet::VERB_MULTICAST_LIKE: return _doMULTICAST_LIKE(RR,peer);
|
||||||
case Packet::VERB_NETWORK_MEMBERSHIP_CERTIFICATE: return _doNETWORK_MEMBERSHIP_CERTIFICATE(RR,peer);
|
case Packet::VERB_NETWORK_MEMBERSHIP_CERTIFICATE: return _doNETWORK_MEMBERSHIP_CERTIFICATE(RR,peer);
|
||||||
case Packet::VERB_NETWORK_CONFIG_REQUEST: return _doNETWORK_CONFIG_REQUEST(RR,peer);
|
case Packet::VERB_NETWORK_CONFIG_REQUEST: return _doNETWORK_CONFIG_REQUEST(RR,peer);
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
#include "Peer.hpp"
|
#include "Peer.hpp"
|
||||||
#include "CMWC4096.hpp"
|
#include "CMWC4096.hpp"
|
||||||
#include "C25519.hpp"
|
#include "C25519.hpp"
|
||||||
|
#include "NodeConfig.hpp"
|
||||||
#include "CertificateOfMembership.hpp"
|
#include "CertificateOfMembership.hpp"
|
||||||
#include "Logger.hpp"
|
#include "Logger.hpp"
|
||||||
|
|
||||||
@ -54,66 +55,67 @@ Multicaster::~Multicaster()
|
|||||||
unsigned int Multicaster::gather(const Address &queryingPeer,uint64_t nwid,const MulticastGroup &mg,Packet &appendTo,unsigned int limit) const
|
unsigned int Multicaster::gather(const Address &queryingPeer,uint64_t nwid,const MulticastGroup &mg,Packet &appendTo,unsigned int limit) const
|
||||||
{
|
{
|
||||||
unsigned char *p;
|
unsigned char *p;
|
||||||
unsigned int n = 0,i,rptr,skipped = 0;
|
unsigned int added = 0,i,k,rptr,totalKnown = 0;
|
||||||
uint64_t a,done[(ZT_PROTO_MAX_PACKET_LENGTH / 5) + 1];
|
uint64_t a,picked[(ZT_PROTO_MAX_PACKET_LENGTH / 5) + 1];
|
||||||
|
|
||||||
|
if (!limit)
|
||||||
|
return 0;
|
||||||
|
if (limit > 0xffff) // TODO: multiple return packets not yet supported
|
||||||
|
limit = 0xffff;
|
||||||
|
|
||||||
|
{ // Return myself if I am a member of this group
|
||||||
|
SharedPtr<Network> network(RR->nc->network(nwid));
|
||||||
|
if ((network)&&(network->subscribedToMulticastGroup(mg))) {
|
||||||
|
RR->identity.address().appendTo(appendTo);
|
||||||
|
++totalKnown;
|
||||||
|
++added;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Mutex::Lock _l(_groups_m);
|
Mutex::Lock _l(_groups_m);
|
||||||
|
|
||||||
std::map< std::pair<uint64_t,MulticastGroup>,MulticastGroupStatus >::const_iterator gs(_groups.find(std::pair<uint64_t,MulticastGroup>(nwid,mg)));
|
const unsigned int totalAt = appendTo.size();
|
||||||
if ((gs == _groups.end())||(gs->second.members.empty())) {
|
|
||||||
appendTo.append((uint32_t)0);
|
|
||||||
appendTo.append((uint16_t)0);
|
|
||||||
//TRACE("..MC Multicaster::gather() attached 0 of 0 peers for %.16llx/%s (1)",nwid,mg.toString().c_str());
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (limit > gs->second.members.size())
|
|
||||||
limit = (unsigned int)gs->second.members.size();
|
|
||||||
if (limit > ((ZT_PROTO_MAX_PACKET_LENGTH / ZT_ADDRESS_LENGTH) + 1))
|
|
||||||
limit = (ZT_PROTO_MAX_PACKET_LENGTH / ZT_ADDRESS_LENGTH) + 1;
|
|
||||||
|
|
||||||
unsigned int totalAt = appendTo.size();
|
|
||||||
appendTo.addSize(4); // sizeof(uint32_t)
|
appendTo.addSize(4); // sizeof(uint32_t)
|
||||||
unsigned int nAt = appendTo.size();
|
const unsigned int addedAt = appendTo.size();
|
||||||
appendTo.addSize(2); // sizeof(uint16_t)
|
appendTo.addSize(2); // sizeof(uint16_t)
|
||||||
|
|
||||||
// Members are returned in random order so that repeated gather queries
|
std::map< std::pair<uint64_t,MulticastGroup>,MulticastGroupStatus >::const_iterator gs(_groups.find(std::pair<uint64_t,MulticastGroup>(nwid,mg)));
|
||||||
// will return different subsets of a large multicast group.
|
if ((gs != _groups.end())&&(!gs->second.members.empty())) {
|
||||||
while ((n < limit)&&((appendTo.size() + ZT_ADDRESS_LENGTH) <= ZT_PROTO_MAX_PACKET_LENGTH)) {
|
totalKnown += gs->second.members.size();
|
||||||
rptr = (unsigned int)RR->prng->next32();
|
|
||||||
|
// Members are returned in random order so that repeated gather queries
|
||||||
|
// will return different subsets of a large multicast group.
|
||||||
|
k = 0;
|
||||||
|
while ((added < limit)&&(k < gs->second.members.size())&&((appendTo.size() + ZT_ADDRESS_LENGTH) <= ZT_PROTO_MAX_PACKET_LENGTH)) {
|
||||||
|
rptr = (unsigned int)RR->prng->next32();
|
||||||
restart_member_scan:
|
restart_member_scan:
|
||||||
a = gs->second.members[rptr % (unsigned int)gs->second.members.size()].address.toInt();
|
a = gs->second.members[rptr % (unsigned int)gs->second.members.size()].address.toInt();
|
||||||
for(i=0;i<n;++i) {
|
for(i=0;i<k;++i) {
|
||||||
if (done[i] == a) {
|
if (picked[i] == a) {
|
||||||
++rptr;
|
++rptr;
|
||||||
goto restart_member_scan;
|
goto restart_member_scan;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
picked[k++] = a;
|
||||||
|
|
||||||
// Log that we've picked this one
|
if (queryingPeer.toInt() != a) { // do not return the peer that is making the request as a result
|
||||||
done[n++] = a;
|
p = (unsigned char *)appendTo.appendField(ZT_ADDRESS_LENGTH);
|
||||||
|
*(p++) = (unsigned char)((a >> 32) & 0xff);
|
||||||
if (queryingPeer.toInt() == a) {
|
*(p++) = (unsigned char)((a >> 24) & 0xff);
|
||||||
++skipped;
|
*(p++) = (unsigned char)((a >> 16) & 0xff);
|
||||||
} else {
|
*(p++) = (unsigned char)((a >> 8) & 0xff);
|
||||||
// Append to packet
|
*p = (unsigned char)(a & 0xff);
|
||||||
p = (unsigned char *)appendTo.appendField(ZT_ADDRESS_LENGTH);
|
++added;
|
||||||
*(p++) = (unsigned char)((a >> 32) & 0xff);
|
}
|
||||||
*(p++) = (unsigned char)((a >> 24) & 0xff);
|
|
||||||
*(p++) = (unsigned char)((a >> 16) & 0xff);
|
|
||||||
*(p++) = (unsigned char)((a >> 8) & 0xff);
|
|
||||||
*p = (unsigned char)(a & 0xff);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
n -= skipped;
|
appendTo.setAt(totalAt,(uint32_t)totalKnown);
|
||||||
|
appendTo.setAt(addedAt,(uint16_t)added);
|
||||||
appendTo.setAt(totalAt,(uint32_t)(gs->second.members.size() - skipped));
|
|
||||||
appendTo.setAt(nAt,(uint16_t)n);
|
|
||||||
|
|
||||||
//TRACE("..MC Multicaster::gather() attached %u of %u peers for %.16llx/%s (2)",n,(unsigned int)(gs->second.members.size() - skipped),nwid,mg.toString().c_str());
|
//TRACE("..MC Multicaster::gather() attached %u of %u peers for %.16llx/%s (2)",n,(unsigned int)(gs->second.members.size() - skipped),nwid,mg.toString().c_str());
|
||||||
|
|
||||||
return n;
|
return added;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Address> Multicaster::getLegacySubscribers(uint64_t nwid,const MulticastGroup &mg) const
|
std::vector<Address> Multicaster::getLegacySubscribers(uint64_t nwid,const MulticastGroup &mg) const
|
||||||
@ -383,7 +385,7 @@ void Multicaster::_add(uint64_t now,uint64_t nwid,const MulticastGroup &mg,Multi
|
|||||||
// this somewhere else but we'll try this for now.
|
// this somewhere else but we'll try this for now.
|
||||||
gs.members.push_back(MulticastGroupMember(member,learnedFrom,now));
|
gs.members.push_back(MulticastGroupMember(member,learnedFrom,now));
|
||||||
|
|
||||||
TRACE("..MC %s joined multicast group %.16llx/%s via %s",member.toString().c_str(),nwid,mg.toString().c_str(),((learnedFrom) ? learnedFrom.toString().c_str() : "(direct)"));
|
//TRACE("..MC %s joined multicast group %.16llx/%s via %s",member.toString().c_str(),nwid,mg.toString().c_str(),((learnedFrom) ? learnedFrom.toString().c_str() : "(direct)"));
|
||||||
|
|
||||||
// Try to send to any outgoing multicasts that are waiting for more recipients
|
// Try to send to any outgoing multicasts that are waiting for more recipients
|
||||||
for(std::list<OutboundMulticast>::iterator tx(gs.txQueue.begin());tx!=gs.txQueue.end();) {
|
for(std::list<OutboundMulticast>::iterator tx(gs.txQueue.begin());tx!=gs.txQueue.end();) {
|
||||||
|
@ -163,6 +163,16 @@ public:
|
|||||||
return _myMulticastGroups;
|
return _myMulticastGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mg Multicast group
|
||||||
|
* @return True if this network endpoint / peer is a member
|
||||||
|
*/
|
||||||
|
bool subscribedToMulticastGroup(const MulticastGroup &mg) const
|
||||||
|
{
|
||||||
|
Mutex::Lock _l(_lock);
|
||||||
|
return (_myMulticastGroups.find(mg) != _myMulticastGroups.end());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply a NetworkConfig to this network
|
* Apply a NetworkConfig to this network
|
||||||
*
|
*
|
||||||
|
@ -58,6 +58,7 @@ void OutboundMulticast::init(
|
|||||||
if (gatherLimit) flags |= 0x02;
|
if (gatherLimit) flags |= 0x02;
|
||||||
if (src) flags |= 0x04;
|
if (src) flags |= 0x04;
|
||||||
|
|
||||||
|
/*
|
||||||
TRACE(">>MC %.16llx INIT %.16llx/%s limit %u gatherLimit %u from %s to %s length %u com==%d",
|
TRACE(">>MC %.16llx INIT %.16llx/%s limit %u gatherLimit %u from %s to %s length %u com==%d",
|
||||||
(unsigned long long)this,
|
(unsigned long long)this,
|
||||||
nwid,
|
nwid,
|
||||||
@ -68,6 +69,7 @@ void OutboundMulticast::init(
|
|||||||
dest.toString().c_str(),
|
dest.toString().c_str(),
|
||||||
len,
|
len,
|
||||||
(com) ? 1 : 0);
|
(com) ? 1 : 0);
|
||||||
|
*/
|
||||||
|
|
||||||
_packetNoCom.setSource(RR->identity.address());
|
_packetNoCom.setSource(RR->identity.address());
|
||||||
_packetNoCom.setVerb(Packet::VERB_MULTICAST_FRAME);
|
_packetNoCom.setVerb(Packet::VERB_MULTICAST_FRAME);
|
||||||
@ -107,12 +109,12 @@ void OutboundMulticast::sendOnly(const RuntimeEnvironment *RR,const Address &toA
|
|||||||
if (network->peerNeedsOurMembershipCertificate(toAddr,Utils::now())) {
|
if (network->peerNeedsOurMembershipCertificate(toAddr,Utils::now())) {
|
||||||
_packetWithCom.newInitializationVector();
|
_packetWithCom.newInitializationVector();
|
||||||
_packetWithCom.setDestination(toAddr);
|
_packetWithCom.setDestination(toAddr);
|
||||||
TRACE(">>MC %.16llx -> %s (with COM)",(unsigned long long)this,toAddr.toString().c_str());
|
//TRACE(">>MC %.16llx -> %s (with COM)",(unsigned long long)this,toAddr.toString().c_str());
|
||||||
RR->sw->send(_packetWithCom,true);
|
RR->sw->send(_packetWithCom,true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TRACE(">>MC %.16llx -> %s (without COM)",(unsigned long long)this,toAddr.toString().c_str());
|
//TRACE(">>MC %.16llx -> %s (without COM)",(unsigned long long)this,toAddr.toString().c_str());
|
||||||
_packetNoCom.newInitializationVector();
|
_packetNoCom.newInitializationVector();
|
||||||
_packetNoCom.setDestination(toAddr);
|
_packetNoCom.setDestination(toAddr);
|
||||||
RR->sw->send(_packetNoCom,true);
|
RR->sw->send(_packetNoCom,true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user