From 8607aa7c3c0a24c3161b605e5195bfd5a7ad1258 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Tue, 30 Sep 2014 08:38:03 -0700 Subject: Everything in for new multicast except IncomingPacket parsing... --- node/Peer.cpp | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'node/Peer.cpp') diff --git a/node/Peer.cpp b/node/Peer.cpp index a58bfe3b..5f27da3f 100644 --- a/node/Peer.cpp +++ b/node/Peer.cpp @@ -28,6 +28,9 @@ #include "Constants.hpp" #include "Peer.hpp" #include "Switch.hpp" +#include "Packet.hpp" +#include "Network.hpp" +#include "NodeConfig.hpp" #include "AntiRecursion.hpp" #include @@ -76,14 +79,14 @@ void Peer::receive( // Update system-wide last packet receive time *((const_cast(&(RR->timeOfLastPacketReceived)))) = now; + Mutex::Lock _l(_lock); + // Global last receive time regardless of path _lastReceive = now; - // Learn paths from direct packets (hops == 0) if (!hops) { + // Learn paths from direct packets (hops == 0) { - Mutex::Lock _l(_lock); - bool havePath = false; for(std::vector::iterator p(_paths.begin());p!=_paths.end();++p) { if ((p->address() == remoteAddr)&&(p->tcp() == fromSock->tcp())) { @@ -110,11 +113,36 @@ void Peer::receive( } } - // Announce multicast LIKEs to peers to whom we have a direct link - // Lock can't be locked here or it'll recurse and deadlock. + // Announce multicast groups of interest to direct peers if they are + // considered authorized members of a given network. Also announce to + // supernodes and network controllers. TODO: the former may go + // obsolete with time as network controllers take over this role. if ((now - _lastAnnouncedTo) >= ((ZT_MULTICAST_LIKE_EXPIRE / 2) - 1000)) { _lastAnnouncedTo = now; - RR->sw->announceMulticastGroups(SharedPtr(this)); + + Packet outp(_id.address(),RR->identity.address(),Packet::VERB_MULTICAST_LIKE); + std::vector< SharedPtr > networks(RR->nc->networks()); + for(std::vector< SharedPtr >::iterator n(networks.begin());n!=networks.end();++n) { + if ( ((*n)->isAllowed(_id.address())) || ((*n)->controller() == _id.address()) || (RR->topology->isSupernode(_id.address())) ) { + std::set mgs((*n)->multicastGroups()); + for(std::set::iterator mg(mgs.begin());mg!=mgs.end();++mg) { + if ((outp.size() + 18) > ZT_UDP_DEFAULT_PAYLOAD_MTU) { + outp.armor(_key,true); + fromSock->send(remoteAddr,outp.data(),outp.size()); + outp.reset(_id.address(),RR->identity.address(),Packet::VERB_MULTICAST_LIKE); + } + + // network ID, MAC, ADI + outp.append((uint64_t)(*n)->id()); + mg->mac().appendTo(outp); + outp.append((uint32_t)mg->adi()); + } + } + } + if (outp.size() > ZT_PROTO_MIN_PACKET_LENGTH) { + outp.armor(_key,true); + fromSock->send(remoteAddr,outp.data(),outp.size()); + } } } -- cgit v1.2.3