mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
Merge branch 'new-cmdline' into openssl
Conflicts: ClientContext.cpp Daemon.cpp I2PControl.cpp I2PControl.h docs/configuration.md
This commit is contained in:
commit
900fc1cb46
21 changed files with 745 additions and 477 deletions
131
Daemon.cpp
131
Daemon.cpp
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "Daemon.h"
|
||||
|
||||
#include "Config.h"
|
||||
#include "Log.h"
|
||||
#include "Base.h"
|
||||
#include "version.h"
|
||||
|
@ -50,78 +51,106 @@ 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[])
|
||||
{
|
||||
std::string config = i2p::util::filesystem::GetConfigFile().string();
|
||||
std::string tunconf = i2p::util::filesystem::GetTunnelsConfigFile().string();
|
||||
std::string datadir = i2p::util::filesystem::GetDataDir().string();
|
||||
|
||||
LogPrint(eLogInfo, "i2pd v", VERSION, " starting");
|
||||
LogPrint(eLogDebug, "FS: main config file: ", config);
|
||||
LogPrint(eLogDebug, "FS: tunnels config: ", tunconf);
|
||||
LogPrint(eLogDebug, "FS: data directory: ", datadir);
|
||||
|
||||
i2p::config::Init();
|
||||
i2p::config::ParseCmdline(argc, argv);
|
||||
i2p::config::ParseConfig(config);
|
||||
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());
|
||||
i2p::config::GetOption("daemon", isDaemon);
|
||||
|
||||
isDaemon = i2p::util::config::GetArg("-daemon", 0);
|
||||
isLogging = i2p::util::config::GetArg("-log", (int)isDaemon);
|
||||
// temporary hack
|
||||
std::string logs = "";
|
||||
i2p::config::GetOption("log", logs);
|
||||
if (logs != "")
|
||||
isLogging = true;
|
||||
|
||||
int port = i2p::util::config::GetArg("-port", 0);
|
||||
if (port)
|
||||
i2p::context.UpdatePort (port);
|
||||
std::string host = i2p::util::config::GetArg("-host", "");
|
||||
if (host != "")
|
||||
uint16_t port; i2p::config::GetOption("port", port);
|
||||
LogPrint(eLogInfo, "Daemon: accepting incoming connections at port ", port);
|
||||
i2p::context.UpdatePort (port);
|
||||
|
||||
std::string host; i2p::config::GetOption("host", host);
|
||||
if (host != "") {
|
||||
LogPrint(eLogInfo, "Daemon: address for incoming connections is ", 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);
|
||||
i2p::context.SetFloodfill (isFloodfill);
|
||||
auto bandwidth = i2p::util::config::GetArg("-bandwidth", "");
|
||||
if (bandwidth.length () > 0)
|
||||
{
|
||||
if (bandwidth[0] > 'O')
|
||||
i2p::context.SetExtraBandwidth ();
|
||||
else if (bandwidth[0] > 'L')
|
||||
i2p::context.SetHighBandwidth ();
|
||||
else
|
||||
i2p::context.SetLowBandwidth ();
|
||||
}
|
||||
else if (isFloodfill)
|
||||
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);
|
||||
char bandwidth; i2p::config::GetOption("bandwidth", bandwidth);
|
||||
|
||||
if (isFloodfill) {
|
||||
LogPrint(eLogInfo, "Daemon: router will be floodfill, bandwidth set to 'extra'");
|
||||
i2p::context.SetFloodfill (true);
|
||||
i2p::context.SetExtraBandwidth ();
|
||||
LogPrint(eLogDebug, "Daemon: CMD parameters:");
|
||||
for (int i = 0; i < argc; ++i)
|
||||
LogPrint(eLogDebug, i, ": ", argv[i]);
|
||||
} else if (bandwidth != '-') {
|
||||
LogPrint(eLogInfo, "Daemon: bandwidth set to ", bandwidth);
|
||||
switch (bandwidth) {
|
||||
case 'P' : i2p::context.SetExtraBandwidth (); break;
|
||||
case 'L' : i2p::context.SetHighBandwidth (); break;
|
||||
default : i2p::context.SetLowBandwidth (); break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Daemon_Singleton::start()
|
||||
{
|
||||
// initialize log
|
||||
if (isLogging)
|
||||
{
|
||||
std::string logfile_path = IsService () ? "/var/log/i2pd" : i2p::util::filesystem::GetDataDir().string();
|
||||
{
|
||||
// set default to stdout
|
||||
std::string logfile = ""; i2p::config::GetOption("logfile", logfile);
|
||||
std::string loglevel = ""; i2p::config::GetOption("loglevel", loglevel);
|
||||
if (isDaemon && logfile == "") {
|
||||
// can't log to stdout, use autodetect of logfile
|
||||
if (IsService ()) {
|
||||
logfile = "/var/log";
|
||||
} else {
|
||||
logfile = i2p::util::filesystem::GetDataDir().string();
|
||||
}
|
||||
#ifndef _WIN32
|
||||
logfile_path.append("/i2pd.log");
|
||||
logfile.append("/i2pd.log");
|
||||
#else
|
||||
logfile_path.append("\\i2pd.log");
|
||||
logfile.append("\\i2pd.log");
|
||||
#endif
|
||||
StartLog (logfile_path);
|
||||
}
|
||||
StartLog (logfile);
|
||||
g_Log->SetLogLevel(loglevel);
|
||||
}
|
||||
|
||||
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: starting HTTP Server at ", httpAddr, ":", httpPort);
|
||||
d.httpServer = std::unique_ptr<i2p::util::HTTPServer>(new i2p::util::HTTPServer(httpAddr, httpPort));
|
||||
d.httpServer->Start();
|
||||
}
|
||||
else
|
||||
StartLog (""); // write to stdout
|
||||
g_Log->SetLogLevel(i2p::util::config::GetArg("-loglevel", "info"));
|
||||
|
||||
std::string httpAddr = i2p::util::config::GetArg("-httpaddress", "127.0.0.1");
|
||||
uint16_t httpPort = i2p::util::config::GetArg("-httpport", 7070);
|
||||
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();
|
||||
|
@ -140,10 +169,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 ();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue