diff --git a/libi2pd/Config.cpp b/libi2pd/Config.cpp index 9eaaf068..3a3d6c09 100644 --- a/libi2pd/Config.cpp +++ b/libi2pd/Config.cpp @@ -34,6 +34,7 @@ namespace config { ("help", "Show this message") ("conf", value()->default_value(""), "Path to main i2pd config file (default: try ~/.i2pd/i2pd.conf or /var/lib/i2pd/i2pd.conf)") ("tunconf", value()->default_value(""), "Path to config with tunnels list and options (default: try ~/.i2pd/tunnels.conf or /var/lib/i2pd/tunnels.conf)") + ("tunnelsdir", value()->default_value(""), "Path to extra tunnels' configs folder (default: ~/.i2pd/tunnels.d or /var/lib/i2pd/tunnels.d") ("pidfile", value()->default_value(""), "Path to pidfile (default: ~/i2pd/i2pd.pid or /var/lib/i2pd/i2pd.pid)") ("log", value()->default_value(""), "Logs destination: stdout, file, syslog (stdout if not set)") ("logfile", value()->default_value(""), "Path to logfile (stdout if not set, autodetect if daemon)") diff --git a/libi2pd_client/ClientContext.cpp b/libi2pd_client/ClientContext.cpp index b58677c8..257087ee 100644 --- a/libi2pd_client/ClientContext.cpp +++ b/libi2pd_client/ClientContext.cpp @@ -410,18 +410,44 @@ namespace client void ClientContext::ReadTunnels () { - boost::property_tree::ptree pt; + int numClientTunnels = 0, numServerTunnels = 0; std::string tunConf; i2p::config::GetOption("tunconf", tunConf); - if (tunConf == "") { + if (tunConf.empty ()) + { // TODO: cleanup this in 2.8.0 tunConf = i2p::fs::DataDirPath ("tunnels.cfg"); - if (i2p::fs::Exists(tunConf)) { - LogPrint(eLogWarning, "FS: please rename tunnels.cfg -> tunnels.conf here: ", tunConf); - } else { + if (i2p::fs::Exists(tunConf)) + LogPrint(eLogWarning, "Clients: please rename tunnels.cfg -> tunnels.conf here: ", tunConf); + else tunConf = i2p::fs::DataDirPath ("tunnels.conf"); + } + LogPrint(eLogDebug, "Clients: tunnels config file: ", tunConf); + ReadTunnels (tunConf, numClientTunnels, numServerTunnels); + + std::string tunDir; i2p::config::GetOption("tunnelsdir", tunDir); + if (tunDir.empty ()) + tunDir = i2p::fs::DataDirPath ("tunnels.d"); + if (i2p::fs::Exists (tunDir)) + { + std::vector files; + if (i2p::fs::ReadDir (tunDir, files)) + { + for (auto& it: files) + { + LogPrint(eLogDebug, "Clients: tunnels extra config file: ", it); + ReadTunnels (it, numClientTunnels, numServerTunnels); + } } } - LogPrint(eLogDebug, "FS: tunnels config file: ", tunConf); + + LogPrint (eLogInfo, "Clients: ", numClientTunnels, " I2P client tunnels created"); + LogPrint (eLogInfo, "Clients: ", numServerTunnels, " I2P server tunnels created"); + } + + + void ClientContext::ReadTunnels (const std::string& tunConf, int& numClientTunnels, int& numServerTunnels) + { + boost::property_tree::ptree pt; try { boost::property_tree::read_ini (tunConf, pt); @@ -432,7 +458,6 @@ namespace client return; } - int numClientTunnels = 0, numServerTunnels = 0; for (auto& section: pt) { std::string name = section.first; @@ -672,8 +697,6 @@ namespace client LogPrint (eLogError, "Clients: Can't read tunnel ", name, " params: ", ex.what ()); } } - LogPrint (eLogInfo, "Clients: ", numClientTunnels, " I2P client tunnels created"); - LogPrint (eLogInfo, "Clients: ", numServerTunnels, " I2P server tunnels created"); } void ClientContext::ReadHttpProxy () diff --git a/libi2pd_client/ClientContext.h b/libi2pd_client/ClientContext.h index 06aab3b1..a0c92045 100644 --- a/libi2pd_client/ClientContext.h +++ b/libi2pd_client/ClientContext.h @@ -87,6 +87,7 @@ namespace client private: void ReadTunnels (); + void ReadTunnels (const std::string& tunConf, int& numClientTunnels, int& numServerTunnels); void ReadHttpProxy (); void ReadSocksProxy (); template