From 3cbea6c8986d9fcd296a7b73ed3430e6d6ba497a Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Wed, 2 Mar 2022 11:44:04 -0800 Subject: [PATCH 1/2] make TCP fallback relay address configurable --- service/OneService.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/service/OneService.cpp b/service/OneService.cpp index 73b3a9d56..9553add15 100644 --- a/service/OneService.cpp +++ b/service/OneService.cpp @@ -747,6 +747,7 @@ public: // Time we last received a packet from a global address uint64_t _lastDirectReceiveFromGlobal; #ifdef ZT_TCP_FALLBACK_RELAY + InetAddress _fallbackRelayAddress; uint64_t _lastSendToGlobalV4; #endif @@ -810,6 +811,7 @@ public: ,_udpPortPickerCounter(0) ,_lastDirectReceiveFromGlobal(0) #ifdef ZT_TCP_FALLBACK_RELAY + , _fallbackRelayAddress(ZT_TCP_FALLBACK_RELAY) ,_lastSendToGlobalV4(0) #endif ,_lastRestart(0) @@ -2138,6 +2140,9 @@ div.icon {\ // bondingPolicy cannot be used with allowTcpFallbackRelay _allowTcpFallbackRelay = OSUtils::jsonBool(settings["allowTcpFallbackRelay"],true) && !(_node->bondController()->inUse()); +#ifdef ZT_TCP_FALLBACK_RELAY + _fallbackRelayAddress = InetAddress(OSUtils::jsonString("tcpFallbackRelay", ZT_TCP_FALLBACK_RELAY).c_str()); +#endif _primaryPort = (unsigned int)OSUtils::jsonInt(settings["primaryPort"],(uint64_t)_primaryPort) & 0xffff; _allowSecondaryPort = OSUtils::jsonBool(settings["allowSecondaryPort"],true); _secondaryPort = (unsigned int)OSUtils::jsonInt(settings["secondaryPort"],0); @@ -3149,7 +3154,7 @@ div.icon {\ phyOnTcpWritable(_tcpFallbackTunnel->sock,&tmpptr); } } else if (((now - _lastSendToGlobalV4) < ZT_TCP_FALLBACK_AFTER)&&((now - _lastSendToGlobalV4) > (ZT_PING_CHECK_INVERVAL / 2))) { - const InetAddress addr(ZT_TCP_FALLBACK_RELAY); + const InetAddress addr(_fallbackRelayAddress); TcpConnection *tc = new TcpConnection(); { Mutex::Lock _l(_tcpConnections_m); From ecde26c823b3375368089b4b3aee601457631efc Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Fri, 4 Mar 2022 12:35:11 -0800 Subject: [PATCH 2/2] fix http return value from one service when nework list is empty --- service/OneService.cpp | 47 +++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/service/OneService.cpp b/service/OneService.cpp index 1ae4ace90..dd03814d8 100644 --- a/service/OneService.cpp +++ b/service/OneService.cpp @@ -1577,37 +1577,32 @@ public: } } else if (ps[0] == "network") { Mutex::Lock _l(_nets_m); - if (!_nets.empty()) { - if (ps.size() == 1) { - // Return [array] of all networks + if (ps.size() == 1) { + // Return [array] of all networks - res = nlohmann::json::array(); - - for (auto it = _nets.begin(); it != _nets.end(); ++it) { - NetworkState &ns = it->second; - nlohmann::json nj; - _networkToJson(nj, ns); - res.push_back(nj); - } + res = nlohmann::json::array(); + + for (auto it = _nets.begin(); it != _nets.end(); ++it) { + NetworkState &ns = it->second; + nlohmann::json nj; + _networkToJson(nj, ns); + res.push_back(nj); + } + scode = 200; + } else if (ps.size() == 2) { + // Return a single network by ID or 404 if not found + + const uint64_t wantnw = Utils::hexStrToU64(ps[1].c_str()); + if (_nets.find(wantnw) != _nets.end()) { + res = json::object(); + NetworkState& ns = _nets[wantnw]; + _networkToJson(res, ns); scode = 200; - } else if (ps.size() == 2) { - // Return a single network by ID or 404 if not found - - const uint64_t wantnw = Utils::hexStrToU64(ps[1].c_str()); - if (_nets.find(wantnw) != _nets.end()) { - res = json::object(); - NetworkState& ns = _nets[wantnw]; - _networkToJson(res, ns); - scode = 200; - } - } else { - fprintf(stderr, "not found\n"); - scode = 404; } } else { - fprintf(stderr, "_nets is empty??\n"); - scode = 500; + fprintf(stderr, "not found\n"); + scode = 404; } } else if (ps[0] == "peer") { ZT_PeerList *pl = _node->peers();