From 39da360725cd5ff4297c504569cf20521beefe74 Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Fri, 22 May 2020 14:16:04 -0700 Subject: [PATCH] add online controller list in Redis --- controller/PostgreSQL.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/controller/PostgreSQL.cpp b/controller/PostgreSQL.cpp index 7e7677ad4..36d6da0a5 100644 --- a/controller/PostgreSQL.cpp +++ b/controller/PostgreSQL.cpp @@ -686,12 +686,13 @@ void PostgreSQL::heartbeat() PQfinish(conn); exit(6); } + int64_t ts = OSUtils::now(); if (conn) { std::string major = std::to_string(ZEROTIER_ONE_VERSION_MAJOR); std::string minor = std::to_string(ZEROTIER_ONE_VERSION_MINOR); std::string rev = std::to_string(ZEROTIER_ONE_VERSION_REVISION); std::string build = std::to_string(ZEROTIER_ONE_VERSION_BUILD); - std::string now = std::to_string(OSUtils::now()); + std::string now = std::to_string(ts); std::string host_port = std::to_string(_listenPort); std::string use_redis = (_rc != NULL) ? "true" : "false"; const char *values[10] = { @@ -726,6 +727,13 @@ void PostgreSQL::heartbeat() } PQclear(res); } + if (_rc != NULL) { + if (_rc->clusterMode) { + _cluster->zadd("controllers", controllerId, ts); + } else { + _redis->zadd("controllers", controllerId, ts); + } + } std::this_thread::sleep_for(std::chrono::milliseconds(1000)); }