Adam Ierymenko 5 years ago
parent
commit
1003455160
3 changed files with 15 additions and 2 deletions
  1. 10 0
      node/Locator.cpp
  2. 2 0
      node/Locator.hpp
  3. 3 2
      node/Node.cpp

+ 10 - 0
node/Locator.cpp

@@ -18,6 +18,16 @@
 
 namespace ZeroTier {
 
+Locator::Locator(const char *const str) noexcept
+{
+	if (!fromString(str)) {
+		m_ts = 0;
+		m_signer.zero();
+		m_endpoints.clear();
+		m_signature.clear();
+	}
+}
+
 bool Locator::add(const Endpoint &ep)
 {
 	if (m_endpoints.size() < ZT_LOCATOR_MAX_ENDPOINTS) {

+ 2 - 0
node/Locator.hpp

@@ -44,6 +44,8 @@ public:
 		m_ts(0)
 	{}
 
+	explicit Locator(const char *const str) noexcept;
+
 	ZT_INLINE Locator(const Locator &loc) noexcept :
 		m_ts(loc.m_ts),
 		m_signer(loc.m_signer),

+ 3 - 2
node/Node.cpp

@@ -124,8 +124,9 @@ Node::Node(void *uPtr, void *tPtr, const struct ZT_Node_Callbacks *callbacks, in
 	for(unsigned int i=0;i<1023;++i)
 		RR->randomPrivilegedPortOrder[i] = (uint16_t)(i + 1);
 	for(unsigned int i=0;i<512;++i) {
-		const unsigned int a = (unsigned int)Utils::random() % 1023;
-		const unsigned int b = (unsigned int)Utils::random() % 1023;
+		uint64_t rn = Utils::random();
+		const unsigned int a = (unsigned int)rn % 1023;
+		const unsigned int b = (unsigned int)(rn >> 32U) % 1023;
 		if (a != b) {
 			const uint16_t tmp = RR->randomPrivilegedPortOrder[a];
 			RR->randomPrivilegedPortOrder[a] = RR->randomPrivilegedPortOrder[b];