Browse Source

* migrate to new settings

pull/358/head
hagen 9 years ago
parent
commit
2335d3879e
  1. 49
      ClientContext.cpp
  2. 6
      Config.h
  3. 68
      Daemon.cpp
  4. 6
      DaemonLinux.cpp
  5. 3
      DaemonWin32.cpp
  6. 8
      RouterContext.cpp
  7. 5
      api.cpp
  8. 19
      util.cpp

49
ClientContext.cpp

@ -2,6 +2,7 @@
#include <iostream> #include <iostream>
#include <boost/property_tree/ptree.hpp> #include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp> #include <boost/property_tree/ini_parser.hpp>
#include "Config.h"
#include "util.h" #include "util.h"
#include "Log.h" #include "Log.h"
#include "Identity.h" #include "Identity.h"
@ -37,44 +38,56 @@ namespace client
} }
std::shared_ptr<ClientDestination> localDestination; std::shared_ptr<ClientDestination> localDestination;
// proxies bool httproxy; i2p::config::GetOption("httpproxy.enabled", httproxy);
std::string proxyKeys = i2p::util::config::GetArg("-proxykeys", ""); if (httproxy) {
if (proxyKeys.length () > 0) std::string httpProxyKeys; i2p::config::GetOption("httpproxy.keys", httpProxyKeys);
std::string httpProxyAddr; i2p::config::GetOption("httpproxy.address", httpProxyAddr);
uint16_t httpProxyPort; i2p::config::GetOption("httpproxy.port", httpProxyPort);
LogPrint(eLogInfo, "Clients: starting HTTP Proxy at ", httpProxyAddr, ":", httpProxyPort);
if (httpProxyKeys.length () > 0)
{ {
i2p::data::PrivateKeys keys; i2p::data::PrivateKeys keys;
LoadPrivateKeys (keys, proxyKeys); LoadPrivateKeys (keys, httpProxyKeys);
localDestination = CreateNewLocalDestination (keys, false); localDestination = CreateNewLocalDestination (keys, false);
} }
std::string httpProxyAddr = i2p::util::config::GetArg("-httpproxyaddress", "127.0.0.1");
uint16_t httpProxyPort = i2p::util::config::GetArg("-httpproxyport", 4446);
LogPrint(eLogInfo, "Clients: starting HTTP Proxy at ", httpProxyAddr, ":", httpProxyPort);
m_HttpProxy = new i2p::proxy::HTTPProxy(httpProxyAddr, httpProxyPort, localDestination); m_HttpProxy = new i2p::proxy::HTTPProxy(httpProxyAddr, httpProxyPort, localDestination);
m_HttpProxy->Start(); m_HttpProxy->Start();
}
std::string socksProxyAddr = i2p::util::config::GetArg("-socksproxyaddress", "127.0.0.1"); bool socksproxy; i2p::config::GetOption("socksproxy.enabled", socksproxy);
uint16_t socksProxyPort = i2p::util::config::GetArg("-socksproxyport", 4447); if (socksproxy) {
std::string socksProxyKeys; i2p::config::GetOption("socksproxy.keys", socksProxyKeys);
std::string socksProxyAddr; i2p::config::GetOption("socksproxy.address", socksProxyAddr);
uint16_t socksProxyPort; i2p::config::GetOption("socksproxy.port", socksProxyPort);
LogPrint(eLogInfo, "Clients: starting SOCKS Proxy at ", socksProxyAddr, ":", socksProxyPort); LogPrint(eLogInfo, "Clients: starting SOCKS Proxy at ", socksProxyAddr, ":", socksProxyPort);
if (socksProxyKeys.length () > 0)
{
i2p::data::PrivateKeys keys;
LoadPrivateKeys (keys, socksProxyKeys);
localDestination = CreateNewLocalDestination (keys, false);
}
m_SocksProxy = new i2p::proxy::SOCKSProxy(socksProxyAddr, socksProxyPort, localDestination); m_SocksProxy = new i2p::proxy::SOCKSProxy(socksProxyAddr, socksProxyPort, localDestination);
m_SocksProxy->Start(); m_SocksProxy->Start();
}
// I2P tunnels // I2P tunnels
ReadTunnels (); ReadTunnels ();
// SAM // SAM
std::string samAddr = i2p::util::config::GetArg("-samaddress", "127.0.0.1"); bool sam; i2p::config::GetOption("sam.enabled", sam);
uint16_t samPort = i2p::util::config::GetArg("-samport", 0); if (sam) {
if (samPort) std::string samAddr; i2p::config::GetOption("sam.address", samAddr);
{ uint16_t samPort; i2p::config::GetOption("sam.port", samPort);
LogPrint(eLogInfo, "Clients: starting SAM bridge at", samAddr, ":", samPort); LogPrint(eLogInfo, "Clients: starting SAM bridge at ", samAddr, ":", samPort);
m_SamBridge = new SAMBridge (samAddr, samPort); m_SamBridge = new SAMBridge (samAddr, samPort);
m_SamBridge->Start (); m_SamBridge->Start ();
} }
// BOB // BOB
std::string bobAddr = i2p::util::config::GetArg("-bobaddress", "127.0.0.1"); bool bob; i2p::config::GetOption("bob.enabled", bob);
uint16_t bobPort = i2p::util::config::GetArg("-bobport", 0); if (bob) {
if (bobPort) std::string bobAddr; i2p::config::GetOption("bob.address", bobAddr);
{ uint16_t bobPort; i2p::config::GetOption("bob.port", bobPort);
LogPrint(eLogInfo, "Clients: starting BOB command channel at ", bobAddr, ":", bobPort); LogPrint(eLogInfo, "Clients: starting BOB command channel at ", bobAddr, ":", bobPort);
m_BOBCommandChannel = new BOBCommandChannel (bobAddr, bobPort); m_BOBCommandChannel = new BOBCommandChannel (bobAddr, bobPort);
m_BOBCommandChannel->Start (); m_BOBCommandChannel->Start ();

6
Config.h

@ -1,5 +1,5 @@
#ifndef CONFIG_H__ #ifndef CONFIG_H
#define CONFIG_H__ #define CONFIG_H
#include <string> #include <string>
#include <boost/program_options/options_description.hpp> #include <boost/program_options/options_description.hpp>
@ -97,4 +97,4 @@ namespace config {
} }
} }
#endif // CONFIG_H__ #endif // CONFIG_H

