mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-10-10 15:25:06 +02:00
query fix for new networks
This commit is contained in:
parent
e51e516f85
commit
c6b7c263d2
2 changed files with 13 additions and 5 deletions
|
@ -1303,21 +1303,29 @@ void CentralDB::commitThread()
|
||||||
std::string id = config["id"];
|
std::string id = config["id"];
|
||||||
|
|
||||||
pqxx::row nwrow =
|
pqxx::row nwrow =
|
||||||
w.exec(
|
w.exec("SELECT COUNT(id) frontend FROM networks_ctl WHERE id = $1", pqxx::params { id })
|
||||||
"SELECT COUNT(id), frontend FROM networks_ctl WHERE id = $1 GROUP BY frontend",
|
|
||||||
pqxx::params { id })
|
|
||||||
.one_row();
|
.one_row();
|
||||||
int nwcount = nwrow[0].as<int>();
|
int nwcount = nwrow[0].as<int>();
|
||||||
std::string frontend = nwrow[1].as<std::string>();
|
|
||||||
bool isNewNetwork = (nwcount == 0);
|
bool isNewNetwork = (nwcount == 0);
|
||||||
|
std::string frontend = "";
|
||||||
|
|
||||||
|
if (! isNewNetwork) {
|
||||||
|
pqxx::row nwrow =
|
||||||
|
w.exec("SELECT frontend FROM networks_ctl WHERE id = $1", pqxx::params { id }).one_row();
|
||||||
|
frontend = nwrow[0].as<std::string>();
|
||||||
|
}
|
||||||
|
|
||||||
std::string change_source;
|
std::string change_source;
|
||||||
if (! config["change_source"].is_null()) {
|
if (! config["change_source"].is_null()) {
|
||||||
change_source = config["change_source"];
|
change_source = config["change_source"];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! isNewNetwork && change_source != "controller" && frontend != change_source) {
|
if (! isNewNetwork && change_source != "controller" && frontend != change_source) {
|
||||||
// if it is not a new network and the change source is not the controller and doesn't match the
|
// if it is not a new network and the change source is not the controller and doesn't match the
|
||||||
// frontend, don't apply the change.
|
// frontend, don't apply the change.
|
||||||
|
fprintf(
|
||||||
|
stderr, "Skipping network update %s. isNewNetwork: %s, change_source: %s, frontend: %s\n",
|
||||||
|
id.c_str(), isNewNetwork ? "true" : "false", change_source.c_str(), frontend.c_str());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -134,7 +134,7 @@ void PubSubNetworkListener::onNotification(const std::string& payload)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Network notification received");
|
fprintf(stderr, "Network notification received\n");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
nlohmann::json oldConfig, newConfig;
|
nlohmann::json oldConfig, newConfig;
|
||||||
|
|
Loading…
Add table
Reference in a new issue