From 5bb854e504a0db968b47c0a983d0148629e126e7 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Tue, 28 Oct 2014 17:25:34 -0700 Subject: Fix a nasty bug introduced in packet fragmentation a while back during refactoring, and a few other things related to multicast. --- node/Multicaster.cpp | 15 +++++++++++---- node/OutboundMulticast.hpp | 2 +- node/Packet.hpp | 7 ++++--- node/Switch.cpp | 8 +++++--- 4 files changed, 21 insertions(+), 11 deletions(-) (limited to 'node') diff --git a/node/Multicaster.cpp b/node/Multicaster.cpp index 94c6a45b..4d1b82d4 100644 --- a/node/Multicaster.cpp +++ b/node/Multicaster.cpp @@ -325,7 +325,7 @@ void Multicaster::clean(uint64_t now) // so that remaining members can be sorted in ascending order of // transmit priority. std::vector::iterator reader(mm->second.members.begin()); - std::vector::iterator writer(mm->second.members.begin()); + std::vector::iterator writer(reader); unsigned int count = 0; while (reader != mm->second.members.end()) { if ((now - reader->timestamp) < ZT_MULTICAST_LIKE_EXPIRE) { @@ -363,7 +363,10 @@ void Multicaster::clean(uint64_t now) } else if (mm->second.txQueue.empty()) { // There are no remaining members and no pending multicasts, so erase the entry _groups.erase(mm++); - } else ++mm; + } else { + mm->second.members.clear(); + ++mm; + } } } @@ -399,10 +402,14 @@ void Multicaster::_add(uint64_t now,uint64_t nwid,const MulticastGroup &mg,Multi SharedPtr p(RR->topology->getPeer(member)); if ((!p)||(!p->remoteVersionKnown())||(p->remoteVersionMajor() >= 1)) { for(std::list::iterator tx(gs.txQueue.begin());tx!=gs.txQueue.end();) { - tx->sendIfNew(RR,member); if (tx->atLimit()) gs.txQueue.erase(tx++); - else ++tx; + else { + tx->sendIfNew(RR,member); + if (tx->atLimit()) + gs.txQueue.erase(tx++); + else ++tx; + } } } } diff --git a/node/OutboundMulticast.hpp b/node/OutboundMulticast.hpp index ab0aae55..f87656eb 100644 --- a/node/OutboundMulticast.hpp +++ b/node/OutboundMulticast.hpp @@ -102,7 +102,7 @@ public: /** * @return True if this outbound multicast has been sent to enough peers */ - inline bool atLimit() const throw() { return (_alreadySentTo.size() > _limit); } + inline bool atLimit() const throw() { return (_alreadySentTo.size() >= _limit); } /** * Just send without checking log diff --git a/node/Packet.hpp b/node/Packet.hpp index a6ac9dc6..2d2c11e2 100644 --- a/node/Packet.hpp +++ b/node/Packet.hpp @@ -35,11 +35,12 @@ #include #include +#include "Constants.hpp" + #include "Address.hpp" #include "Poly1305.hpp" #include "Salsa20.hpp" #include "Utils.hpp" -#include "Constants.hpp" #include "Buffer.hpp" #include "../ext/lz4/lz4.h" @@ -425,13 +426,13 @@ public: setSize(fragLen + ZT_PROTO_MIN_FRAGMENT_LENGTH); // NOTE: this copies both the IV/packet ID and the destination address. - memcpy(field(ZT_PACKET_FRAGMENT_IDX_PACKET_ID,13),field(ZT_PACKET_IDX_IV,13),13); + memcpy(field(ZT_PACKET_FRAGMENT_IDX_PACKET_ID,13),p.field(ZT_PACKET_IDX_IV,13),13); (*this)[ZT_PACKET_FRAGMENT_IDX_FRAGMENT_INDICATOR] = ZT_PACKET_FRAGMENT_INDICATOR; (*this)[ZT_PACKET_FRAGMENT_IDX_FRAGMENT_NO] = (char)(((fragTotal & 0xf) << 4) | (fragNo & 0xf)); (*this)[ZT_PACKET_FRAGMENT_IDX_HOPS] = 0; - memcpy(field(ZT_PACKET_FRAGMENT_IDX_PAYLOAD,fragLen),field(fragStart,fragLen),fragLen); + memcpy(field(ZT_PACKET_FRAGMENT_IDX_PAYLOAD,fragLen),p.field(fragStart,fragLen),fragLen); } /** diff --git a/node/Switch.cpp b/node/Switch.cpp index 4819bd56..7c63761b 100644 --- a/node/Switch.cpp +++ b/node/Switch.cpp @@ -785,9 +785,9 @@ bool Switch::_trySend(const Packet &packet,bool encrypt) ++fragsRemaining; unsigned int totalFragments = fragsRemaining + 1; - for(unsigned int f=0;fsend(RR,frag.data(),frag.size(),now); fragStart += chunkSize; remaining -= chunkSize; @@ -795,7 +795,9 @@ bool Switch::_trySend(const Packet &packet,bool encrypt) } return true; } - } else requestWhois(packet.destination()); + } else { + requestWhois(packet.destination()); + } return false; } -- cgit v1.2.3