68
Daemon.cpp

@ -3,6 +3,7 @@
#include "Daemon.h" #include "Daemon.h"
#include "Config.h"
#include "Log.h" #include "Log.h"
#include "Base.h" #include "Base.h"
#include "version.h" #include "version.h"
@ -50,52 +51,55 @@ namespace i2p
bool Daemon_Singleton::IsService () const bool Daemon_Singleton::IsService () const
{ {
bool service = false;
#ifndef _WIN32 #ifndef _WIN32
return i2p::util::config::GetArg("-service", 0); i2p::config::GetOption("service", service);
#else
return false;
#endif #endif
return service;
} }
bool Daemon_Singleton::init(int argc, char* argv[]) bool Daemon_Singleton::init(int argc, char* argv[])
{ {
i2p::config::Init();
i2p::config::ParseCmdline(argc, argv);
i2p::config::ParseConfig(i2p::util::filesystem::GetConfigFile().string());
i2p::config::Finalize();
i2p::crypto::InitCrypto (); i2p::crypto::InitCrypto ();
i2p::util::config::OptionParser(argc, argv);
i2p::context.Init (); i2p::context.Init ();
LogPrint(eLogInfo, "i2pd v", VERSION, " starting"); LogPrint(eLogInfo, "i2pd v", VERSION, " starting");
LogPrint(eLogDebug, "FS: data directory: ", i2p::util::filesystem::GetDataDir().string()); LogPrint(eLogDebug, "FS: data directory: ", i2p::util::filesystem::GetDataDir().string());
i2p::util::config::ReadConfigFile(i2p::util::filesystem::GetConfigFile());
isDaemon = i2p::util::config::GetArg("-daemon", 0); i2p::config::GetOption("daemon", isDaemon);
isLogging = i2p::util::config::GetArg("-log", 1); i2p::config::GetOption("log", isLogging);
int port = i2p::util::config::GetArg("-port", 0); uint16_t port; i2p::config::GetOption("port", port);
if (port) if (port)
i2p::context.UpdatePort (port); i2p::context.UpdatePort (port);
std::string host = i2p::util::config::GetArg("-host", ""); std::string host; i2p::config::GetOption("host", host);
if (host != "") if (host != "")
i2p::context.UpdateAddress (boost::asio::ip::address::from_string (host)); i2p::context.UpdateAddress (boost::asio::ip::address::from_string (host));
i2p::context.SetSupportsV6 (i2p::util::config::GetArg("-v6", 0)); bool ipv6; i2p::config::GetOption("ipv6", ipv6);
i2p::context.SetAcceptsTunnels (!i2p::util::config::GetArg("-notransit", 0)); bool transit; i2p::config::GetOption("notransit", transit);
bool isFloodfill = i2p::util::config::GetArg("-floodfill", 0); i2p::context.SetSupportsV6 (ipv6);
i2p::context.SetAcceptsTunnels (!transit);
bool isFloodfill; i2p::config::GetOption("floodfill", isFloodfill);
i2p::context.SetFloodfill (isFloodfill); i2p::context.SetFloodfill (isFloodfill);
auto bandwidth = i2p::util::config::GetArg("-bandwidth", "");
if (bandwidth.length () > 0) char bandwidth; i2p::config::GetOption("bandwidth", bandwidth);
if (bandwidth != '-')
{ {
if (bandwidth[0] > 'O') switch (bandwidth) {
i2p::context.SetExtraBandwidth (); case 'P' : i2p::context.SetExtraBandwidth (); break;
else if (bandwidth[0] > 'L') case 'L' : i2p::context.SetHighBandwidth (); break;
i2p::context.SetHighBandwidth (); default : i2p::context.SetLowBandwidth (); break;
else }
i2p::context.SetLowBandwidth ();
} }
else if (isFloodfill) else if (isFloodfill)
i2p::context.SetExtraBandwidth (); i2p::context.SetExtraBandwidth ();
LogPrint(eLogDebug, "Daemon: CMD parameters:");
for (int i = 0; i < argc; ++i)
LogPrint(eLogDebug, i, ": ", argv[i]);
return true; return true;
} }
@ -117,14 +121,18 @@ namespace i2p
} else { } else {
StartLog (""); // write to stdout StartLog (""); // write to stdout
} }
g_Log->SetLogLevel(i2p::util::config::GetArg("-loglevel", "info")); std::string loglevel; i2p::config::GetOption("loglevel", loglevel);
g_Log->SetLogLevel(loglevel);
} }
std::string httpAddr = i2p::util::config::GetArg("-httpaddress", "127.0.0.1"); bool http; i2p::config::GetOption("http.enabled", http);
uint16_t httpPort = i2p::util::config::GetArg("-httpport", 7070); if (http) {
std::string httpAddr; i2p::config::GetOption("http.address", httpAddr);
uint16_t httpPort; i2p::config::GetOption("http.port", httpPort);
LogPrint(eLogInfo, "Daemon: staring HTTP Server at ", httpAddr, ":", httpPort); LogPrint(eLogInfo, "Daemon: staring HTTP Server at ", httpAddr, ":", httpPort);
d.httpServer = std::unique_ptr<i2p::util::HTTPServer>(new i2p::util::HTTPServer(httpAddr, httpPort)); d.httpServer = std::unique_ptr<i2p::util::HTTPServer>(new i2p::util::HTTPServer(httpAddr, httpPort));
d.httpServer->Start(); d.httpServer->Start();
}
LogPrint(eLogInfo, "Daemon: starting NetDB"); LogPrint(eLogInfo, "Daemon: starting NetDB");
i2p::data::netdb.Start(); i2p::data::netdb.Start();
@ -143,10 +151,10 @@ namespace i2p
i2p::client::context.Start (); i2p::client::context.Start ();
// I2P Control Protocol // I2P Control Protocol
std::string i2pcpAddr = i2p::util::config::GetArg("-i2pcontroladdress", "127.0.0.1"); bool i2pcontrol; i2p::config::GetOption("i2pcontrol.enabled", i2pcontrol);
uint16_t i2pcpPort = i2p::util::config::GetArg("-i2pcontrolport", 0); if (i2pcontrol) {
if (i2pcpPort) std::string i2pcpAddr; i2p::config::GetOption("i2pcontrol.address", i2pcpAddr);
{ uint16_t i2pcpPort; i2p::config::GetOption("i2pcontrol.port", i2pcpPort);
LogPrint(eLogInfo, "Daemon: starting I2PControl at ", i2pcpAddr, ":", i2pcpPort); LogPrint(eLogInfo, "Daemon: starting I2PControl at ", i2pcpAddr, ":", i2pcpPort);
d.m_I2PControlService = std::unique_ptr<i2p::client::I2PControlService>(new i2p::client::I2PControlService (i2pcpAddr, i2pcpPort)); d.m_I2PControlService = std::unique_ptr<i2p::client::I2PControlService>(new i2p::client::I2PControlService (i2pcpAddr, i2pcpPort));
d.m_I2PControlService->Start (); d.m_I2PControlService->Start ();

6
DaemonLinux.cpp

@ -8,10 +8,10 @@
#include <fcntl.h> #include <fcntl.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "Config.h"
#include "Log.h" #include "Log.h"
#include "util.h" #include "util.h"
void handle_signal(int sig) void handle_signal(int sig)
{ {
switch (sig) switch (sig)
@ -28,7 +28,6 @@ void handle_signal(int sig)
} }
} }
namespace i2p namespace i2p
{ {
namespace util namespace util
@ -74,7 +73,7 @@ namespace i2p
// Pidfile // Pidfile
// this code is c-styled and a bit ugly, but we need fd for locking pidfile // this code is c-styled and a bit ugly, but we need fd for locking pidfile
pidfile = i2p::util::config::GetArg("-pidfile", ""); std::string pidfile; i2p::config::GetOption("pidfile", pidfile);
if (pidfile == "") { if (pidfile == "") {
pidfile = IsService () ? "/var/run" : i2p::util::filesystem::GetDataDir().string(); pidfile = IsService () ? "/var/run" : i2p::util::filesystem::GetDataDir().string();
pidfile.append("/i2pd.pid"); pidfile.append("/i2pd.pid");
@ -120,7 +119,6 @@ namespace i2p
return Daemon_Singleton::stop(); return Daemon_Singleton::stop();
} }
} }
} }

