Skip to content

Commit

Permalink
fixed #1259. read extra tunnels from tunnels.d
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Oct 19, 2018
1 parent 15ded89 commit 9439621
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
1 change: 1 addition & 0 deletions libi2pd/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace config {
("help", "Show this message")
("conf", value<std::string>()->default_value(""), "Path to main i2pd config file (default: try ~/.i2pd/i2pd.conf or /var/lib/i2pd/i2pd.conf)")
("tunconf", value<std::string>()->default_value(""), "Path to config with tunnels list and options (default: try ~/.i2pd/tunnels.conf or /var/lib/i2pd/tunnels.conf)")
("tunnelsdir", value<std::string>()->default_value(""), "Path to extra tunnels' configs folder (default: ~/.i2pd/tunnels.d or /var/lib/i2pd/tunnels.d")
("pidfile", value<std::string>()->default_value(""), "Path to pidfile (default: ~/i2pd/i2pd.pid or /var/lib/i2pd/i2pd.pid)")
("log", value<std::string>()->default_value(""), "Logs destination: stdout, file, syslog (stdout if not set)")
("logfile", value<std::string>()->default_value(""), "Path to logfile (stdout if not set, autodetect if daemon)")
Expand Down
41 changes: 32 additions & 9 deletions libi2pd_client/ClientContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> 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);
Expand All @@ -432,7 +458,6 @@ namespace client
return;
}

int numClientTunnels = 0, numServerTunnels = 0;
for (auto& section: pt)
{
std::string name = section.first;
Expand Down Expand Up @@ -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 ()
Expand Down
1 change: 1 addition & 0 deletions libi2pd_client/ClientContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ namespace client
private:

void ReadTunnels ();
void ReadTunnels (const std::string& tunConf, int& numClientTunnels, int& numServerTunnels);
void ReadHttpProxy ();
void ReadSocksProxy ();
template<typename Section, typename Type>
Expand Down

0 comments on commit 9439621

Please sign in to comment.