summaryrefslogtreecommitdiff
path: root/node/Multicaster.cpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2014-10-05 10:34:25 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2014-10-05 10:34:25 -0700
commitab22feba9a6e6c7e2eb3bc8ba3ecc48f19f878a0 (patch)
treeff45aca809f4161dfd8c152f045536f0e6f220ef /node/Multicaster.cpp
parent10c196df50b10c4445ef0d7205da290fc78973d2 (diff)
downloadinfinitytier-ab22feba9a6e6c7e2eb3bc8ba3ecc48f19f878a0.tar.gz
infinitytier-ab22feba9a6e6c7e2eb3bc8ba3ecc48f19f878a0.zip
Bump version to 1.0.0, add legacy support code to Multicaster to not send new frame to known-to-be-old peers.
Diffstat (limited to 'node/Multicaster.cpp')
-rw-r--r--node/Multicaster.cpp67
1 files changed, 57 insertions, 10 deletions
diff --git a/node/Multicaster.cpp b/node/Multicaster.cpp
index afe1c83f..585ced06 100644
--- a/node/Multicaster.cpp
+++ b/node/Multicaster.cpp
@@ -50,7 +50,7 @@ Multicaster::~Multicaster()
{
}
-unsigned int Multicaster::gather(const RuntimeEnvironment *RR,const Address &queryingPeer,uint64_t nwid,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 int n = 0,i,rptr,skipped = 0;
@@ -111,6 +111,24 @@ restart_member_scan:
return n;
}
+std::vector<Address> Multicaster::getLegacySubscribers(uint64_t nwid,const MulticastGroup &mg) const
+{
+ std::vector<Address> ls;
+ 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)));
+ if (gs == _groups.end())
+ return ls;
+
+ for(std::vector<MulticastGroupMember>::const_iterator m(gs->second.members.begin());m!=gs->second.members.end();++m) {
+ SharedPtr<Peer> p(RR->topology->getPeer(m->address));
+ if ((p)&&(p->remoteVersionKnown())&&(p->remoteVersionMajor() < 1))
+ ls.push_back(m->address);
+ }
+
+ return ls;
+}
+
void Multicaster::send(
const CertificateOfMembership *com,
unsigned int limit,
@@ -148,12 +166,24 @@ void Multicaster::send(
unsigned int count = 0;
for(std::vector<Address>::const_iterator ast(alwaysSendTo.begin());ast!=alwaysSendTo.end();++ast) {
+ { // TODO / LEGACY: don't send new multicast frame to old peers (if we know their version)
+ SharedPtr<Peer> p(RR->topology->getPeer(*ast));
+ if ((p)&&(p->remoteVersionKnown())&&(p->remoteVersionMajor() < 1))
+ continue;
+ }
+
if (count++ >= limit)
break;
out.sendOnly(*(RR->sw),*ast);
}
for(std::vector<MulticastGroupMember>::const_reverse_iterator m(gs.members.rbegin());m!=gs.members.rend();++m) {
+ { // TODO / LEGACY: don't send new multicast frame to old peers (if we know their version)
+ SharedPtr<Peer> p(RR->topology->getPeer(m->address));
+ if ((p)&&(p->remoteVersionKnown())&&(p->remoteVersionMajor() < 1))
+ continue;
+ }
+
if (count++ >= limit)
break;
if (std::find(alwaysSendTo.begin(),alwaysSendTo.end(),m->address) == alwaysSendTo.end())
@@ -164,7 +194,6 @@ void Multicaster::send(
if ((now - gs.lastExplicitGather) >= ZT_MULTICAST_EXPLICIT_GATHER_DELAY) {
gs.lastExplicitGather = now;
-
SharedPtr<Peer> sn(RR->topology->getBestSupernode());
if (sn) {
Packet outp(sn->address(),RR->identity.address(),Packet::VERB_MULTICAST_GATHER);
@@ -176,13 +205,12 @@ void Multicaster::send(
outp.armor(sn->key(),true);
sn->send(RR,outp.data(),outp.size(),now);
}
-
- gatherLimit = 0; // once we've done this we don't need to do it implicitly
- }
-
- if ((gatherLimit > 0)&&((now - gs.lastImplicitGather) > ZT_MULTICAST_IMPLICIT_GATHER_DELAY))
+ gatherLimit = 0; // implicit not needed
+ } else if ((now - gs.lastImplicitGather) > ZT_MULTICAST_IMPLICIT_GATHER_DELAY) {
gs.lastImplicitGather = now;
- else gatherLimit = 0;
+ } else {
+ gatherLimit = 0;
+ }
gs.txQueue.push_back(OutboundMulticast());
OutboundMulticast &out = gs.txQueue.back();
@@ -200,10 +228,23 @@ void Multicaster::send(
data,
len);
- for(std::vector<Address>::const_iterator ast(alwaysSendTo.begin());ast!=alwaysSendTo.end();++ast)
+ for(std::vector<Address>::const_iterator ast(alwaysSendTo.begin());ast!=alwaysSendTo.end();++ast) {
+ { // TODO / LEGACY: don't send new multicast frame to old peers (if we know their version)
+ SharedPtr<Peer> p(RR->topology->getPeer(*ast));
+ if ((p)&&(p->remoteVersionKnown())&&(p->remoteVersionMajor() < 1))
+ continue;
+ }
+
out.sendAndLog(*(RR->sw),*ast);
+ }
for(std::vector<MulticastGroupMember>::const_reverse_iterator m(gs.members.rbegin());m!=gs.members.rend();++m) {
+ { // TODO / LEGACY: don't send new multicast frame to old peers (if we know their version)
+ SharedPtr<Peer> p(RR->topology->getPeer(m->address));
+ if ((p)&&(p->remoteVersionKnown())&&(p->remoteVersionMajor() < 1))
+ continue;
+ }
+
if (std::find(alwaysSendTo.begin(),alwaysSendTo.end(),m->address) == alwaysSendTo.end())
out.sendAndLog(*(RR->sw),m->address);
}
@@ -211,7 +252,7 @@ void Multicaster::send(
// DEPRECATED / LEGACY / TODO:
// Currently we also always send a legacy P5_MULTICAST_FRAME packet to our
- // supernode. Our supernode then takes care of relaying it down to all <1.0.0
+ // supernode. Our supernode then takes care of relaying it down to <1.0.0
// nodes. This code can go away (along with support for P5_MULTICAST_FRAME)
// once there are no more such nodes on the network.
{
@@ -337,6 +378,12 @@ void Multicaster::_add(uint64_t now,uint64_t nwid,MulticastGroupStatus &gs,const
// 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();) {
+ { // TODO / LEGACY: don't send new multicast frame to old peers (if we know their version)
+ SharedPtr<Peer> p(RR->topology->getPeer(member));
+ if ((p)&&(p->remoteVersionKnown())&&(p->remoteVersionMajor() < 1))
+ continue;
+ }
+
tx->sendIfNew(*(RR->sw),member);
if (tx->atLimit())
gs.txQueue.erase(tx++);