support cdn redirection

This commit is contained in:
John
2024-07-08 21:42:27 +02:00
parent b5899fc378
commit 0efcdf10a4
8 changed files with 64 additions and 25 deletions
+1 -1
View File
@@ -742,7 +742,7 @@ void BusHandler::formatUpdateInfo(ostringstream* output) const {
}
unsigned char address = 0;
for (int index = 0; index < 256; index++, address++) {
bool ownAddress = !m_protocol->isOwnAddress(address);
bool ownAddress = m_protocol->isOwnAddress(address);
if (!isValidAddress(address, false) || ((m_seenAddresses[address]&SEEN) == 0 && !ownAddress)) {
continue;
}
+25 -2
View File
@@ -288,8 +288,10 @@ int main(int argc, char* argv[], char* envp[]) {
logWrite(lf_main, ll_error, "invalid configPath URL"); // force logging on exit
return EINVAL;
}
if (configHost == CONFIG_HOST) {
string suffix = (lang != "en" ? "de" : lang) + "/";
bool isCdn = configHost == CONFIG_HOST;
string suffix;
if (isCdn) {
suffix = (lang != "en" ? "de" : lang) + "/";
configUriPrefix += suffix;
configPath += suffix; // only for informational purposes
} else {
@@ -306,6 +308,27 @@ int main(int argc, char* argv[], char* envp[]) {
cleanup();
return EINVAL;
}
if (isCdn) {
// check load balancing redirection
string redirPath;
uint16_t redirPort = 443;
string redirProto, redirHost, redirUriPrefix;
bool repeat = false;
bool json = true;
if (configHttpClient->get("/redirect.json", "", &redirPath, nullptr, nullptr, &json) && !json
&& HttpClient::parseUrl(redirPath, &redirProto, &redirHost, &redirPort, &redirUriPrefix)
&& redirHost != configHost) {
configHttpClient->disconnect();
ebusd::HttpClient* redirClient = new HttpClient();
if (redirClient->connect(redirHost, redirPort, redirProto == "https", PACKAGE_NAME "/" PACKAGE_VERSION)) {
configUriPrefix = redirUriPrefix + suffix;
configPath = redirPath + suffix; // only for informational purposes
delete configHttpClient;
configHttpClient = redirClient;
logNotice(lf_main, "configPath URL redirected to %s", configPath.c_str());
}
}
}
logInfo(lf_main, "configPath URL is valid");
configHttpClient->disconnect();
}
+1 -1
View File
@@ -157,7 +157,7 @@ static const argDef argDefs[] = {
"arguments for checking a particular scan configuration, e.g. \"FF08070400/0AB5454850303003277201\"."},
{"scanretries", O_SCNRET, "COUNT", 0, "Retry scanning devices COUNT times [5]"},
{"configlang", O_CFGLNG, "LANG", 0,
"Prefer LANG in multilingual configuration files [system default language]"},
"Prefer LANG in multilingual configuration files [system default language, DE as fallback]"},
{"checkconfig", O_CHKCFG, nullptr, 0, "Check config files, then stop"},
{"dumpconfig", O_DMPCFG, "FORMAT", af_optional,
"Check and dump config files in FORMAT (\"json\" or \"csv\"), then stop"},
+4
View File
@@ -321,6 +321,10 @@ void MainLoop::run() {
<< ",\"a\":\"other\""
#endif
<< ",\"u\":" << (now-start);
const string configPathCDN = m_scanHelper->getConfigPathCDN();
if (!configPathCDN.empty()) {
ostr << ",\"cp\":\"" << configPathCDN << "\"";
}
m_protocol->formatInfoJson(&ostr);
if (m_reconnectCount) {
ostr << ",\"rc\":" << m_reconnectCount;
+5
View File
@@ -71,6 +71,11 @@ class ScanHelper : public Resolver {
*/
const string getConfigPath() const { return m_configPath; }
/**
* @return the config path when pointing to CDN, empty otherwise.
*/
const string getConfigPathCDN() const { return m_configUriPrefix.empty() ? "" : m_configPath; }
/**
* Try to connect to the specified server.
* @param host the host name to connect to.