Преглед на файлове

wire up configuration.

New config block in local.conf for controllers:

```
{
  "settings": {
    ...standard zt1 local.conf settings...
  },
  "controller": {
    "listenMode": (pgsql|redis|pubsub),
    "statusMode": (pgsql|redis|bigtable),
    "redis": {
      "hostname": ...,
      "port": 6379,
      "clusterMode": true
    },
    "pubsub": {
      "project_id": <gcp-project-id>
    },
    "bigtable": {
      "project_id": <gcp-project-id>,
      "instance_id": <bigtable-instance-id>,
      "table_id": <bigtable-table-id>
    }
  }
}
```
Grant Limberg преди 1 седмица
родител
ревизия
0753556aa3
променени са 3 файла, в които са добавени 57 реда и са изтрити 13 реда
  1. 2 2
      nonfree/controller/CentralDB.cpp
  2. 1 11
      nonfree/controller/ControllerConfig.hpp
  3. 54 0
      service/OneService.cpp

+ 2 - 2
nonfree/controller/CentralDB.cpp

@@ -184,9 +184,9 @@ CentralDB::CentralDB(
 		case LISTENER_MODE_PUBSUB:
 			if (cc->pubSubConfig != NULL) {
 				_membersDbWatcher =
-					std::make_shared<PubSubMemberListener>(_myAddressStr, cc->pubSubConfig->project, this);
+					std::make_shared<PubSubMemberListener>(_myAddressStr, cc->pubSubConfig->project_id, this);
 				_networksDbWatcher =
-					std::make_shared<PubSubNetworkListener>(_myAddressStr, cc->pubSubConfig->project, this);
+					std::make_shared<PubSubNetworkListener>(_myAddressStr, cc->pubSubConfig->project_id, this);
 			}
 			else {
 				throw std::runtime_error(

+ 1 - 11
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;

+ 54 - 0
service/OneService.cpp

@@ -1790,6 +1790,60 @@ class OneServiceImpl : public OneService {
 				_node->setPhysicalPathConfiguration(
 					reinterpret_cast<const struct sockaddr_storage*>(&(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