mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-05 20:13:44 +02:00
Build fixes
This commit is contained in:
parent
d3777b3eb4
commit
996589894d
11 changed files with 53 additions and 72 deletions
|
@ -154,7 +154,7 @@ class String : public std::basic_string< char,std::char_traits<char>,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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -62,8 +62,9 @@ public:
|
|||
* Create an uninitialized ephemeral key (must call generate())
|
||||
*/
|
||||
ZT_INLINE EphemeralKey() noexcept :
|
||||
pub({0})
|
||||
pub()
|
||||
{
|
||||
const_cast<uint8_t *>(pub)[0] = (uint8_t)TYPE_NIL;
|
||||
Utils::memoryLock(this,sizeof(EphemeralKey));
|
||||
}
|
||||
|
||||
|
|
|
@ -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<const T *>(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))
|
||||
|
|
|
@ -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); }
|
||||
|
|
|
@ -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<ZT_IDENTITY_V1_POW_MEMORY_SIZE_U64;i+=8) {
|
||||
SHA512(b + i,b + (i - 8),64);
|
||||
if (unlikely((b[i] % 31337ULL) == (b[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<ZT_IDENTITY_V1_POW_MEMORY_SIZE_U64;i+=8) {
|
||||
for(unsigned int i=0;i<ZT_IDENTITY_V1_POW_MEMORY_SIZE_U64;i+=4) {
|
||||
b[i] = Utils::swapBytes(b[i]);
|
||||
b[i + 1] = Utils::swapBytes(b[i + 1]);
|
||||
b[i + 2] = Utils::swapBytes(b[i + 2]);
|
||||
b[i + 3] = Utils::swapBytes(b[i + 3]);
|
||||
b[i + 4] = Utils::swapBytes(b[i + 4]);
|
||||
b[i + 5] = Utils::swapBytes(b[i + 5]);
|
||||
b[i + 6] = Utils::swapBytes(b[i + 6]);
|
||||
b[i + 7] = Utils::swapBytes(b[i + 7]);
|
||||
}
|
||||
#endif
|
||||
std::sort(b,b + ZT_IDENTITY_V1_POW_MEMORY_SIZE_U64);
|
||||
#if __BYTE_ORDER == __BIG_ENDIAN
|
||||
for(unsigned int i=0;i<ZT_IDENTITY_V1_POW_MEMORY_SIZE_U64;i+=8) {
|
||||
for(unsigned int i=0;i<ZT_IDENTITY_V1_POW_MEMORY_SIZE_U64;i+=4) {
|
||||
b[i] = Utils::swapBytes(b[i]);
|
||||
b[i + 1] = Utils::swapBytes(b[i + 1]);
|
||||
b[i + 2] = Utils::swapBytes(b[i + 2]);
|
||||
b[i + 3] = Utils::swapBytes(b[i + 3]);
|
||||
b[i + 4] = Utils::swapBytes(b[i + 4]);
|
||||
b[i + 5] = Utils::swapBytes(b[i + 5]);
|
||||
b[i + 6] = Utils::swapBytes(b[i + 6]);
|
||||
b[i + 7] = Utils::swapBytes(b[i + 7]);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -119,7 +112,7 @@ bool identityV1ProofOfWorkCriteria(const void *in,const unsigned int len,uint64_
|
|||
// We also include the original input after so that cryptographically this
|
||||
// is exactly like SHA384(in). This should make any FIPS types happy as
|
||||
// this means the identity hash is SHA384 and not some weird construction.
|
||||
SHA384(b,b,sizeof(b),in,len);
|
||||
SHA384(b,b,ZT_IDENTITY_V1_POW_MEMORY_SIZE,in,len);
|
||||
|
||||
// PoW passes if sum of first two 64-bit integers (treated as little-endian) mod 180 is 0.
|
||||
// This value was picked to yield about 1-2s total on typical desktop and server cores in 2020.
|
||||
|
@ -158,9 +151,6 @@ bool Identity::generate(const Type t)
|
|||
} break;
|
||||
|
||||
case P384: {
|
||||
uint64_t *const b = (uint64_t *)malloc(ZT_IDENTITY_V1_POW_MEMORY_SIZE); // NOLINT(hicpp-use-auto,modernize-use-auto)
|
||||
if (!b)
|
||||
return false;
|
||||
for(;;) {
|
||||
// Loop until we pass the PoW criteria. The nonce is only 8 bits, so generate
|
||||
// some new key material every time it wraps. The ECC384 generator is slightly
|
||||
|
@ -169,7 +159,7 @@ bool Identity::generate(const Type t)
|
|||
C25519::generateCombined(m_pub + 1,m_priv + 1);
|
||||
ECC384GenerateKey(m_pub + 1 + ZT_C25519_COMBINED_PUBLIC_KEY_SIZE,m_priv + ZT_C25519_COMBINED_PRIVATE_KEY_SIZE);
|
||||
for(;;) {
|
||||
if (identityV1ProofOfWorkCriteria(&m_pub,sizeof(m_pub),b))
|
||||
if (identityV1ProofOfWorkCriteria(m_pub,sizeof(m_pub)))
|
||||
break;
|
||||
if (++m_pub[0] == 0)
|
||||
ECC384GenerateKey(m_pub + 1 + ZT_C25519_COMBINED_PUBLIC_KEY_SIZE,m_priv + ZT_C25519_COMBINED_PRIVATE_KEY_SIZE);
|
||||
|
@ -181,7 +171,6 @@ bool Identity::generate(const Type t)
|
|||
if (!m_fp.address().isReserved())
|
||||
break;
|
||||
}
|
||||
free(b);
|
||||
} break;
|
||||
|
||||
default:
|
||||
|
@ -208,12 +197,7 @@ bool Identity::locallyValidate() const noexcept
|
|||
case P384: {
|
||||
if (m_fp.address() != Address(m_fp.hash()))
|
||||
return false;
|
||||
uint64_t *const genmem = (uint64_t *)malloc(ZT_IDENTITY_V1_POW_MEMORY_SIZE * 8);
|
||||
if (!genmem)
|
||||
return false;
|
||||
const bool ok = identityV1ProofOfWorkCriteria(m_pub,sizeof(m_pub),genmem);
|
||||
free(genmem);
|
||||
return ok;
|
||||
return identityV1ProofOfWorkCriteria(m_pub,sizeof(m_pub));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -185,7 +185,7 @@ public:
|
|||
* @return ASCII string representation of identity (pointer to buf)
|
||||
*/
|
||||
char *toString(bool includePrivate,char buf[ZT_IDENTITY_STRING_BUFFER_LENGTH]) const;
|
||||
ZT_INLINE String toString(const bool includePrivate = false) const { char buf[ZT_IDENTITY_STRING_BUFFER_LENGTH]; toString(includePrivate); return String(buf); }
|
||||
ZT_INLINE String toString(const bool includePrivate = false) const { char buf[ZT_IDENTITY_STRING_BUFFER_LENGTH]; toString(includePrivate,buf); return String(buf); }
|
||||
|
||||
/**
|
||||
* Deserialize a human-friendly string
|
||||
|
|
|
@ -91,6 +91,7 @@ public:
|
|||
ZT_INLINE InetAddress &operator=(const sockaddr_storage &ss) noexcept
|
||||
{
|
||||
as.ss = ss;
|
||||
return *this;
|
||||
}
|
||||
ZT_INLINE InetAddress &operator=(const sockaddr_storage *ss) noexcept
|
||||
{
|
||||
|
|
|
@ -142,6 +142,28 @@ void Peer::received(
|
|||
}
|
||||
}
|
||||
|
||||
void Peer::send(void *tPtr,int64_t now,const void *data,unsigned int len) noexcept
|
||||
{
|
||||
SharedPtr<Path> via(this->path(now));
|
||||
if (via) {
|
||||
via->send(RR,tPtr,data,len,now);
|
||||
} else {
|
||||
const SharedPtr<Peer> 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;
|
||||
|
|
|
@ -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<Path> via(this->path(now));
|
||||
if (via) {
|
||||
via->send(RR,tPtr,data,len,now);
|
||||
} else {
|
||||
const SharedPtr<Peer> 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.
|
||||
|
|
|
@ -36,7 +36,7 @@ public:
|
|||
template<typename T>
|
||||
static ZT_INLINE void memoryZero(T *obj) noexcept
|
||||
{
|
||||
static_assert(isTriviallyCopyable(obj),"parameter is not TriviallyCopyable");
|
||||
mustBeTriviallyCopyable(obj);
|
||||
Utils::zero<sizeof(T)>(obj);
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ public:
|
|||
template<typename T>
|
||||
static ZT_INLINE void memoryZero(T &obj) noexcept
|
||||
{
|
||||
static_assert(isTriviallyCopyable(obj),"parameter is not TriviallyCopyable");
|
||||
mustBeTriviallyCopyable(obj);
|
||||
Utils::zero<sizeof(T)>(&obj);
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ public:
|
|||
template<typename T>
|
||||
static ZT_INLINE void memoryCopy(T *dest,const T *src) noexcept
|
||||
{
|
||||
static_assert(isTriviallyCopyable(dest),"parameter is not TriviallyCopyable");
|
||||
mustBeTriviallyCopyable(dest);
|
||||
Utils::copy<sizeof(T)>(dest,src);
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ public:
|
|||
template<typename T>
|
||||
static ZT_INLINE void memoryCopy(T *dest,const T &src) noexcept
|
||||
{
|
||||
static_assert(isTriviallyCopyable(src),"parameter is not TriviallyCopyable");
|
||||
mustBeTriviallyCopyable(src);
|
||||
Utils::copy<sizeof(T)>(dest,&src);
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ public:
|
|||
template<typename T>
|
||||
static ZT_INLINE void memoryCopy(T &dest,const T *src) noexcept
|
||||
{
|
||||
static_assert(isTriviallyCopyable(dest),"parameter is not TriviallyCopyable");
|
||||
mustBeTriviallyCopyable(dest);
|
||||
Utils::copy<sizeof(T)>(&dest,src);
|
||||
}
|
||||
|
||||
|
@ -105,17 +105,15 @@ public:
|
|||
template<typename T>
|
||||
static ZT_INLINE void memoryCopy(T &dest,const T &src) noexcept
|
||||
{
|
||||
static_assert(isTriviallyCopyable(dest),"parameter is not TriviallyCopyable");
|
||||
mustBeTriviallyCopyable(dest);
|
||||
Utils::copy<sizeof(T)>(&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<typename T>
|
||||
static constexpr bool isTriviallyCopyable(const T &anything) noexcept { return isTriviallyCopyable(&anything); }
|
||||
|
||||
} // namespace ZeroTier
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue