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