diff --git a/node/Containers.hpp b/node/Containers.hpp index 27aa059cf..f615ae452 100644 --- a/node/Containers.hpp +++ b/node/Containers.hpp @@ -154,7 +154,7 @@ class String : public std::basic_string< char,std::char_traits,Utils::Mall public: ZT_INLINE String() {} explicit ZT_INLINE String(const char *const s) { assign(s); } - ZT_INLINE &operator=(const char *const s) { assign(s); } + ZT_INLINE String &operator=(const char *const s) { assign(s); return *this; } }; } // ZeroTier diff --git a/node/Endpoint.hpp b/node/Endpoint.hpp index e75910ada..6f2f0412d 100644 --- a/node/Endpoint.hpp +++ b/node/Endpoint.hpp @@ -106,7 +106,7 @@ public: /** * @return True if endpoint type isn't NIL */ - ZT_INLINE operator bool() const noexcept { return (m_value[ZT_ENDPOINT_MARSHAL_SIZE_MAX] != (uint8_t)ZT_ENDPOINT_TYPE_NIL); } + ZT_INLINE operator bool() const noexcept { return (m_value[ZT_ENDPOINT_MARSHAL_SIZE_MAX-1] != (uint8_t)ZT_ENDPOINT_TYPE_NIL); } /** * @return True if this endpoint type has an InetAddress address type and thus ip() is valid diff --git a/node/EphemeralKey.hpp b/node/EphemeralKey.hpp index 6f32f3170..cae8c8561 100644 --- a/node/EphemeralKey.hpp +++ b/node/EphemeralKey.hpp @@ -62,8 +62,9 @@ public: * Create an uninitialized ephemeral key (must call generate()) */ ZT_INLINE EphemeralKey() noexcept : - pub({0}) + pub() { + const_cast(pub)[0] = (uint8_t)TYPE_NIL; Utils::memoryLock(this,sizeof(EphemeralKey)); } diff --git a/node/FCV.hpp b/node/FCV.hpp index fde7faf8b..f0ea0ed24 100644 --- a/node/FCV.hpp +++ b/node/FCV.hpp @@ -46,11 +46,6 @@ public: typedef T * iterator; typedef const T * const_iterator; - /** - * @return True if this FCV is trivially copyable, which means its type is also. - */ - static constexpr bool isTriviallyCopyable() noexcept { return ZeroTier::isTriviallyCopyable(reinterpret_cast(nullptr)); } - ZT_INLINE FCV() noexcept : _s(0) {} // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init) ZT_INLINE FCV(const FCV &v) : _s(0) { *this = v; } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init) @@ -220,7 +215,7 @@ public: * @param i Index to obtain as a reference, resizing if needed * @return Reference to value at this index */ - ZT_INLINE T &at(const unsigned int i) + ZT_INLINE T &at(unsigned int i) { if (i >= _s) { if (unlikely(i >= C)) diff --git a/node/Fingerprint.hpp b/node/Fingerprint.hpp index 9d46db820..51c8a7d0d 100644 --- a/node/Fingerprint.hpp +++ b/node/Fingerprint.hpp @@ -41,7 +41,7 @@ public: /** * Create an empty/nil fingerprint */ - ZT_INLINE Fingerprint() noexcept { memoryZero(this); } // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init) + ZT_INLINE Fingerprint() noexcept { memoryZero(this); } ZT_INLINE Address address() const noexcept { return Address(m_cfp.address); } ZT_INLINE const uint8_t *hash() const noexcept { return m_cfp.hash; } @@ -86,7 +86,7 @@ public: ZT_INLINE void zero() noexcept { memoryZero(this); } ZT_INLINE unsigned long hashCode() const noexcept { return (unsigned long)m_cfp.address; } - ZT_INLINE operator bool() const noexcept { return (m_cfp.address != 0); } // NOLINT(google-explicit-constructor,hicpp-explicit-conversions) + ZT_INLINE operator bool() const noexcept { return (m_cfp.address != 0); } ZT_INLINE bool operator==(const Fingerprint &h) const noexcept { return ((m_cfp.address == h.m_cfp.address) && (memcmp(m_cfp.hash, h.m_cfp.hash, ZT_FINGERPRINT_HASH_SIZE) == 0)); } ZT_INLINE bool operator!=(const Fingerprint &h) const noexcept { return !(*this == h); } diff --git a/node/Identity.cpp b/node/Identity.cpp index d212ee9c5..51970af37 100644 --- a/node/Identity.cpp +++ b/node/Identity.cpp @@ -76,42 +76,35 @@ struct identityV0ProofOfWorkCriteria // It's not quite as heavy as the V0 frankenhash, is a little more orderly in // its design, but remains relatively resistant to GPU acceleration due to memory // requirements for efficient computation. -#define ZT_IDENTITY_V1_POW_MEMORY_SIZE 1048576 -#define ZT_IDENTITY_V1_POW_MEMORY_SIZE_U64 131072 -bool identityV1ProofOfWorkCriteria(const void *in,const unsigned int len,uint64_t *const b) +#define ZT_IDENTITY_V1_POW_MEMORY_SIZE 262144 +#define ZT_IDENTITY_V1_POW_MEMORY_SIZE_U64 32768 +bool identityV1ProofOfWorkCriteria(const void *in,const unsigned int len) { - SHA512(b,in,len); + uint64_t b[ZT_IDENTITY_V1_POW_MEMORY_SIZE_U64]; + SHA512(b,in,len); AES c(b); for(unsigned int i=8;i> 49U))) + if (unlikely((b[i] % 31ULL) == (b[i - 1] >> 59U))) c.encrypt(b + i,b + i); } #if __BYTE_ORDER == __BIG_ENDIAN - for(unsigned int i=0;i via(this->path(now)); + if (via) { + via->send(RR,tPtr,data,len,now); + } else { + const SharedPtr root(RR->topology->root()); + if ((root)&&(root.ptr() != this)) { + via = root->path(now); + if (via) { + via->send(RR,tPtr,data,len,now); + root->relayed(now,len); + } else { + return; + } + } else { + return; + } + } + sent(now,len); +} + unsigned int Peer::hello(void *tPtr,int64_t localSocket,const InetAddress &atAddress,int64_t now) { Buf outp; diff --git a/node/Peer.hpp b/node/Peer.hpp index b41e9fad0..ce3f4241b 100644 --- a/node/Peer.hpp +++ b/node/Peer.hpp @@ -180,27 +180,7 @@ public: * @param data Data to send * @param len Length in bytes */ - ZT_INLINE void send(void *tPtr,int64_t now,const void *data,unsigned int len) noexcept - { - SharedPtr via(this->path(now)); - if (via) { - via->send(RR,tPtr,data,len,now); - } else { - const SharedPtr root(RR->topology->root()); - if ((root)&&(root.ptr() != this)) { - via = root->path(now); - if (via) { - via->send(RR,tPtr,data,len,now); - root->relayed(now,len); - } else { - return; - } - } else { - return; - } - } - sent(now,len); - } + void send(void *tPtr,int64_t now,const void *data,unsigned int len) noexcept; /** * Send a HELLO to this peer at a specified physical address. diff --git a/node/TriviallyCopyable.hpp b/node/TriviallyCopyable.hpp index 474b34bb4..d6358b47a 100644 --- a/node/TriviallyCopyable.hpp +++ b/node/TriviallyCopyable.hpp @@ -36,7 +36,7 @@ public: template static ZT_INLINE void memoryZero(T *obj) noexcept { - static_assert(isTriviallyCopyable(obj),"parameter is not TriviallyCopyable"); + mustBeTriviallyCopyable(obj); Utils::zero(obj); } @@ -49,7 +49,7 @@ public: template static ZT_INLINE void memoryZero(T &obj) noexcept { - static_assert(isTriviallyCopyable(obj),"parameter is not TriviallyCopyable"); + mustBeTriviallyCopyable(obj); Utils::zero(&obj); } @@ -63,7 +63,7 @@ public: template static ZT_INLINE void memoryCopy(T *dest,const T *src) noexcept { - static_assert(isTriviallyCopyable(dest),"parameter is not TriviallyCopyable"); + mustBeTriviallyCopyable(dest); Utils::copy(dest,src); } @@ -77,7 +77,7 @@ public: template static ZT_INLINE void memoryCopy(T *dest,const T &src) noexcept { - static_assert(isTriviallyCopyable(src),"parameter is not TriviallyCopyable"); + mustBeTriviallyCopyable(src); Utils::copy(dest,&src); } @@ -91,7 +91,7 @@ public: template static ZT_INLINE void memoryCopy(T &dest,const T *src) noexcept { - static_assert(isTriviallyCopyable(dest),"parameter is not TriviallyCopyable"); + mustBeTriviallyCopyable(dest); Utils::copy(&dest,src); } @@ -105,17 +105,15 @@ public: template static ZT_INLINE void memoryCopy(T &dest,const T &src) noexcept { - static_assert(isTriviallyCopyable(dest),"parameter is not TriviallyCopyable"); + mustBeTriviallyCopyable(dest); Utils::copy(&dest,&src); } + +private: + static ZT_INLINE void mustBeTriviallyCopyable(const TriviallyCopyable &) noexcept {} + static ZT_INLINE void mustBeTriviallyCopyable(const TriviallyCopyable *) noexcept {} }; -static constexpr bool isTriviallyCopyable(const TriviallyCopyable *) noexcept { return true; } -static constexpr bool isTriviallyCopyable(const void *) noexcept { return false; } - -template -static constexpr bool isTriviallyCopyable(const T &anything) noexcept { return isTriviallyCopyable(&anything); } - } // namespace ZeroTier #endif