Browse Source

Cleanup, and implement compression disable flag for networks.

Adam Ierymenko 8 years ago
parent
commit
cc4bacc199

+ 2 - 5
node/IncomingPacket.cpp

@@ -425,12 +425,12 @@ bool IncomingPacket::_doOK(const RuntimeEnvironment *RR,const SharedPtr<Peer> &p
 					RR->sa->iam(peer->address(),_path->localAddress(),_path->address(),externalSurfaceAddress,RR->topology->isUpstream(peer->identity()),RR->node->now());
 			}	break;
 
-			case Packet::VERB_WHOIS: {
+			case Packet::VERB_WHOIS:
 				if (RR->topology->isUpstream(peer->identity())) {
 					const Identity id(*this,ZT_PROTO_VERB_WHOIS__OK__IDX_IDENTITY);
 					RR->sw->doAnythingWaitingForPeer(RR->topology->addPeer(SharedPtr<Peer>(new Peer(RR,RR->identity,id))));
 				}
-			} break;
+				break;
 
 			case Packet::VERB_NETWORK_CONFIG_REQUEST: {
 				const SharedPtr<Network> network(RR->node->network(at<uint64_t>(ZT_PROTO_VERB_OK_IDX_PAYLOAD)));
@@ -438,9 +438,6 @@ bool IncomingPacket::_doOK(const RuntimeEnvironment *RR,const SharedPtr<Peer> &p
 					network->handleConfigChunk(*this,ZT_PROTO_VERB_OK_IDX_PAYLOAD);
 			}	break;
 
-			//case Packet::VERB_ECHO: {
-			//}	break;
-
 			case Packet::VERB_MULTICAST_GATHER: {
 				const uint64_t nwid = at<uint64_t>(ZT_PROTO_VERB_MULTICAST_GATHER__OK__IDX_NETWORK_ID);
 				const SharedPtr<Network> network(RR->node->network(nwid));

+ 3 - 0
node/Multicaster.cpp

@@ -155,6 +155,7 @@ void Multicaster::send(
 	unsigned int limit,
 	uint64_t now,
 	uint64_t nwid,
+	bool disableCompression,
 	const std::vector<Address> &alwaysSendTo,
 	const MulticastGroup &mg,
 	const MAC &src,
@@ -193,6 +194,7 @@ void Multicaster::send(
 				RR,
 				now,
 				nwid,
+				disableCompression,
 				limit,
 				1, // we'll still gather a little from peers to keep multicast list fresh
 				src,
@@ -265,6 +267,7 @@ void Multicaster::send(
 				RR,
 				now,
 				nwid,
+				disableCompression,
 				limit,
 				gatherLimit,
 				src,

+ 2 - 0
node/Multicaster.hpp

@@ -153,6 +153,7 @@ public:
 	 * @param limit Multicast limit
 	 * @param now Current time
 	 * @param nwid Network ID
+	 * @param disableCompression Disable packet payload compression?
 	 * @param alwaysSendTo Send to these peers first and even if not included in subscriber list
 	 * @param mg Multicast group
 	 * @param src Source Ethernet MAC address or NULL to skip in packet and compute from ZT address (non-bridged mode)
@@ -164,6 +165,7 @@ public:
 		unsigned int limit,
 		uint64_t now,
 		uint64_t nwid,
+		bool disableCompression,
 		const std::vector<Address> &alwaysSendTo,
 		const MulticastGroup &mg,
 		const MAC &src,

+ 0 - 1
node/Network.cpp

@@ -962,7 +962,6 @@ uint64_t Network::handleConfigChunk(const Packet &chunk,unsigned int ptr)
 		if (totalLength >= ZT_NETWORKCONFIG_DICT_CAPACITY)
 			return 0;
 
-		// Find oldest slot for this udpate to use buffer space
 		for(int i=0;i<ZT_NETWORK_MAX_INCOMING_UPDATES;++i) {
 			if ((!c)||(_incomingConfigChunks[i].ts < c->ts))
 				c = &(_incomingConfigChunks[i]);

+ 10 - 0
node/NetworkConfig.hpp

@@ -76,6 +76,11 @@
  */
 #define ZT_NETWORKCONFIG_FLAG_RULES_RESULT_OF_UNSUPPORTED_MATCH 0x0000000000000008ULL
 
+/**
+ * Flag: disable frame compression
+ */
+#define ZT_NETWORKCONFIG_FLAG_DISABLE_COMPRESSION 0x0000000000000010ULL
+
 /**
  * Device is an active bridge
  */
@@ -255,6 +260,11 @@ public:
 	 */
 	inline bool ndpEmulation() const throw() { return ((this->flags & ZT_NETWORKCONFIG_FLAG_ENABLE_IPV6_NDP_EMULATION) != 0); }
 
+	/**
+	 * @return True if frames should not be compressed
+	 */
+	inline bool disableCompression() const throw() { return ((this->flags & ZT_NETWORKCONFIG_FLAG_DISABLE_COMPRESSION) != 0); }
+
 	/**
 	 * @return Network type is public (no access control)
 	 */

+ 3 - 1
node/OutboundMulticast.cpp

@@ -31,6 +31,7 @@ void OutboundMulticast::init(
 	const RuntimeEnvironment *RR,
 	uint64_t timestamp,
 	uint64_t nwid,
+	bool disableCompression,
 	unsigned int limit,
 	unsigned int gatherLimit,
 	const MAC &src,
@@ -78,7 +79,8 @@ void OutboundMulticast::init(
 	_packet.append((uint32_t)dest.adi());
 	_packet.append((uint16_t)etherType);
 	_packet.append(payload,_frameLen);
-	_packet.compress();
+	if (!disableCompression)
+		_packet.compress();
 
 	memcpy(_frameData,payload,_frameLen);
 }

+ 2 - 0
node/OutboundMulticast.hpp

@@ -56,6 +56,7 @@ public:
 	 * @param RR Runtime environment
 	 * @param timestamp Creation time
 	 * @param nwid Network ID
+	 * @param disableCompression Disable compression of frame payload
 	 * @param limit Multicast limit for desired number of packets to send
 	 * @param gatherLimit Number to lazily/implicitly gather with this frame or 0 for none
 	 * @param src Source MAC address of frame or NULL to imply compute from sender ZT address
@@ -69,6 +70,7 @@ public:
 		const RuntimeEnvironment *RR,
 		uint64_t timestamp,
 		uint64_t nwid,
+		bool disableCompression,
 		unsigned int limit,
 		unsigned int gatherLimit,
 		const MAC &src,

+ 3 - 0
node/Packet.hpp

@@ -799,6 +799,9 @@ public:
 		 * carries the same payload as OK(NETWORK_CONFIG_REQUEST) and has the same
 		 * semantics.
 		 *
+		 * The legacy mode missing the additional chunking fields is not supported
+		 * here.
+		 *
 		 * Flags:
 		 *   0x01 - Use fast propagation
 		 *

+ 7 - 3
node/Switch.cpp

@@ -476,6 +476,7 @@ void Switch::onLocalEthernet(const SharedPtr<Network> &network,const MAC &from,c
 			network->config().multicastLimit,
 			RR->node->now(),
 			network->id(),
+			network->config().disableCompression(),
 			network->config().activeBridges(),
 			multicastGroup,
 			(fromBridged) ? from : MAC(),
@@ -501,14 +502,16 @@ void Switch::onLocalEthernet(const SharedPtr<Network> &network,const MAC &from,c
 			from.appendTo(outp);
 			outp.append((uint16_t)etherType);
 			outp.append(data,len);
-			outp.compress();
+			if (!network->config().disableCompression())
+				outp.compress();
 			send(outp,true);
 		} else {
 			Packet outp(toZT,RR->identity.address(),Packet::VERB_FRAME);
 			outp.append(network->id());
 			outp.append((uint16_t)etherType);
 			outp.append(data,len);
-			outp.compress();
+			if (!network->config().disableCompression())
+				outp.compress();
 			send(outp,true);
 		}
 
@@ -565,7 +568,8 @@ void Switch::onLocalEthernet(const SharedPtr<Network> &network,const MAC &from,c
 				from.appendTo(outp);
 				outp.append((uint16_t)etherType);
 				outp.append(data,len);
-				outp.compress();
+				if (!network->config().disableCompression())
+					outp.compress();
 				send(outp,true);
 			} else {
 				TRACE("%.16llx: %s -> %s %s packet not sent: filterOutgoingPacket() returned false",network->id(),from.toString().c_str(),to.toString().c_str(),etherTypeName(etherType));