RPC info: detect public IP without the proxy

getPublicIpAddress() ran the ipify/checkip/icanhazip/ifconfig probes through
the shared proxied NetworkClient. That was wrong twice over: it returned the
proxy's exit IP instead of the bot's reachable address (so the Desktop could
not use it), and every probe died on the proxy CONNECT, hanging the !rpc
command ~30s while it retried all four services. Always use a fresh, un-proxied
client for public-IP detection.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 4.8 committed 2026-06-25 02:13:06 +03:00
1 parent 1f26927ad6
commit 7e3081ecd1
1 file changed
+12 -15
+12 -15
View File
@@ -9,7 +9,7 @@
namespace Echoion::Core
{
std::string getPublicIpAddress(Api::INetworkClient* shared)
std::string getPublicIpAddress()
{
// Try to get public IP from external services
static std::string cachedIp;
@@ -28,17 +28,15 @@ namespace Echoion::Core
"https://api.ipify.org", "https://checkip.amazonaws.com",
"https://icanhazip.com", "https://ifconfig.me/ip"};
// Prefer the shared, already-initialized network client resolved from
// the service registry; only spin up a throwaway one as a fallback.
std::shared_ptr<NetworkClient> owned;
Api::INetworkClient* networkClient = shared;
if (!networkClient) {
owned = std::make_shared<NetworkClient>();
if (!owned->initialize()) {
return cachedIp.empty() ? "127.0.0.1" : cachedIp;
}
networkClient = owned.get();
// Public-IP detection must NOT go through the proxy: the Desktop needs
// the bot's own reachable address, not the proxy's exit IP, and routing
// these probes through the proxy is what made them fail (and hang the
// command retrying). Always use a fresh, un-proxied client.
auto owned = std::make_shared<NetworkClient>();
if (!owned->initialize()) {
return cachedIp.empty() ? "127.0.0.1" : cachedIp;
}
NetworkClient* networkClient = owned.get();
for (const auto& service : ipServices) {
try {
@@ -84,10 +82,9 @@ namespace Echoion::Core
uint16_t rpcPort = networkConfig.rpcPort;
std::string rpcBindAddress = networkConfig.rpcBindAddress;
// Determine the public IP to show, reusing the shared network client
// from the registry when available.
auto sharedNet = ctx.service<Api::INetworkClient>();
std::string publicIp = getPublicIpAddress(sharedNet.get());
// Determine the public IP to show. This deliberately bypasses the proxy
// (see getPublicIpAddress) so it reports the bot's reachable address.
std::string publicIp = getPublicIpAddress();
// If bind address is not localhost, use it
if (rpcBindAddress != "127.0.0.1" && rpcBindAddress != "localhost") {