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 @@ @@ -2,6 +2,7 @@
#include <iostream>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>
#include "Config.h"
#include "util.h"
#include "Log.h"
#include "Identity.h"
@ -37,44 +38,56 @@ namespace client @@ -37,44 +38,56 @@ namespace client
}
std::shared_ptr<ClientDestination> localDestination;
// proxies
std::string proxyKeys = i2p::util::config::GetArg("-proxykeys", "");
if (proxyKeys.length () > 0)
bool httproxy; i2p::config::GetOption("httpproxy.enabled", httproxy);
if (httproxy) {
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;
LoadPrivateKeys (keys, proxyKeys);
LoadPrivateKeys (keys, httpProxyKeys);
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->Start();
}
std::string socksProxyAddr = i2p::util::config::GetArg("-socksproxyaddress", "127.0.0.1");
uint16_t socksProxyPort = i2p::util::config::GetArg("-socksproxyport", 4447);
bool socksproxy; i2p::config::GetOption("socksproxy.enabled", socksproxy);
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);
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->Start();
}
// I2P tunnels
ReadTunnels ();
// SAM
std::string samAddr = i2p::util::config::GetArg("-samaddress", "127.0.0.1");
uint16_t samPort = i2p::util::config::GetArg("-samport", 0);
if (samPort)
{
LogPrint(eLogInfo, "Clients: starting SAM bridge at", samAddr, ":", samPort);
bool sam; i2p::config::GetOption("sam.enabled", sam);
if (sam) {
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);
m_SamBridge = new SAMBridge (samAddr, samPort);
m_SamBridge->Start ();
}
// BOB
std::string bobAddr = i2p::util::config::GetArg("-bobaddress", "127.0.0.1");
uint16_t bobPort = i2p::util::config::GetArg("-bobport", 0);
if (bobPort)
{
bool bob; i2p::config::GetOption("bob.enabled", bob);
if (bob) {
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);
m_BOBCommandChannel = new BOBCommandChannel (bobAddr, bobPort);
m_BOBCommandChannel->Start ();

6
Config.h

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

68
Daemon.cpp

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
#include "Daemon.h"
#include "Config.h"
#include "Log.h"
#include "Base.h"
#include "version.h"
@ -50,52 +51,55 @@ namespace i2p @@ -50,52 +51,55 @@ namespace i2p
bool Daemon_Singleton::IsService () const
{
bool service = false;
#ifndef _WIN32
return i2p::util::config::GetArg("-service", 0);
#else
return false;
i2p::config::GetOption("service", service);
#endif
return service;
}
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::util::config::OptionParser(argc, argv);
i2p::context.Init ();
LogPrint(eLogInfo, "i2pd v", VERSION, " starting");
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);
isLogging = i2p::util::config::GetArg("-log", 1);
i2p::config::GetOption("daemon", isDaemon);
i2p::config::GetOption("log", isLogging);
int port = i2p::util::config::GetArg("-port", 0);
uint16_t port; i2p::config::GetOption("port", port);
if (port)
i2p::context.UpdatePort (port);
std::string host = i2p::util::config::GetArg("-host", "");
std::string host; i2p::config::GetOption("host", host);
if (host != "")
i2p::context.UpdateAddress (boost::asio::ip::address::from_string (host));
i2p::context.SetSupportsV6 (i2p::util::config::GetArg("-v6", 0));
i2p::context.SetAcceptsTunnels (!i2p::util::config::GetArg("-notransit", 0));
bool isFloodfill = i2p::util::config::GetArg("-floodfill", 0);
bool ipv6; i2p::config::GetOption("ipv6", ipv6);
bool transit; i2p::config::GetOption("notransit", transit);
i2p::context.SetSupportsV6 (ipv6);
i2p::context.SetAcceptsTunnels (!transit);
bool isFloodfill; i2p::config::GetOption("floodfill", 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')
i2p::context.SetExtraBandwidth ();
else if (bandwidth[0] > 'L')
i2p::context.SetHighBandwidth ();
else
i2p::context.SetLowBandwidth ();
switch (bandwidth) {
case 'P' : i2p::context.SetExtraBandwidth (); break;
case 'L' : i2p::context.SetHighBandwidth (); break;
default : i2p::context.SetLowBandwidth (); break;
}
}
else if (isFloodfill)
i2p::context.SetExtraBandwidth ();
LogPrint(eLogDebug, "Daemon: CMD parameters:");
for (int i = 0; i < argc; ++i)
LogPrint(eLogDebug, i, ": ", argv[i]);
return true;
}
@ -117,14 +121,18 @@ namespace i2p @@ -117,14 +121,18 @@ namespace i2p
} else {
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");
uint16_t httpPort = i2p::util::config::GetArg("-httpport", 7070);
bool http; i2p::config::GetOption("http.enabled", http);
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);
d.httpServer = std::unique_ptr<i2p::util::HTTPServer>(new i2p::util::HTTPServer(httpAddr, httpPort));
d.httpServer->Start();
}
LogPrint(eLogInfo, "Daemon: starting NetDB");
i2p::data::netdb.Start();
@ -143,10 +151,10 @@ namespace i2p @@ -143,10 +151,10 @@ namespace i2p
i2p::client::context.Start ();
// I2P Control Protocol
std::string i2pcpAddr = i2p::util::config::GetArg("-i2pcontroladdress", "127.0.0.1");
uint16_t i2pcpPort = i2p::util::config::GetArg("-i2pcontrolport", 0);
if (i2pcpPort)
{
bool i2pcontrol; i2p::config::GetOption("i2pcontrol.enabled", i2pcontrol);
if (i2pcontrol) {
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);
d.m_I2PControlService = std::unique_ptr<i2p::client::I2PControlService>(new i2p::client::I2PControlService (i2pcpAddr, i2pcpPort));
d.m_I2PControlService->Start ();

6
DaemonLinux.cpp

@ -8,10 +8,10 @@ @@ -8,10 +8,10 @@
#include <fcntl.h>
#include <sys/stat.h>
#include "Config.h"
#include "Log.h"
#include "util.h"
void handle_signal(int sig)
{
switch (sig)
@ -28,7 +28,6 @@ void handle_signal(int sig) @@ -28,7 +28,6 @@ void handle_signal(int sig)
}
}
namespace i2p
{
namespace util
@ -74,7 +73,7 @@ namespace i2p @@ -74,7 +73,7 @@ namespace i2p
// 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 == "") {
pidfile = IsService () ? "/var/run" : i2p::util::filesystem::GetDataDir().string();
pidfile.append("/i2pd.pid");
@ -120,7 +119,6 @@ namespace i2p @@ -120,7 +119,6 @@ namespace i2p
return Daemon_Singleton::stop();
}
}
}

