|
@@ -37,11 +37,15 @@
|
|
|
|
|
|
#include "../osdep/OSUtils.hpp"
|
|
#include "../osdep/OSUtils.hpp"
|
|
#include "../osdep/Thread.hpp"
|
|
#include "../osdep/Thread.hpp"
|
|
|
|
+#include "../osdep/BlockingQueue.hpp"
|
|
|
|
|
|
#include "../ext/json/json.hpp"
|
|
#include "../ext/json/json.hpp"
|
|
|
|
|
|
#include "JSONDB.hpp"
|
|
#include "JSONDB.hpp"
|
|
|
|
|
|
|
|
+// Number of background threads to start -- not actually started until needed
|
|
|
|
+#define ZT_EMBEDDEDNETWORKCONTROLLER_BACKGROUND_THREAD_COUNT 2
|
|
|
|
+
|
|
namespace ZeroTier {
|
|
namespace ZeroTier {
|
|
|
|
|
|
class Node;
|
|
class Node;
|
|
@@ -52,13 +56,14 @@ public:
|
|
EmbeddedNetworkController(Node *node,const char *dbPath);
|
|
EmbeddedNetworkController(Node *node,const char *dbPath);
|
|
virtual ~EmbeddedNetworkController();
|
|
virtual ~EmbeddedNetworkController();
|
|
|
|
|
|
- virtual NetworkController::ResultCode doNetworkConfigRequest(
|
|
|
|
|
|
+ virtual void init(const Identity &signingId,Sender *sender);
|
|
|
|
+
|
|
|
|
+ virtual void request(
|
|
|
|
+ uint64_t nwid,
|
|
const InetAddress &fromAddr,
|
|
const InetAddress &fromAddr,
|
|
- const Identity &signingId,
|
|
|
|
|
|
+ uint64_t requestPacketId,
|
|
const Identity &identity,
|
|
const Identity &identity,
|
|
- uint64_t nwid,
|
|
|
|
- const Dictionary<ZT_NETWORKCONFIG_METADATA_DICT_CAPACITY> &metaData,
|
|
|
|
- NetworkConfig &nc);
|
|
|
|
|
|
+ const Dictionary<ZT_NETWORKCONFIG_METADATA_DICT_CAPACITY> &metaData);
|
|
|
|
|
|
unsigned int handleControlPlaneHttpGET(
|
|
unsigned int handleControlPlaneHttpGET(
|
|
const std::vector<std::string> &path,
|
|
const std::vector<std::string> &path,
|
|
@@ -82,8 +87,31 @@ public:
|
|
std::string &responseBody,
|
|
std::string &responseBody,
|
|
std::string &responseContentType);
|
|
std::string &responseContentType);
|
|
|
|
|
|
|
|
+ void threadMain()
|
|
|
|
+ throw();
|
|
|
|
+
|
|
private:
|
|
private:
|
|
static void _circuitTestCallback(ZT_Node *node,ZT_CircuitTest *test,const ZT_CircuitTestReport *report);
|
|
static void _circuitTestCallback(ZT_Node *node,ZT_CircuitTest *test,const ZT_CircuitTestReport *report);
|
|
|
|
+ void _request(
|
|
|
|
+ uint64_t nwid,
|
|
|
|
+ const InetAddress &fromAddr,
|
|
|
|
+ uint64_t requestPacketId,
|
|
|
|
+ const Identity &identity,
|
|
|
|
+ const Dictionary<ZT_NETWORKCONFIG_METADATA_DICT_CAPACITY> &metaData);
|
|
|
|
+
|
|
|
|
+ struct _RQEntry
|
|
|
|
+ {
|
|
|
|
+ uint64_t nwid;
|
|
|
|
+ uint64_t requestPacketId;
|
|
|
|
+ InetAddress fromAddr;
|
|
|
|
+ Identity identity;
|
|
|
|
+ Dictionary<ZT_NETWORKCONFIG_METADATA_DICT_CAPACITY> metaData;
|
|
|
|
+ };
|
|
|
|
+ BlockingQueue<_RQEntry *> _queue;
|
|
|
|
+
|
|
|
|
+ Thread _threads[ZT_EMBEDDEDNETWORKCONTROLLER_BACKGROUND_THREAD_COUNT];
|
|
|
|
+ bool _threadsStarted;
|
|
|
|
+ Mutex _threads_m;
|
|
|
|
|
|
// Gathers a bunch of statistics about members of a network, IP assignments, etc. that we need in various places
|
|
// Gathers a bunch of statistics about members of a network, IP assignments, etc. that we need in various places
|
|
// This does lock _networkMemberCache_m
|
|
// This does lock _networkMemberCache_m
|
|
@@ -96,9 +124,14 @@ private:
|
|
unsigned long activeMemberCount;
|
|
unsigned long activeMemberCount;
|
|
unsigned long totalMemberCount;
|
|
unsigned long totalMemberCount;
|
|
uint64_t mostRecentDeauthTime;
|
|
uint64_t mostRecentDeauthTime;
|
|
|
|
+ uint64_t nmiTimestamp; // time this NMI structure was computed
|
|
};
|
|
};
|
|
|
|
+ std::map<uint64_t,_NetworkMemberInfo> _nmiCache;
|
|
|
|
+ Mutex _nmiCache_m;
|
|
void _getNetworkMemberInfo(uint64_t now,uint64_t nwid,_NetworkMemberInfo &nmi);
|
|
void _getNetworkMemberInfo(uint64_t now,uint64_t nwid,_NetworkMemberInfo &nmi);
|
|
|
|
|
|
|
|
+ void _pushMemberUpdate(uint64_t now,uint64_t nwid,const nlohmann::json &member);
|
|
|
|
+
|
|
// These init objects with default and static/informational fields
|
|
// These init objects with default and static/informational fields
|
|
inline void _initMember(nlohmann::json &member)
|
|
inline void _initMember(nlohmann::json &member)
|
|
{
|
|
{
|
|
@@ -112,7 +145,8 @@ private:
|
|
if (!member.count("creationTime")) member["creationTime"] = OSUtils::now();
|
|
if (!member.count("creationTime")) member["creationTime"] = OSUtils::now();
|
|
if (!member.count("noAutoAssignIps")) member["noAutoAssignIps"] = false;
|
|
if (!member.count("noAutoAssignIps")) member["noAutoAssignIps"] = false;
|
|
if (!member.count("revision")) member["revision"] = 0ULL;
|
|
if (!member.count("revision")) member["revision"] = 0ULL;
|
|
- if (!member.count("enableBroadcast")) member["enableBroadcast"] = true;
|
|
|
|
|
|
+ if (!member.count("lastDeauthorizedTime")) member["lastDeauthorizedTime"] = 0ULL;
|
|
|
|
+ if (!member.count("lastAuthorizedTime")) member["lastAuthorizedTime"] = 0ULL;
|
|
member["objtype"] = "member";
|
|
member["objtype"] = "member";
|
|
}
|
|
}
|
|
inline void _initNetwork(nlohmann::json &network)
|
|
inline void _initNetwork(nlohmann::json &network)
|
|
@@ -121,6 +155,7 @@ private:
|
|
if (!network.count("creationTime")) network["creationTime"] = OSUtils::now();
|
|
if (!network.count("creationTime")) network["creationTime"] = OSUtils::now();
|
|
if (!network.count("name")) network["name"] = "";
|
|
if (!network.count("name")) network["name"] = "";
|
|
if (!network.count("multicastLimit")) network["multicastLimit"] = (uint64_t)32;
|
|
if (!network.count("multicastLimit")) network["multicastLimit"] = (uint64_t)32;
|
|
|
|
+ if (!network.count("enableBroadcast")) network["enableBroadcast"] = true;
|
|
if (!network.count("v4AssignMode")) network["v4AssignMode"] = {{"zt",false}};
|
|
if (!network.count("v4AssignMode")) network["v4AssignMode"] = {{"zt",false}};
|
|
if (!network.count("v6AssignMode")) network["v6AssignMode"] = {{"rfc4193",false},{"zt",false},{"6plane",false}};
|
|
if (!network.count("v6AssignMode")) network["v6AssignMode"] = {{"rfc4193",false},{"zt",false},{"6plane",false}};
|
|
if (!network.count("authTokens")) network["authTokens"] = nlohmann::json::array();
|
|
if (!network.count("authTokens")) network["authTokens"] = nlohmann::json::array();
|
|
@@ -154,6 +189,9 @@ private:
|
|
Node *const _node;
|
|
Node *const _node;
|
|
std::string _path;
|
|
std::string _path;
|
|
|
|
|
|
|
|
+ NetworkController::Sender *_sender;
|
|
|
|
+ Identity _signingId;
|
|
|
|
+
|
|
struct _CircuitTestEntry
|
|
struct _CircuitTestEntry
|
|
{
|
|
{
|
|
ZT_CircuitTest *test;
|
|
ZT_CircuitTest *test;
|