[grade=B urn:ump:w4iifvsmrrra4o25btcpohxwhzvhulh3e22yjeplzw6ms2id33ja] fix(i2p): override SOCKS+SAM ports via SetOption — libi2pd API never reads i2pd.conf
This commit is contained in:
@@ -415,8 +415,13 @@ bool CI2PEmbedded::Start(int socks, int sam, int server)
|
||||
printf("Embedded I2P: starting i2pd router...\n");
|
||||
|
||||
// Write an i2pd.conf configuration file that enables SAM + SOCKS proxy.
|
||||
// i2pd's config system reads from a file; programmatic option setting is
|
||||
// fragile across i2pd versions. Writing a minimal conf is robust.
|
||||
// NOTE: As of i2pd 2.60.0, the embedded library API (i2p::api::InitI2P)
|
||||
// never calls ParseConfig, so this file is NOT read at runtime. It is
|
||||
// written for documentation/debugging purposes only — operators can
|
||||
// inspect it to see what ports the daemon intends to use. The actual
|
||||
// port bindings are applied programmatically via i2p::config::SetOption
|
||||
// below (before the background thread starts). Keep the file in sync
|
||||
// with the SetOption calls.
|
||||
{
|
||||
fs::path confPath = fs::path(i2pDataDir) / "i2pd.conf";
|
||||
std::ofstream conf(confPath.string());
|
||||
@@ -425,6 +430,8 @@ bool CI2PEmbedded::Start(int socks, int sam, int server)
|
||||
return false;
|
||||
}
|
||||
conf << "# Auto-generated by Triangles embedded I2P\n";
|
||||
conf << "# NOTE: i2pd 2.60.0 library API does NOT read this file.\n";
|
||||
conf << "# Actual port bindings come from i2p::config::SetOption in i2p_embedded.cpp.\n";
|
||||
conf << "datadir = " << i2pDataDir << "\n";
|
||||
conf << "loglevel = info\n";
|
||||
conf << "\n";
|
||||
@@ -524,6 +531,61 @@ bool CI2PEmbedded::Start(int socks, int sam, int server)
|
||||
printf("Embedded I2P: launching router in background thread...\n");
|
||||
fflush(stdout);
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// PROGRAMMATIC OVERRIDE OF SOCKS/SAM PORTS
|
||||
//
|
||||
// i2pd 2.60.0's library API (i2p::api::InitI2P) only calls ParseCmdline
|
||||
// — it never calls ParseConfig. The i2pd.conf file we just wrote is
|
||||
// NEVER READ by the embedded library path. SOCKS proxy falls back to
|
||||
// its built-in default port (4447) regardless of what we put in the
|
||||
// conf file. This is verified by the library's bundled ParseConfig
|
||||
// (called only by the standalone daemon binary at
|
||||
// src/i2p/i2pd-src/daemon/Daemon.cpp:107) — the library API
|
||||
// deliberately omits it.
|
||||
//
|
||||
// The fix: override socksproxy.port + sam.port + socksproxy.address
|
||||
// AFTER i2p::api::InitI2P returns (so all defaults are in m_Options)
|
||||
// but BEFORE the background thread calls i2p::client::context.Start
|
||||
// which calls ReadSocksProxy + ReadSAMBridge. SetOption calls
|
||||
// notify() internally, so the new values are visible to GetOption.
|
||||
// ----------------------------------------------------------------
|
||||
if (socksPort < 1 || socksPort > 65535) {
|
||||
lastError = strprintf("SOCKS proxy port %d out of range (1-65535)",
|
||||
socksPort);
|
||||
return false;
|
||||
}
|
||||
if (samPort < 1 || samPort > 65535) {
|
||||
lastError = strprintf("SAM bridge port %d out of range (1-65535)",
|
||||
samPort);
|
||||
return false;
|
||||
}
|
||||
printf("Embedded I2P: overriding socksproxy.port=%d sam.port=%d via SetOption\n",
|
||||
socksPort, samPort);
|
||||
fflush(stdout);
|
||||
{
|
||||
bool socksEnabled = true;
|
||||
std::string socksAddr = "127.0.0.1";
|
||||
uint16_t socksPortVal = (uint16_t)socksPort;
|
||||
std::string socksKeys = "socks-proxy.dat";
|
||||
bool samEnabled = true;
|
||||
std::string samAddr = "127.0.0.1";
|
||||
uint16_t samPortVal = (uint16_t)samPort;
|
||||
bool httpEnabled = false;
|
||||
bool i2pcontrolEnabled = false;
|
||||
bool bobEnabled = false;
|
||||
|
||||
i2p::config::SetOption("socksproxy.enabled", socksEnabled);
|
||||
i2p::config::SetOption("socksproxy.address", socksAddr);
|
||||
i2p::config::SetOption("socksproxy.port", socksPortVal);
|
||||
i2p::config::SetOption("socksproxy.keys", socksKeys);
|
||||
i2p::config::SetOption("sam.enabled", samEnabled);
|
||||
i2p::config::SetOption("sam.address", samAddr);
|
||||
i2p::config::SetOption("sam.port", samPortVal);
|
||||
i2p::config::SetOption("http.enabled", httpEnabled);
|
||||
i2p::config::SetOption("i2pcontrol.enabled", i2pcontrolEnabled);
|
||||
i2p::config::SetOption("bob.enabled", bobEnabled);
|
||||
}
|
||||
|
||||
// Keep the thread handle so Stop() can join it. A detached thread
|
||||
// that is still running would block the wallet from exiting.
|
||||
routerThread = std::thread([this]() {
|
||||
|
||||
Reference in New Issue
Block a user