3
DaemonWin32.cpp

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

8
RouterContext.cpp

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

5
api.cpp

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
#include <string>
#include <map>
#include "Config.h"
#include "Log.h"
#include "NetDb.h"
#include "Transports.h"
@ -18,7 +19,9 @@ namespace api @@ -18,7 +19,9 @@ namespace api
void InitI2P (int argc, char* argv[], const char * 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::context.Init ();
}

19
util.cpp

@ -13,6 +13,7 @@ @@ -13,6 +13,7 @@
#include <boost/program_options/detail/config_file.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/algorithm/string.hpp>
#include "Config.h"
#include "util.h"
#include "Log.h"
@ -166,8 +167,10 @@ namespace filesystem @@ -166,8 +167,10 @@ namespace filesystem
// TODO: datadir parameter is useless because GetDataDir is called before OptionParser
// 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 */
path = GetDefaultDataDir();
@ -200,14 +203,17 @@ namespace filesystem @@ -200,14 +203,17 @@ namespace filesystem
boost::filesystem::path GetConfigFile()
{
boost::filesystem::path pathConfigFile(i2p::util::config::GetArg("-conf", "i2p.conf"));
if (!pathConfigFile.is_complete()) pathConfigFile = GetDataDir() / pathConfigFile;
std::string config; i2p::config::GetOption("conf", config);
boost::filesystem::path pathConfigFile(config);
if (!pathConfigFile.is_complete())
pathConfigFile = GetDataDir() / pathConfigFile;
return pathConfigFile;
}
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())
pathTunnelsConfigFile = GetDataDir() / pathTunnelsConfigFile;
return pathTunnelsConfigFile;
@ -225,7 +231,8 @@ namespace filesystem @@ -225,7 +231,8 @@ namespace filesystem
SHGetFolderPath(NULL, CSIDL_PROFILE, 0, 0, localAppData);
return boost::filesystem::path(std::string(localAppData) + "\\" + "." + appName);
#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);
boost::filesystem::path pathRet;
char* pszHome = getenv("HOME");

Loading…
Cancel
Save