Controller support for "relays" field.

This commit is contained in:
Adam Ierymenko 2025-07-17 17:04:07 -04:00
parent 055be92ef0
commit 92838fa1b2
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
3 changed files with 28 additions and 14 deletions

View file

@ -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)) {

View file

@ -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>

View file

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