3
DaemonWin32.cpp

@ -1,3 +1,4 @@
#include "Config.h"
#include "Daemon.h" #include "Daemon.h"
#include "util.h" #include "util.h"
#include "Log.h" #include "Log.h"
@ -23,7 +24,7 @@ namespace i2p
else else
isDaemon = 0; isDaemon = 0;
std::string serviceControl = i2p::util::config::GetArg("-svcctl", ""); std::string serviceControl; i2p::config::GetOption("svcctl", serviceControl);
if (serviceControl == "install") if (serviceControl == "install")
{ {
LogPrint(eLogInfo, "WinSVC: installing ", SERVICE_NAME, " as service"); LogPrint(eLogInfo, "WinSVC: installing ", SERVICE_NAME, " as service");

8
RouterContext.cpp

@ -1,5 +1,6 @@
#include <fstream> #include <fstream>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include "Config.h"
#include "Crypto.h" #include "Crypto.h"
#include "Timestamp.h" #include "Timestamp.h"
#include "I2NPProtocol.h" #include "I2NPProtocol.h"
@ -43,11 +44,12 @@ namespace i2p
{ {
i2p::data::RouterInfo routerInfo; i2p::data::RouterInfo routerInfo;
routerInfo.SetRouterIdentity (GetIdentity ()); routerInfo.SetRouterIdentity (GetIdentity ());
int port = i2p::util::config::GetArg("-port", 0); uint16_t port; i2p::config::GetOption("port", port);
if (!port) if (!port)
port = rand () % (30777 - 9111) + 9111; // I2P network ports range port = rand () % (30777 - 9111) + 9111; // I2P network ports range
routerInfo.AddSSUAddress (i2p::util::config::GetArg("-host", "127.0.0.1").c_str (), port, routerInfo.GetIdentHash ()); std::string host; i2p::config::GetOption("host", host);
routerInfo.AddNTCPAddress (i2p::util::config::GetArg("-host", "127.0.0.1").c_str (), port); routerInfo.AddSSUAddress (host.c_str(), port, routerInfo.GetIdentHash ());
routerInfo.AddNTCPAddress (host.c_str(), port);
routerInfo.SetCaps (i2p::data::RouterInfo::eReachable | routerInfo.SetCaps (i2p::data::RouterInfo::eReachable |
i2p::data::RouterInfo::eSSUTesting | i2p::data::RouterInfo::eSSUIntroducer); // LR, BC i2p::data::RouterInfo::eSSUTesting | i2p::data::RouterInfo::eSSUIntroducer); // LR, BC
routerInfo.SetProperty ("coreVersion", I2P_VERSION); routerInfo.SetProperty ("coreVersion", I2P_VERSION);

5
api.cpp

@ -1,5 +1,6 @@
#include <string> #include <string>
#include <map> #include <map>
#include "Config.h"
#include "Log.h" #include "Log.h"
#include "NetDb.h" #include "NetDb.h"
#include "Transports.h" #include "Transports.h"
@ -18,7 +19,9 @@ namespace api
void InitI2P (int argc, char* argv[], const char * appName) void InitI2P (int argc, char* argv[], const char * appName)
{ {
i2p::util::filesystem::SetAppName (appName); i2p::util::filesystem::SetAppName (appName);
i2p::util::config::OptionParser(argc, argv); i2p::config::Init ();
i2p::config::ParseCmdline (argc, argv);
i2p::config::Finalize ();
i2p::crypto::InitCrypto (); i2p::crypto::InitCrypto ();
i2p::context.Init (); i2p::context.Init ();
} }

19
util.cpp

@ -13,6 +13,7 @@
#include <boost/program_options/detail/config_file.hpp> #include <boost/program_options/detail/config_file.hpp>
#include <boost/program_options/parsers.hpp> #include <boost/program_options/parsers.hpp>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include "Config.h"
#include "util.h" #include "util.h"
#include "Log.h" #include "Log.h"
@ -166,8 +167,10 @@ namespace filesystem
// TODO: datadir parameter is useless because GetDataDir is called before OptionParser // TODO: datadir parameter is useless because GetDataDir is called before OptionParser
// and mapArgs is not initialized yet // and mapArgs is not initialized yet
/*if (i2p::util::config::mapArgs.count("-datadir")) /*
path = boost::filesystem::system_complete(i2p::util::config::mapArgs["-datadir"]); std::string datadir; i2p::config::GetOption("datadir", datadir);
if (datadir != "")
path = boost::filesystem::system_complete(datadir);
else */ else */
path = GetDefaultDataDir(); path = GetDefaultDataDir();
@ -200,14 +203,17 @@ namespace filesystem
boost::filesystem::path GetConfigFile() boost::filesystem::path GetConfigFile()
{ {
boost::filesystem::path pathConfigFile(i2p::util::config::GetArg("-conf", "i2p.conf")); std::string config; i2p::config::GetOption("conf", config);
if (!pathConfigFile.is_complete()) pathConfigFile = GetDataDir() / pathConfigFile; boost::filesystem::path pathConfigFile(config);
if (!pathConfigFile.is_complete())
pathConfigFile = GetDataDir() / pathConfigFile;
return pathConfigFile; return pathConfigFile;
} }
boost::filesystem::path GetTunnelsConfigFile() boost::filesystem::path GetTunnelsConfigFile()
{ {
boost::filesystem::path pathTunnelsConfigFile(i2p::util::config::GetArg("-tunnelscfg", "tunnels.cfg")); std::string tunconf; i2p::config::GetOption("tunconf", tunconf);
boost::filesystem::path pathTunnelsConfigFile(tunconf);
if (!pathTunnelsConfigFile.is_complete()) if (!pathTunnelsConfigFile.is_complete())
pathTunnelsConfigFile = GetDataDir() / pathTunnelsConfigFile; pathTunnelsConfigFile = GetDataDir() / pathTunnelsConfigFile;
return pathTunnelsConfigFile; return pathTunnelsConfigFile;
@ -225,7 +231,8 @@ namespace filesystem
SHGetFolderPath(NULL, CSIDL_PROFILE, 0, 0, localAppData); SHGetFolderPath(NULL, CSIDL_PROFILE, 0, 0, localAppData);
return boost::filesystem::path(std::string(localAppData) + "\\" + "." + appName); return boost::filesystem::path(std::string(localAppData) + "\\" + "." + appName);
#else /* UNIX */ #else /* UNIX */
if (i2p::util::config::GetArg("-service", 0)) // use system folder bool service; i2p::config::GetOption("service", service);
if (service) // use system folder
return boost::filesystem::path(std::string ("/var/lib/") + appName); return boost::filesystem::path(std::string ("/var/lib/") + appName);
boost::filesystem::path pathRet; boost::filesystem::path pathRet;
char* pszHome = getenv("HOME"); char* pszHome = getenv("HOME");

Loading…
Cancel
Save