Explorar el Código

Fix a nasty bug introduced in packet fragmentation a while back during refactoring, and a few other things related to multicast.

Adam Ierymenko hace 10 años
padre
commit
5bb854e504
Se han modificado 6 ficheros con 27 adiciones y 17 borrados
  1. 11 4
      node/Multicaster.cpp
  2. 1 1
      node/OutboundMulticast.hpp
  3. 4 3
      node/Packet.hpp
  4. 5 3
      node/Switch.cpp
  5. 5 5
      testnet.cpp
  6. 1 1
      testnet/TestEthernetTap.cpp

+ 11 - 4
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<MulticastGroupMember>::iterator reader(mm->second.members.begin());
-		std::vector<MulticastGroupMember>::iterator writer(mm->second.members.begin());
+		std::vector<MulticastGroupMember>::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<Peer> p(RR->topology->getPeer(member));
 	if ((!p)||(!p->remoteVersionKnown())||(p->remoteVersionMajor() >= 1)) {
 		for(std::list<OutboundMulticast>::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;
+			}
 		}
 	}
 }

+ 1 - 1
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

+ 4 - 3
node/Packet.hpp

@@ -35,11 +35,12 @@
 #include <string>
 #include <iostream>
 
+#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);
 		}
 
 		/**

+ 5 - 3
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;f<fragsRemaining;++f) {
+				for(unsigned int fno=1;fno<totalFragments;++fno) {
 					chunkSize = std::min(remaining,(unsigned int)(ZT_UDP_DEFAULT_PAYLOAD_MTU - ZT_PROTO_MIN_FRAGMENT_LENGTH));
-					Packet::Fragment frag(tmp,fragStart,chunkSize,f + 1,totalFragments);
+					Packet::Fragment frag(tmp,fragStart,chunkSize,fno,totalFragments);
 					via->send(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;
 }
 

+ 5 - 5
testnet.cpp

@@ -559,11 +559,11 @@ static void doUnicast(const std::vector<std::string> &cmd)
 			SimNode *receiver = nodes[*r];
 			SharedPtr<TestEthernetTap> rtap(receiver->tapFactory.getByNwid(nwid));
 			if (rtap) {
-				while (rtap->getNextReceivedFrame(frame,1)) {
+				if (rtap->getNextReceivedFrame(frame,5)) {
 					if ((frame.len == frameLen)&&(!memcmp(frame.data + 16,pkt.data + 16,frameLen - 16))) {
 						uint64_t ints[2];
 						memcpy(ints,frame.data,16);
-						printf("%s <- %.10llx received test packet, latency == %llums"ZT_EOL_S,r->toString().c_str(),ints[0],frame.timestamp - ints[1]);
+						printf("%s <- %.10llx received test packet, length == %u, latency == %llums"ZT_EOL_S,r->toString().c_str(),ints[0],frame.len,frame.timestamp - ints[1]);
 						receivedPairs.insert(std::pair<Address,Address>(Address(ints[0]),*r));
 					} else {
 						printf("%s !! got spurious packet, length == %u, etherType == 0x%.4x"ZT_EOL_S,r->toString().c_str(),frame.len,frame.etherType);
@@ -647,19 +647,19 @@ static void doMulticast(const std::vector<std::string> &cmd)
 
 	printf("---------- waiting %llu seconds..."ZT_EOL_S,tout / 1000ULL);
 
-	uint64_t toutend = Utils::now() + tout;
 	unsigned int receiveCount = 0;
 	TestEthernetTap::TestFrame frame;
+	uint64_t toutend = Utils::now() + tout;
 	do {
 		for(std::map< Address,SimNode * >::iterator nn(nodes.begin());nn!=nodes.end();++nn) {
 			SimNode *receiver = nn->second;
 			SharedPtr<TestEthernetTap> rtap(receiver->tapFactory.getByNwid(nwid));
 			if (rtap) {
-				while (rtap->getNextReceivedFrame(frame,1)) {
+				if (rtap->getNextReceivedFrame(frame,5)) {
 					if ((frame.len == frameLen)&&(!memcmp(frame.data + 16,pkt.data + 16,frameLen - 16))) {
 						uint64_t ints[2];
 						memcpy(ints,frame.data,16);
-						printf("%s <- %.10llx received test packet, latency == %llums"ZT_EOL_S,nn->first.toString().c_str(),ints[0],frame.timestamp - ints[1]);
+						printf("%s <- %.10llx received test packet, length == %u, latency == %llums"ZT_EOL_S,nn->first.toString().c_str(),ints[0],frame.len,frame.timestamp - ints[1]);
 						++receiveCount;
 					} else {
 						printf("%s !! got spurious packet, length == %u, etherType == 0x%.4x"ZT_EOL_S,nn->first.toString().c_str(),frame.len,frame.etherType);

+ 1 - 1
testnet/TestEthernetTap.cpp

@@ -128,7 +128,7 @@ bool TestEthernetTap::updateMulticastGroups(std::set<MulticastGroup> &groups)
 
 bool TestEthernetTap::injectPacketFromHost(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len)
 {
-	if ((len == 0)||(len > 2800))
+	if ((len == 0)||(len > _mtu))
 		return false;
 	_pq.push(TestFrame(from,to,data,etherType & 0xffff,len));
 	return true;