Browse Source

more test fixes

Adam Ierymenko 5 years ago
parent
commit
4b20638568
4 changed files with 45 additions and 32 deletions
  1. 18 2
      node/Endpoint.cpp
  2. 10 24
      node/Endpoint.hpp
  3. 8 0
      node/Tests.cpp
  4. 9 6
      node/Utils.cpp

+ 18 - 2
node/Endpoint.cpp

@@ -15,7 +15,23 @@
 
 namespace ZeroTier {
 
-bool Endpoint::operator==(const Endpoint &ep) const
+Endpoint::Endpoint(const InetAddress &sa,const Protocol proto) noexcept
+{
+	switch (sa.family()) {
+		case AF_INET:
+			_t = TYPE_INETADDR_V4;
+			break;
+		case AF_INET6:
+			_t = TYPE_INETADDR_V6;
+		default:
+			_t = TYPE_NIL;
+			return;
+	}
+	asInetAddress(_v.in.sa) = sa;
+	_v.in.proto = (uint8_t)proto;
+}
+
+bool Endpoint::operator==(const Endpoint &ep) const noexcept
 {
 	if (_t == ep._t) {
 		switch(_t) {
@@ -31,7 +47,7 @@ bool Endpoint::operator==(const Endpoint &ep) const
 	return false;
 }
 
-bool Endpoint::operator<(const Endpoint &ep) const
+bool Endpoint::operator<(const Endpoint &ep) const noexcept
 {
 	if ((int)_t < (int)ep._t) {
 		return true;

+ 10 - 24
node/Endpoint.hpp

@@ -70,37 +70,23 @@ public:
 
 	ZT_INLINE Endpoint() noexcept { memoryZero(this); }
 
-	ZT_INLINE Endpoint(const InetAddress &sa,const Protocol proto = PROTO_UDP_ZT)
-	{
-		switch (sa.family()) {
-			case AF_INET:
-				_t = TYPE_INETADDR_V4;
-				break;
-			case AF_INET6:
-				_t = TYPE_INETADDR_V6;
-			default:
-				_t = TYPE_NIL;
-				return;
-		}
-		asInetAddress(_v.in.sa) = sa;
-		_v.in.proto = (uint8_t)proto;
-	}
+	explicit Endpoint(const InetAddress &sa,const Protocol proto = PROTO_UDP_ZT) noexcept;
 
-	ZT_INLINE Endpoint(const Address &zt,const uint8_t identityHash[ZT_IDENTITY_HASH_SIZE]) :
+	explicit ZT_INLINE Endpoint(const Address &zt,const uint8_t identityHash[ZT_IDENTITY_HASH_SIZE]) noexcept :
 		_t(TYPE_ZEROTIER)
 	{
 		_v.zt.address = zt.toInt();
 		memcpy(_v.zt.hash,identityHash,ZT_IDENTITY_HASH_SIZE);
 	}
 
-	ZT_INLINE Endpoint(const char *name,const int port) :
+	explicit ZT_INLINE Endpoint(const char *name,const int port) noexcept :
 		_t(TYPE_DNSNAME)
 	{
 		_v.dns.port = port;
 		Utils::scopy(_v.dns.name,sizeof(_v.dns.name),name);
 	}
 
-	explicit ZT_INLINE Endpoint(const char *url) :
+	explicit ZT_INLINE Endpoint(const char *url) noexcept :
 		_t(TYPE_URL)
 	{
 		Utils::scopy(_v.url,sizeof(_v.url),url);
@@ -153,12 +139,12 @@ public:
 
 	ZT_INLINE operator bool() const noexcept { return _t != TYPE_NIL; }
 
-	bool operator==(const Endpoint &ep) const;
-	ZT_INLINE bool operator!=(const Endpoint &ep) const { return (!(*this == ep)); }
-	bool operator<(const Endpoint &ep) const;
-	ZT_INLINE bool operator>(const Endpoint &ep) const { return (ep < *this); }
-	ZT_INLINE bool operator<=(const Endpoint &ep) const { return !(ep < *this); }
-	ZT_INLINE bool operator>=(const Endpoint &ep) const { return !(*this < ep); }
+	bool operator==(const Endpoint &ep) const noexcept;
+	ZT_INLINE bool operator!=(const Endpoint &ep) const noexcept { return (!(*this == ep)); }
+	bool operator<(const Endpoint &ep) const noexcept;
+	ZT_INLINE bool operator>(const Endpoint &ep) const noexcept { return (ep < *this); }
+	ZT_INLINE bool operator<=(const Endpoint &ep) const noexcept { return !(ep < *this); }
+	ZT_INLINE bool operator>=(const Endpoint &ep) const noexcept { return !(*this < ep); }
 
 	static constexpr int marshalSizeMax() noexcept { return ZT_ENDPOINT_MARSHAL_SIZE_MAX; }
 	int marshal(uint8_t data[ZT_ENDPOINT_MARSHAL_SIZE_MAX]) const noexcept;

+ 8 - 0
node/Tests.cpp

@@ -789,6 +789,14 @@ extern "C" const char *ZTT_crypto()
 				ZT_T_PRINTF("FAILED (%.16llx)" ZT_EOL_S,proof);
 				return "MIMC52 failed simple delay/verify test";
 			}
+			for(int i=0;i<1024;++i) {
+				uint64_t in = Utils::random();
+				unsigned long r = 1 + (unsigned long)(Utils::random() % 1024);
+				if (!mimc52Verify(&in,sizeof(in),r,mimc52Delay(&in,sizeof(in),r))) {
+					ZT_T_PRINTF("FAILED (random input test)");
+					return "MIMC52 failed random input test";
+				}
+			}
 			ZT_T_PRINTF("OK (%.16llx)" ZT_EOL_S,proof);
 		}
 

+ 9 - 6
node/Utils.cpp

@@ -439,7 +439,7 @@ uint64_t random() noexcept
 	return result;
 }
 
-bool scopy(char *dest,unsigned int len,const char *src) noexcept
+bool scopy(char *const dest,const unsigned int len,const char *const src) noexcept
 {
 	if (!len)
 		return false; // sanity check
@@ -447,14 +447,17 @@ bool scopy(char *dest,unsigned int len,const char *src) noexcept
 		*dest = (char)0;
 		return true;
 	}
-	char *const end = dest + len;
-	while ((*dest++ = *src++)) {
-		if (dest == end) {
-			*(--dest) = (char)0;
+	unsigned int i = 0;
+	for(;;) {
+		if (i >= len) {
+			dest[len - 1] = 0;
 			return false;
 		}
+		const char c = src[i];
+		dest[i] = c;
+		if (c == 0)
+			return true;
 	}
-	return true;
 }
 
 } // namespace Utils