Browse Source

Some CLI help updates, some code formatting, pre-reorg.

Adam Ierymenko 5 năm trước cách đây
mục cha
commit
03bcdf74a8
5 tập tin đã thay đổi với 58 bổ sung52 xóa
  1. 4 1
      .gitignore
  2. 0 1
      include/ZeroTierCore.h
  3. 1 1
      node/AES.cpp
  4. 48 48
      node/Buf.hpp
  5. 5 1
      node/Constants.hpp

+ 4 - 1
.gitignore

@@ -36,7 +36,9 @@ Commands:
   version                                Print version
   service                                Start as service
   status                                 Show node status and configuration
-  join <network> [fingerprint]           Join a virtual network
+  join <network> [option]                Join a virtual network
+    auth <token>                         Join authorization token
+    fingerprint <fingerprint>            Full controller identity fingerprint
   leave <network>                        Leave a virtual network
   networks                               List VL2 virtual networks
   network <network> [command] [option] - Network management commands
@@ -57,6 +59,7 @@ Commands:
     add <identity> [endpoint]            Designate a peer as a root
     remove <address>                     Un-designate a peer as a root
     subscribe <url>                      Subscribe to a root set
+    unsubscribe <url>                    Unsubscribe from a root set
   set [option] [value]                 - Get or set a core config option
     port <port>                          Primary P2P port
     secondaryport <port/0>               Secondary P2P port (0 to disable)

+ 0 - 1
include/ZeroTierCore.h

@@ -376,7 +376,6 @@ enum ZT_TracePacketDropReason
 	ZT_TRACE_PACKET_DROP_REASON_INVALID_COMPRESSED_DATA = 6,
 	ZT_TRACE_PACKET_DROP_REASON_UNRECOGNIZED_VERB =       7,
 	ZT_TRACE_PACKET_DROP_REASON_REPLY_NOT_EXPECTED =      8
