diff --git a/nonfree/controller/CentralDB.cpp b/nonfree/controller/CentralDB.cpp index f42f50414..c102dab28 100644 --- a/nonfree/controller/CentralDB.cpp +++ b/nonfree/controller/CentralDB.cpp @@ -184,9 +184,9 @@ CentralDB::CentralDB( case LISTENER_MODE_PUBSUB: if (cc->pubSubConfig != NULL) { _membersDbWatcher = - std::make_shared(_myAddressStr, cc->pubSubConfig->project, this); + std::make_shared(_myAddressStr, cc->pubSubConfig->project_id, this); _networksDbWatcher = - std::make_shared(_myAddressStr, cc->pubSubConfig->project, this); + std::make_shared(_myAddressStr, cc->pubSubConfig->project_id, this); } else { throw std::runtime_error( diff --git a/nonfree/controller/ControllerConfig.hpp b/nonfree/controller/ControllerConfig.hpp index 3ee3c8ea5..b082b793b 100644 --- a/nonfree/controller/ControllerConfig.hpp +++ b/nonfree/controller/ControllerConfig.hpp @@ -8,11 +8,7 @@ namespace ZeroTier { struct PubSubConfig { - std::string project; -}; - -struct PostgresNotifyConfig { - std::string channel; + std::string project_id; }; struct BigTableConfig { @@ -27,7 +23,6 @@ struct ControllerConfig { std::string statusMode; RedisConfig* redisConfig; PubSubConfig* pubSubConfig; - PostgresNotifyConfig* postgresNotifyConfig; BigTableConfig* bigTableConfig; ControllerConfig() @@ -36,7 +31,6 @@ struct ControllerConfig { , statusMode("") , redisConfig(nullptr) , pubSubConfig(nullptr) - , postgresNotifyConfig(nullptr) , bigTableConfig(nullptr) { } @@ -51,10 +45,6 @@ struct ControllerConfig { delete pubSubConfig; pubSubConfig = nullptr; } - if (postgresNotifyConfig) { - delete postgresNotifyConfig; - postgresNotifyConfig = nullptr; - } if (bigTableConfig) { delete bigTableConfig; bigTableConfig = nullptr; diff --git a/service/OneService.cpp b/service/OneService.cpp index 8ebc85589..3a5911138 100644 --- a/service/OneService.cpp +++ b/service/OneService.cpp @@ -1790,6 +1790,60 @@ class OneServiceImpl : public OneService { _node->setPhysicalPathConfiguration( reinterpret_cast(&(i->first)), &(i->second)); } + +#ifdef ZT1_CENTRAL_CONTROLLER + // Central Controller Mode Settings + json& cc = lc["controller"]; + if (cc.is_object()) { + _controllerConfig.listenMode = OSUtils::jsonString(cc["listenMode"], "pgsql"); + _controllerConfig.statusMode = OSUtils::jsonString(cc["statusMode"], "pgsql"); + + // redis settings + if (cc["redis"].is_object() && _rc == NULL) { + json& redis = cc["redis"]; + _rc = new RedisConfig; + _rc->hostname = OSUtils::jsonString(redis["hostname"], ""); + _rc->port = OSUtils::jsonInt(redis["port"], 6379); + _rc->password = OSUtils::jsonString(redis["password"], ""); + _rc->clusterMode = OSUtils::jsonBool(redis["clusterMode"], false); + _controllerConfig.redisConfig = _rc; + } + else if (cc["redis"].is_object() && _rc != NULL) { + _controllerConfig.redisConfig = _rc; + } + if ((_controllerConfig.listenMode == "redis" || _controllerConfig.statusMode == "redis") + && ! _controllerConfig.redisConfig) { + fprintf( + stderr, + "ERROR: redis listenMode or statusMode requires redis configuration in local.conf" ZT_EOL_S); + exit(1); + } + + // pubsub settings + if (cc["pubsub"].is_object()) { + json& ps = cc["pubsub"]; + _controllerConfig.pubSubConfig = new PubSubConfig(); + _controllerConfig.pubSubConfig->project_id = OSUtils::jsonString(ps["project_id"], ""); + } + if (_controllerConfig.listenMode == "pubsub" && ! _controllerConfig.pubSubConfig) { + fprintf(stderr, "ERROR: pubsub listenMode requires pubsub configuration in local.conf" ZT_EOL_S); + exit(1); + } + + // bigtable settings + if (cc["bigtable"].is_object()) { + json& bt = cc["bigtable"]; + _controllerConfig.bigTableConfig = new BigTableConfig(); + _controllerConfig.bigTableConfig->project_id = OSUtils::jsonString(bt["project_id"], ""); + _controllerConfig.bigTableConfig->instance_id = OSUtils::jsonString(bt["instance_id"], ""); + _controllerConfig.bigTableConfig->table_id = OSUtils::jsonString(bt["table_id"], ""); + } + if (_controllerConfig.listenMode == "bigtable" && ! _controllerConfig.bigTableConfig) { + fprintf(stderr, "ERROR: bigtable listenMode requires bigtable configuration in local.conf" ZT_EOL_S); + exit(1); + } + } +#endif } virtual ReasonForTermination reasonForTermination() const