瀏覽代碼

Controller support for "relays" field.

Adam Ierymenko 1 月之前
父節點
當前提交
92838fa1b2
共有 3 個文件被更改,包括 28 次插入14 次删除
  1. 28 5
      controller/EmbeddedNetworkController.cpp
  2. 0 7
      controller/EmbeddedNetworkController.hpp
  3. 0 2
      node/Address.hpp

+ 28 - 5
controller/EmbeddedNetworkController.cpp

@@ -16,24 +16,20 @@
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
-#include <type_traits>
 
 #ifndef _WIN32
 #include <sys/time.h>
 #endif
 #include "../include/ZeroTierOne.h"
-#include "../version.h"
 #include "EmbeddedNetworkController.hpp"
 #include "FileDB.hpp"
 #include "LFDB.hpp"
 
 #include <algorithm>
 #include <cctype>
-#include <iomanip>
 #include <map>
 #include <memory>
 #include <sstream>
-#include <stdexcept>
 #include <sys/types.h>
 #include <thread>
 #include <utility>
@@ -44,7 +40,6 @@
 
 #include "../node/CertificateOfMembership.hpp"
 #include "../node/Dictionary.hpp"
-#include "../node/MAC.hpp"
 #include "../node/NetworkConfig.hpp"
 #include "../node/Node.hpp"
 
@@ -754,6 +749,24 @@ std::string EmbeddedNetworkController::networkUpdateFromPostData(uint64_t networ
 		network["v6AssignMode"] = nv6m;
 	}
 
+	if (b.count("relays")) {
+		json nrelays = json::array();
+		char rtmp[64];
+		json& relays = b["relays"];
+		if (relays.is_array()) {
+			for (unsigned long i = 0; i < relays.size(); ++i) {
+				json& relay = relays[i];
+				if (relay.is_string()) {
+					nrelays.push_back(Address(Utils::hexStrToU64(OSUtils::jsonString(relay, "0").c_str()) & 0xffffffffffULL).toString(rtmp));
+				}
+			}
+		}
+		if (nrelays.size() > 0)
+			network["relays"] = nrelays;
+		else
+			network.erase("relays");
+	}
+
 	if (b.count("routes")) {
 		json& rts = b["routes"];
 		if (rts.is_array()) {
@@ -1815,6 +1828,7 @@ void EmbeddedNetworkController::_request(uint64_t nwid, const InetAddress& fromA
 	json& v6AssignMode = network["v6AssignMode"];
 	json& ipAssignmentPools = network["ipAssignmentPools"];
 	json& routes = network["routes"];
+	json& relays = network["relays"];
 	json& rules = network["rules"];
 	json& capabilities = network["capabilities"];
 	json& tags = network["tags"];
@@ -1946,6 +1960,15 @@ void EmbeddedNetworkController::_request(uint64_t nwid, const InetAddress& fromA
 		}
 	}
 
+	if (relays.is_array()) {
+		for (unsigned long i = 0; i < relays.size(); ++i) {
+			Address relay(Address(Utils::hexStrToU64(OSUtils::jsonString(relays[i], "0").c_str()) & 0xffffffffffULL));
+			if (! relay.isReserved()) {
+				nc->addSpecialist(relay, ZT_NETWORKCONFIG_SPECIALIST_TYPE_NETWORK_RELAY);
+			}
+		}
+	}
+
 	const bool noAutoAssignIps = OSUtils::jsonBool(member["noAutoAssignIps"], false);
 
 	if ((v6AssignMode.is_object()) && (! noAutoAssignIps)) {

+ 0 - 7
controller/EmbeddedNetworkController.hpp

@@ -14,21 +14,14 @@
 #ifndef ZT_SQLITENETWORKCONTROLLER_HPP
 #define ZT_SQLITENETWORKCONTROLLER_HPP
 
-#include "../node/Address.hpp"
 #include "../node/Constants.hpp"
 #include "../node/InetAddress.hpp"
 #include "../node/NetworkController.hpp"
-#include "../node/Utils.hpp"
 #include "../osdep/BlockingQueue.hpp"
-#include "../osdep/OSUtils.hpp"
-#include "../osdep/Thread.hpp"
 #include "DB.hpp"
 #include "DBMirrorSet.hpp"
 
-#include <atomic>
 #include <cpp-httplib/httplib.h>
-#include <list>
-#include <map>
 #include <nlohmann/json.hpp>
 #include <set>
 #include <stdint.h>

+ 0 - 2
node/Address.hpp

@@ -21,8 +21,6 @@
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
-#include <string>
 
 namespace ZeroTier {