-
 };
 
 /**

+ 1 - 1
node/AES.cpp

@@ -1116,7 +1116,7 @@ void AES::_encryptSW(const uint8_t in[16], uint8_t out[16]) const noexcept
 
 void AES::_decryptSW(const uint8_t in[16], uint8_t out[16]) const noexcept
 {
-	const uint32_t *const restrict rk = _k.sw.dk;
+	const uint32_t *restrict rk = _k.sw.dk;
 	uint32_t s0, s1, s2, s3, t0, t1, t2, t3;
 	const uint32_t m8 = 0xff;
 	s0 = readuint32_t(in) ^ rk[0];

+ 48 - 48
node/Buf.hpp

@@ -79,7 +79,7 @@ namespace ZeroTier {
  */
 class Buf
 {
-	friend class SharedPtr<Buf>;
+	friend class SharedPtr< Buf >;
 
 public:
 	// New and delete operators that allocate Buf instances from a shared lock-free memory pool.
@@ -115,7 +115,7 @@ public:
 	 */
 	struct Slice : TriviallyCopyable
 	{
-		ZT_INLINE Slice(const SharedPtr<Buf> &b_, const unsigned int s_, const unsigned int e_) noexcept: b(b_), s(s_), e(e_)
+		ZT_INLINE Slice(const SharedPtr< Buf > &b_, const unsigned int s_, const unsigned int e_) noexcept: b(b_), s(s_), e(e_)
 		{}
 
 		ZT_INLINE Slice() noexcept: b(), s(0), e(0)
@@ -137,7 +137,7 @@ public:
 		/**
 		 * Buffer holding slice data
 		 */
-		SharedPtr<Buf> b;
+		SharedPtr< Buf > b;
 
 		/**
 		 * Index of start of data in slice
@@ -153,16 +153,16 @@ public:
 	/**
 	 * A vector of slices making up a packet that might span more than one buffer.
 	 */
-	class PacketVector : public ZeroTier::FCV<Slice, ZT_MAX_PACKET_FRAGMENTS>
+	class PacketVector : public ZeroTier::FCV< Slice, ZT_MAX_PACKET_FRAGMENTS >
 	{
 	public:
-		ZT_INLINE PacketVector() : ZeroTier::FCV<Slice, ZT_MAX_PACKET_FRAGMENTS>()
+		ZT_INLINE PacketVector() : ZeroTier::FCV< Slice, ZT_MAX_PACKET_FRAGMENTS >()
 		{}
 
 		ZT_INLINE unsigned int totalSize() const noexcept
 		{
 			unsigned int size = 0;
-			for (PacketVector::const_iterator s(begin());s != end();++s)
+			for (PacketVector::const_iterator s(begin()); s != end(); ++s)
 				size += s->e - s->s;
 			return size;
 		}
@@ -176,7 +176,7 @@ public:
 		ZT_INLINE int mergeCopy(Buf &b) const noexcept
 		{
 			unsigned int size = 0;
-			for (PacketVector::const_iterator s(begin());s != end();++s) {
+			for (PacketVector::const_iterator s(begin()); s != end(); ++s) {
 				const unsigned int start = s->s;
 				const unsigned int rem = s->e - start;
 				if (likely((size + rem) <= ZT_BUF_MEM_SIZE)) {
@@ -186,7 +186,7 @@ public:
 					return -1;
 				}
 			}
-			return (int) size;
+			return (int)size;
 		}
 
 		/**
@@ -200,11 +200,11 @@ public:
 		 * @tparam F Type of copyFunction (typically inferred)
 		 * @return Size of data in destination or -1 on error
 		 */
-		template<typename F>
+		template< typename F >
 		ZT_INLINE int mergeMap(Buf &b, const unsigned int simpleCopyBefore, F copyFunction) const noexcept
 		{
 			unsigned int size = 0;
-			for (PacketVector::const_iterator s(begin());s != end();++s) {
+			for (PacketVector::const_iterator s(begin()); s != end(); ++s) {
 				unsigned int start = s->s;
 				unsigned int rem = s->e - start;
 				if (likely((size + rem) <= ZT_BUF_MEM_SIZE)) {
@@ -225,7 +225,7 @@ public:
 					return -1;
 				}
 			}
-			return (int) size;
+			return (int)size;
 		}
 	};
 
@@ -248,13 +248,13 @@ public:
 		__nextInPool(0),
 		__refCount(0)
 	{
-		Utils::copy<ZT_BUF_MEM_SIZE>(unsafeData, b2.unsafeData);
+		Utils::copy< ZT_BUF_MEM_SIZE >(unsafeData, b2.unsafeData);
 	}
 
 	ZT_INLINE Buf &operator=(const Buf &b2) noexcept
 	{
 		if (this != &b2)
-			Utils::copy<ZT_BUF_MEM_SIZE>(unsafeData, b2.unsafeData);
+			Utils::copy< ZT_BUF_MEM_SIZE >(unsafeData, b2.unsafeData);
 		return *this;
 	}
 
@@ -281,14 +281,14 @@ public:
 	 * @return True if iterator has read past the size of the data
 	 */
 	static ZT_INLINE bool readOverflow(const int &ii, const unsigned int size) noexcept
-	{ return ((ii - (int) size) > 0); }
+	{ return ((ii - (int)size) > 0); }
 
 	/**
 	 * Set all memory to zero
 	 */
 	ZT_INLINE void clear() noexcept
 	{
-		Utils::zero<ZT_BUF_MEM_SIZE>(unsafeData);
+		Utils::zero< ZT_BUF_MEM_SIZE >(unsafeData);
 	}
 
 	/**
@@ -300,7 +300,7 @@ public:
 	ZT_INLINE uint8_t rI8(int &ii) const noexcept
 	{
 		const int s = ii++;
-		return unsafeData[(unsigned int) s & ZT_BUF_MEM_MASK];
+		return unsafeData[(unsigned int)s & ZT_BUF_MEM_MASK];
 	}
 
 	/**
@@ -311,7 +311,7 @@ public:
 	 */
 	ZT_INLINE uint16_t rI16(int &ii) const noexcept
 	{
-		const unsigned int s = (unsigned int) ii & ZT_BUF_MEM_MASK;
+		const unsigned int s = (unsigned int)ii & ZT_BUF_MEM_MASK;
 		ii += 2;
 #ifdef ZT_NO_UNALIGNED_ACCESS
 		return (
@@ -330,7 +330,7 @@ public:
 	 */
 	ZT_INLINE uint32_t rI32(int &ii) const noexcept
 	{
-		const unsigned int s = (unsigned int) ii & ZT_BUF_MEM_MASK;
+		const unsigned int s = (unsigned int)ii & ZT_BUF_MEM_MASK;
 		ii += 4;
 #ifdef ZT_NO_UNALIGNED_ACCESS
 		return (
@@ -351,7 +351,7 @@ public:
 	 */
 	ZT_INLINE uint64_t rI64(int &ii) const noexcept
 	{
-		const unsigned int s = (unsigned int) ii & ZT_BUF_MEM_MASK;
+		const unsigned int s = (unsigned int)ii & ZT_BUF_MEM_MASK;
 		ii += 8;
 #ifdef ZT_NO_UNALIGNED_ACCESS
 		return (
@@ -383,7 +383,7 @@ public:
 	 * @param obj Object to read
 	 * @return Bytes read or a negative value on unmarshal error (passed from object) or overflow
 	 */
-	template<typename T>
+	template< typename T >
 	ZT_INLINE int rO(int &ii, T &obj) const noexcept
 	{
 		if (likely(ii < ZT_BUF_MEM_SIZE)) {
@@ -408,12 +408,12 @@ public:
 	 */
 	ZT_INLINE char *rS(int &ii, char *const buf, const unsigned int bufSize) const noexcept
 	{
-		const char *const s = (const char *) (unsafeData + ii);
+		const char *const s = (const char *)(unsafeData + ii);
 		const int sii = ii;
 		while (ii < ZT_BUF_MEM_SIZE) {
 			if (unsafeData[ii++] == 0) {
 				const int l = ii - sii;
-				if (unlikely((unsigned int) l > bufSize))
+				if (unlikely((unsigned int)l > bufSize))
 					return nullptr;
 				Utils::copy(buf, s, l);
 				return buf;
@@ -437,7 +437,7 @@ public:
 	 */
 	ZT_INLINE const char *rSnc(int &ii) const noexcept
 	{
-		const char *const s = (const char *) (unsafeData + ii);
+		const char *const s = (const char *)(unsafeData + ii);
 		while (ii < ZT_BUF_MEM_SIZE) {
 			if (unsafeData[ii++] == 0)
 				return s;
@@ -458,7 +458,7 @@ public:
 	 */
 	ZT_INLINE uint8_t *rB(int &ii, void *const bytes, const unsigned int len) const noexcept
 	{
-		if (likely(((ii += (int) len) <= ZT_BUF_MEM_SIZE))) {
+		if (likely(((ii += (int)len) <= ZT_BUF_MEM_SIZE))) {
 			Utils::copy(bytes, unsafeData + ii, len);
 			return reinterpret_cast<uint8_t *>(bytes);
 		}
@@ -481,7 +481,7 @@ public:
 	ZT_INLINE const uint8_t *rBnc(int &ii, unsigned int len) const noexcept
 	{
 		const uint8_t *const b = unsafeData + ii;
-		return ((ii += (int) len) <= ZT_BUF_MEM_SIZE) ? b : nullptr;
+		return ((ii += (int)len) <= ZT_BUF_MEM_SIZE) ? b : nullptr;
 	}
 
 	/**
@@ -490,7 +490,7 @@ public:
 	 * @tparam I Static index
 	 * @return Value
 	 */
-	template<unsigned int I>
+	template< unsigned int I >
 	ZT_INLINE uint8_t lI8() const noexcept
 	{
 		static_assert(I < ZT_BUF_MEM_SIZE, "overflow");
@@ -503,7 +503,7 @@ public:
 	 * @tparam I Static index
 	 * @return Value
 	 */
-	template<unsigned int I>
+	template< unsigned int I >
 	ZT_INLINE uint8_t lI16() const noexcept
 	{
 		static_assert((I + 1) < ZT_BUF_MEM_SIZE, "overflow");
@@ -522,7 +522,7 @@ public:
 	 * @tparam I Static index
 	 * @return Value
 	 */
-	template<unsigned int I>
+	template< unsigned int I >
 	ZT_INLINE uint8_t lI32() const noexcept
 	{
 		static_assert((I + 3) < ZT_BUF_MEM_SIZE, "overflow");
@@ -543,7 +543,7 @@ public:
 	 * @tparam I Static index
 	 * @return Value
 	 */
-	template<unsigned int I>
+	template< unsigned int I >
 	ZT_INLINE uint8_t lI64() const noexcept
 	{
 		static_assert((I + 7) < ZT_BUF_MEM_SIZE, "overflow");
@@ -571,7 +571,7 @@ public:
 	 */
 	ZT_INLINE uint8_t lI8(const int ii) const noexcept
 	{
-		return unsafeData[(unsigned int) ii & ZT_BUF_MEM_MASK];
+		return unsafeData[(unsigned int)ii & ZT_BUF_MEM_MASK];
 	}
 
 	/**
@@ -583,7 +583,7 @@ public:
 	 */
 	ZT_INLINE uint16_t lI16(const int ii) const noexcept
 	{
-		const unsigned int s = (unsigned int) ii & ZT_BUF_MEM_MASK;
+		const unsigned int s = (unsigned int)ii & ZT_BUF_MEM_MASK;
 #ifdef ZT_NO_UNALIGNED_ACCESS
 		return (
 			((uint16_t)unsafeData[s] << 8U) |
@@ -602,7 +602,7 @@ public:
 	 */
 	ZT_INLINE uint32_t lI32(const int ii) const noexcept
 	{
-		const unsigned int s = (unsigned int) ii & ZT_BUF_MEM_MASK;
+		const unsigned int s = (unsigned int)ii & ZT_BUF_MEM_MASK;
 #ifdef ZT_NO_UNALIGNED_ACCESS
 		return (
 			((uint32_t)unsafeData[s] << 24U) |
@@ -623,7 +623,7 @@ public:
 	 */
 	ZT_INLINE uint8_t lI64(const int ii) const noexcept
 	{
-		const unsigned int s = (unsigned int) ii & ZT_BUF_MEM_MASK;
+		const unsigned int s = (unsigned int)ii & ZT_BUF_MEM_MASK;
 #ifdef ZT_NO_UNALIGNED_ACCESS
 		return (
 			((uint64_t)unsafeData[s] << 56U) |
@@ -648,7 +648,7 @@ public:
 	ZT_INLINE void wI8(int &ii, const uint8_t n) noexcept
 	{
 		const int s = ii++;
-		unsafeData[(unsigned int) s & ZT_BUF_MEM_MASK] = n;
+		unsafeData[(unsigned int)s & ZT_BUF_MEM_MASK] = n;
 	}
 
 	/**
@@ -659,7 +659,7 @@ public:
 	 */
 	ZT_INLINE void wI16(int &ii, const uint16_t n) noexcept
 	{
-		const unsigned int s = ((unsigned int) ii) & ZT_BUF_MEM_MASK;
+		const unsigned int s = ((unsigned int)ii) & ZT_BUF_MEM_MASK;
 		ii += 2;
 #ifdef ZT_NO_UNALIGNED_ACCESS
 		unsafeData[s] = (uint8_t)(n >> 8U);
@@ -677,7 +677,7 @@ public:
 	 */
 	ZT_INLINE void wI32(int &ii, const uint32_t n) noexcept
 	{
-		const unsigned int s = ((unsigned int) ii) & ZT_BUF_MEM_MASK;
+		const unsigned int s = ((unsigned int)ii) & ZT_BUF_MEM_MASK;
 		ii += 4;
 #ifdef ZT_NO_UNALIGNED_ACCESS
 		unsafeData[s] = (uint8_t)(n >> 24U);
@@ -697,7 +697,7 @@ public:
 	 */
 	ZT_INLINE void wI64(int &ii, const uint64_t n) noexcept
 	{
-		const unsigned int s = ((unsigned int) ii) & ZT_BUF_MEM_MASK;
+		const unsigned int s = ((unsigned int)ii) & ZT_BUF_MEM_MASK;
 		ii += 8;
 #ifdef ZT_NO_UNALIGNED_ACCESS
 		unsafeData[s] = (uint8_t)(n >> 56U);
@@ -720,7 +720,7 @@ public:
 	 * @param ii Index value-result parameter (incremented by size of object)
 	 * @param t Object to write
 	 */
-	template<typename T>
+	template< typename T >
 	ZT_INLINE void wO(int &ii, T &t) noexcept
 	{
 		const int s = ii;
@@ -745,7 +745,7 @@ public:
 			char c;
 			do {
 				c = *(s++);
-				wI8(ii, (uint8_t) c);
+				wI8(ii, (uint8_t)c);
 			} while (c);
 		} else {
 			wI8(ii, 0);
@@ -762,7 +762,7 @@ public:
 	ZT_INLINE void wB(int &ii, const void *const bytes, const unsigned int len) noexcept
 	{
 		const int s = ii;
-		if (likely((ii += (int) len) <= ZT_BUF_MEM_SIZE))
+		if (likely((ii += (int)len) <= ZT_BUF_MEM_SIZE))
 			Utils::copy(unsafeData + s, bytes, len);
 	}
 
@@ -775,7 +775,7 @@ public:
 	ZT_INLINE void wZ(int &ii, const unsigned int len) noexcept
 	{
 		const int s = ii;
-		if (likely((ii += (int) len) <= ZT_BUF_MEM_SIZE))
+		if (likely((ii += (int)len) <= ZT_BUF_MEM_SIZE))
 			Utils::zero(unsafeData + s, len);
 	}
 
@@ -788,7 +788,7 @@ public:
 	ZT_INLINE void wR(int &ii, const unsigned int len) noexcept
 	{
 		const int s = ii;
-		if (likely((ii += (int) len) <= ZT_BUF_MEM_SIZE))
+		if (likely((ii += (int)len) <= ZT_BUF_MEM_SIZE))
 			Utils::getSecureRandom(unsafeData + s, len);
 	}
 
@@ -797,7 +797,7 @@ public:
 	 */
 	ZT_INLINE void sI8(const int ii, const uint8_t n) noexcept
 	{
-		unsafeData[(unsigned int) ii & ZT_BUF_MEM_MASK] = n;
+		unsafeData[(unsigned int)ii & ZT_BUF_MEM_MASK] = n;
 	}
 
 	/**
@@ -805,7 +805,7 @@ public:
 	 */
 	ZT_INLINE void sI16(const int ii, const uint16_t n) noexcept
 	{
-		const unsigned int s = ((unsigned int) ii) & ZT_BUF_MEM_MASK;
+		const unsigned int s = ((unsigned int)ii) & ZT_BUF_MEM_MASK;
 #ifdef ZT_NO_UNALIGNED_ACCESS
 		unsafeData[s] = (uint8_t)(n >> 8U);
 		unsafeData[s + 1] = (uint8_t)n;
@@ -819,7 +819,7 @@ public:
 	 */
 	ZT_INLINE void sI32(const int ii, const uint32_t n) noexcept
 	{
-		const unsigned int s = ((unsigned int) ii) & ZT_BUF_MEM_MASK;
+		const unsigned int s = ((unsigned int)ii) & ZT_BUF_MEM_MASK;
 #ifdef ZT_NO_UNALIGNED_ACCESS
 		unsafeData[s] = (uint8_t)(n >> 24U);
 		unsafeData[s + 1] = (uint8_t)(n >> 16U);
@@ -835,7 +835,7 @@ public:
 	 */
 	ZT_INLINE void sI64(const int ii, const uint64_t n) noexcept
 	{
-		const unsigned int s = ((unsigned int) ii) & ZT_BUF_MEM_MASK;
+		const unsigned int s = ((unsigned int)ii) & ZT_BUF_MEM_MASK;
 #ifdef ZT_NO_UNALIGNED_ACCESS
 		unsafeData[s] = (uint8_t)(n >> 56U);
 		unsafeData[s + 1] = (uint8_t)(n >> 48U);
@@ -858,10 +858,10 @@ public:
 
 private:
 	// Next item in free buffer pool linked list if Buf is placed in pool, undefined and unused otherwise
-	std::atomic<uintptr_t> __nextInPool;
+	std::atomic< uintptr_t > __nextInPool;
 
 	// Reference counter for SharedPtr<>
-	std::atomic<int> __refCount;
+	std::atomic< int > __refCount;
 };
 
 } // namespace ZeroTier

+ 5 - 1
node/Constants.hpp

@@ -29,7 +29,11 @@
 /**
  * Version bit packed into four 16-bit fields in a 64-bit unsigned integer.
  */
-#define ZT_VERSION_PACKED ( ((uint64_t)ZEROTIER_VERSION_MAJOR << 48U) | ((uint64_t)ZEROTIER_VERSION_MINOR << 32U) | ((uint64_t)ZEROTIER_VERSION_REVISION << 16U) | (uint64_t)ZEROTIER_VERSION_BUILD )
+#define ZT_VERSION_PACKED ( \
+	((uint64_t)ZEROTIER_VERSION_MAJOR << 48U) | \
+	((uint64_t)ZEROTIER_VERSION_MINOR << 32U) | \
+	((uint64_t)ZEROTIER_VERSION_REVISION << 16U) | \
+	(uint64_t)ZEROTIER_VERSION_BUILD )
 
 /**
  * Length of a ZeroTier address in bytes