2020-10-04 16:34:15 +03:00
|
|
|
/*
|
2024-01-11 23:39:42 +03:00
|
|
|
* Copyright (c) 2013-2024, The PurpleI2P Project
|
2020-10-04 16:34:15 +03:00
|
|
|
*
|
|
|
|
* This file is part of Purple i2pd project and licensed under BSD3
|
|
|
|
*
|
|
|
|
* See full license text in LICENSE file at top of project tree
|
|
|
|
*/
|
|
|
|
|
2014-04-23 02:07:21 +04:00
|
|
|
#include <thread>
|
2015-11-03 17:15:49 +03:00
|
|
|
#include <memory>
|
2014-04-23 02:07:21 +04:00
|
|
|
|
2014-04-20 05:54:34 +04:00
|
|
|
#include "Daemon.h"
|
|
|
|
|
2016-01-20 03:00:00 +03:00
|
|
|
#include "Config.h"
|
2014-04-20 05:54:34 +04:00
|
|
|
#include "Log.h"
|
2016-02-11 03:00:00 +03:00
|
|
|
#include "FS.h"
|
2015-11-03 17:15:49 +03:00
|
|
|
#include "Base.h"
|
2014-10-17 19:42:05 +04:00
|
|
|
#include "version.h"
|
2014-04-20 05:54:34 +04:00
|
|
|
#include "Transports.h"
|
|
|
|
#include "RouterInfo.h"
|
|
|
|
#include "RouterContext.h"
|
|
|
|
#include "Tunnel.h"
|
2016-04-27 03:00:00 +03:00
|
|
|
#include "HTTP.h"
|
2017-04-22 03:04:16 +03:00
|
|
|
#include "NetDb.hpp"
|
2014-04-20 05:54:34 +04:00
|
|
|
#include "Garlic.h"
|
|
|
|
#include "Streaming.h"
|
2014-10-05 16:54:59 +04:00
|
|
|
#include "Destination.h"
|
2014-04-23 02:07:21 +04:00
|
|
|
#include "HTTPServer.h"
|
2015-11-03 17:15:49 +03:00
|
|
|
#include "I2PControl.h"
|
2014-10-16 04:52:17 +04:00
|
|
|
#include "ClientContext.h"
|
2016-01-01 00:02:10 +03:00
|
|
|
#include "Crypto.h"
|
2015-11-03 17:15:49 +03:00
|
|
|
#include "UPnP.h"
|
2018-11-14 19:06:53 +03:00
|
|
|
#include "Timestamp.h"
|
2021-05-25 22:03:29 +03:00
|
|
|
#include "I18N.h"
|
2015-11-03 17:15:49 +03:00
|
|
|
|
2014-04-20 05:54:34 +04:00
|
|
|
namespace i2p
|
|
|
|
{
|
2021-02-01 14:36:51 +03:00
|
|
|
namespace util
|
|
|
|
{
|
|
|
|
class Daemon_Singleton::Daemon_Singleton_Private
|
2014-04-20 05:54:34 +04:00
|
|
|
{
|
2021-02-01 14:36:51 +03:00
|
|
|
public:
|
|
|
|
Daemon_Singleton_Private() {};
|
|
|
|
~Daemon_Singleton_Private() {};
|
|
|
|
|
|
|
|
std::unique_ptr<i2p::http::HTTPServer> httpServer;
|
|
|
|
std::unique_ptr<i2p::client::I2PControlService> m_I2PControlService;
|
|
|
|
std::unique_ptr<i2p::transport::UPnP> UPnP;
|
|
|
|
std::unique_ptr<i2p::util::NTPTimeSync> m_NTPSync;
|
|
|
|
};
|
|
|
|
|
|
|
|
Daemon_Singleton::Daemon_Singleton() : isDaemon(false), running(true), d(*new Daemon_Singleton_Private()) {}
|
|
|
|
Daemon_Singleton::~Daemon_Singleton() {
|
|
|
|
delete &d;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Daemon_Singleton::IsService () const
|
|
|
|
{
|
|
|
|
bool service = false;
|
|
|
|
i2p::config::GetOption("service", service);
|
|
|
|
return service;
|
|
|
|
}
|
2014-04-23 02:07:21 +04:00
|
|
|
|
2022-04-09 19:57:16 +03:00
|
|
|
void Daemon_Singleton::setDataDir(std::string path)
|
|
|
|
{
|
|
|
|
if (path != "")
|
|
|
|
DaemonDataDir = path;
|
|
|
|
}
|
|
|
|
|
2021-02-01 14:36:51 +03:00
|
|
|
bool Daemon_Singleton::init(int argc, char* argv[]) {
|
|
|
|
return init(argc, argv, nullptr);
|
|
|
|
}
|
2018-05-19 18:03:49 +03:00
|
|
|
|
2021-02-01 14:36:51 +03:00
|
|
|
bool Daemon_Singleton::init(int argc, char* argv[], std::shared_ptr<std::ostream> logstream)
|
|
|
|
{
|
|
|
|
i2p::config::Init();
|
|
|
|
i2p::config::ParseCmdline(argc, argv);
|
2016-02-03 14:22:00 +03:00
|
|
|
|
2022-05-20 19:56:05 +03:00
|
|
|
std::string config; i2p::config::GetOption("conf", config);
|
2022-04-09 19:57:16 +03:00
|
|
|
std::string datadir;
|
|
|
|
if(DaemonDataDir != "") {
|
|
|
|
datadir = DaemonDataDir;
|
|
|
|
} else {
|
|
|
|
i2p::config::GetOption("datadir", datadir);
|
|
|
|
}
|
|
|
|
|
2021-02-01 14:36:51 +03:00
|
|
|
i2p::fs::DetectDataDir(datadir, IsService());
|
|
|
|
i2p::fs::Init();
|
2016-02-11 03:00:00 +03:00
|
|
|
|
2021-02-01 14:36:51 +03:00
|
|
|
datadir = i2p::fs::GetDataDir();
|
2020-05-05 02:36:34 +03:00
|
|
|
|
2021-02-01 14:36:51 +03:00
|
|
|
if (config == "")
|
|
|
|
{
|
|
|
|
config = i2p::fs::DataDirPath("i2pd.conf");
|
|
|
|
if (!i2p::fs::Exists (config)) {
|
|
|
|
// use i2pd.conf only if exists
|
|
|
|
config = ""; /* reset */
|
2016-02-22 23:17:58 +03:00
|
|
|
}
|
2021-02-01 14:36:51 +03:00
|
|
|
}
|
2016-01-24 14:06:17 +03:00
|
|
|
|
2021-02-01 14:36:51 +03:00
|
|
|
i2p::config::ParseConfig(config);
|
|
|
|
i2p::config::Finalize();
|
2016-01-20 03:00:00 +03:00
|
|
|
|
2021-02-01 14:36:51 +03:00
|
|
|
i2p::config::GetOption("daemon", isDaemon);
|
2014-04-23 02:07:21 +04:00
|
|
|
|
2021-06-18 10:04:48 +03:00
|
|
|
std::string certsdir; i2p::config::GetOption("certsdir", certsdir);
|
|
|
|
i2p::fs::SetCertsDir(certsdir);
|
|
|
|
|
|
|
|
certsdir = i2p::fs::GetCertsDir();
|
|
|
|
|
2022-05-20 19:56:05 +03:00
|
|
|
std::string logs = ""; i2p::config::GetOption("log", logs);
|
|
|
|
std::string logfile = ""; i2p::config::GetOption("logfile", logfile);
|
|
|
|
std::string loglevel = ""; i2p::config::GetOption("loglevel", loglevel);
|
2021-02-01 14:36:51 +03:00
|
|
|
bool logclftime; i2p::config::GetOption("logclftime", logclftime);
|
2016-03-27 03:17:29 +03:00
|
|
|
|
2021-02-01 14:36:51 +03:00
|
|
|
/* setup logging */
|
|
|
|
if (logclftime)
|
|
|
|
i2p::log::Logger().SetTimeFormat ("[%d/%b/%Y:%H:%M:%S %z]");
|
2017-09-20 02:46:28 +03:00
|
|
|
|
2021-03-11 14:39:33 +03:00
|
|
|
#ifdef WIN32_APP
|
|
|
|
// Win32 app with GUI supports only logging to file
|
|
|
|
logs = "file";
|
|
|
|
#else
|
2021-02-01 14:36:51 +03:00
|
|
|
if (isDaemon && (logs == "" || logs == "stdout"))
|
|
|
|
logs = "file";
|
2021-03-11 14:39:33 +03:00
|
|
|
#endif
|
2016-03-27 03:17:29 +03:00
|
|
|
|
2021-02-01 14:36:51 +03:00
|
|
|
i2p::log::Logger().SetLogLevel(loglevel);
|
|
|
|
if (logstream) {
|
2021-11-27 22:53:53 +03:00
|
|
|
LogPrint(eLogInfo, "Log: Sending messages to std::ostream");
|
2021-02-01 14:36:51 +03:00
|
|
|
i2p::log::Logger().SendTo (logstream);
|
|
|
|
} else if (logs == "file") {
|
|
|
|
if (logfile == "")
|
|
|
|
logfile = i2p::fs::DataDirPath("i2pd.log");
|
2021-11-27 22:53:53 +03:00
|
|
|
LogPrint(eLogInfo, "Log: Sending messages to ", logfile);
|
2021-02-01 14:36:51 +03:00
|
|
|
i2p::log::Logger().SendTo (logfile);
|
2016-03-27 03:17:29 +03:00
|
|
|
#ifndef _WIN32
|
2021-02-01 14:36:51 +03:00
|
|
|
} else if (logs == "syslog") {
|
2021-11-27 22:53:53 +03:00
|
|
|
LogPrint(eLogInfo, "Log: Sending messages to syslog");
|
2021-02-01 14:36:51 +03:00
|
|
|
i2p::log::Logger().SendTo("i2pd", LOG_DAEMON);
|
2016-03-27 03:17:29 +03:00
|
|
|
#endif
|
2021-02-01 14:36:51 +03:00
|
|
|
} else {
|
|
|
|
// use stdout -- default
|
|
|
|
}
|
2016-02-03 14:22:00 +03:00
|
|
|
|
2021-11-27 22:53:53 +03:00
|
|
|
LogPrint(eLogNone, "i2pd v", VERSION, " (", I2P_VERSION, ") starting...");
|
|
|
|
LogPrint(eLogDebug, "FS: Main config file: ", config);
|
|
|
|
LogPrint(eLogDebug, "FS: Data directory: ", datadir);
|
|
|
|
LogPrint(eLogDebug, "FS: Certificates directory: ", certsdir);
|
2014-04-20 05:54:34 +04:00
|
|
|
|
2021-02-01 14:36:51 +03:00
|
|
|
bool precomputation; i2p::config::GetOption("precomputation.elgamal", precomputation);
|
|
|
|
bool aesni; i2p::config::GetOption("cpuext.aesni", aesni);
|
|
|
|
bool forceCpuExt; i2p::config::GetOption("cpuext.force", forceCpuExt);
|
2022-08-09 00:53:02 +03:00
|
|
|
bool ssu; i2p::config::GetOption("ssu", ssu);
|
|
|
|
if (!ssu && i2p::config::IsDefault ("precomputation.elgamal"))
|
|
|
|
precomputation = false; // we don't elgamal table if no ssu, unless it's specified explicitly
|
2023-08-31 19:52:51 +03:00
|
|
|
i2p::crypto::InitCrypto (precomputation, aesni, forceCpuExt);
|
2016-11-01 20:34:19 +03:00
|
|
|
|
2022-10-10 15:43:37 +03:00
|
|
|
i2p::transport::InitAddressFromIface (); // get address4/6 from interfaces
|
|
|
|
|
2021-02-01 14:36:51 +03:00
|
|
|
int netID; i2p::config::GetOption("netid", netID);
|
|
|
|
i2p::context.SetNetID (netID);
|
2024-01-12 18:13:07 +03:00
|
|
|
|
|
|
|
bool checkReserved; i2p::config::GetOption("reservedrange", checkReserved);
|
|
|
|
i2p::transport::transports.SetCheckReserved(checkReserved);
|
|
|
|
|
2021-02-01 14:36:51 +03:00
|
|
|
i2p::context.Init ();
|
2016-03-27 03:17:29 +03:00
|
|
|
|
2022-09-24 04:27:11 +03:00
|
|
|
i2p::transport::InitTransports ();
|
2022-10-09 20:24:43 +03:00
|
|
|
|
2021-02-01 14:36:51 +03:00
|
|
|
bool isFloodfill; i2p::config::GetOption("floodfill", isFloodfill);
|
2023-01-03 21:25:19 +03:00
|
|
|
if (isFloodfill)
|
2023-01-02 23:03:00 +03:00
|
|
|
{
|
2021-11-27 22:53:53 +03:00
|
|
|
LogPrint(eLogInfo, "Daemon: Router configured as floodfill");
|
2021-02-01 14:36:51 +03:00
|
|
|
i2p::context.SetFloodfill (true);
|
2014-07-02 21:48:45 +04:00
|
|
|
}
|
2021-02-01 14:36:51 +03:00
|
|
|
else
|
|
|
|
i2p::context.SetFloodfill (false);
|
2016-07-12 03:00:00 +03:00
|
|
|
|
2023-01-02 23:03:00 +03:00
|
|
|
bool transit; i2p::config::GetOption("notransit", transit);
|
|
|
|
i2p::context.SetAcceptsTunnels (!transit);
|
2024-02-22 22:22:11 +03:00
|
|
|
uint32_t transitTunnels; i2p::config::GetOption("limits.transittunnels", transitTunnels);
|
2023-01-02 23:03:00 +03:00
|
|
|
if (isFloodfill && i2p::config::IsDefault ("limits.transittunnels"))
|
|
|
|
transitTunnels *= 2; // double default number of transit tunnels for floodfill
|
2023-03-06 04:08:15 +03:00
|
|
|
i2p::tunnel::tunnels.SetMaxNumTransitTunnels (transitTunnels);
|
2023-01-03 21:25:19 +03:00
|
|
|
|
2021-02-01 14:36:51 +03:00
|
|
|
/* this section also honors 'floodfill' flag, if set above */
|
|
|
|
std::string bandwidth; i2p::config::GetOption("bandwidth", bandwidth);
|
|
|
|
if (bandwidth.length () > 0)
|
|
|
|
{
|
2024-05-14 23:04:05 +03:00
|
|
|
if (bandwidth.length () == 1 && ((bandwidth[0] >= 'K' && bandwidth[0] <= 'P') || bandwidth[0] == 'X' ))
|
2018-11-16 20:49:04 +03:00
|
|
|
{
|
2021-02-01 14:36:51 +03:00
|
|
|
i2p::context.SetBandwidth (bandwidth[0]);
|
2021-11-27 22:53:53 +03:00
|
|
|
LogPrint(eLogInfo, "Daemon: Bandwidth set to ", i2p::context.GetBandwidthLimit (), "KBps");
|
2018-11-16 20:49:04 +03:00
|
|
|
}
|
2020-10-12 17:36:44 +03:00
|
|
|
else
|
2018-08-10 22:35:43 +03:00
|
|
|
{
|
2021-02-01 14:36:51 +03:00
|
|
|
auto value = std::atoi(bandwidth.c_str());
|
|
|
|
if (value > 0)
|
2020-05-05 17:16:16 +03:00
|
|
|
{
|
2021-02-01 14:36:51 +03:00
|
|
|
i2p::context.SetBandwidth (value);
|
2021-11-27 22:53:53 +03:00
|
|
|
LogPrint(eLogInfo, "Daemon: Bandwidth set to ", i2p::context.GetBandwidthLimit (), " KBps");
|
2021-02-01 14:36:51 +03:00
|
|
|
}
|
|
|
|
else
|
2020-05-05 17:16:16 +03:00
|
|
|
{
|
2021-11-27 22:53:53 +03:00
|
|
|
LogPrint(eLogInfo, "Daemon: Unexpected bandwidth ", bandwidth, ". Set to 'low'");
|
2021-02-01 14:36:51 +03:00
|
|
|
i2p::context.SetBandwidth (i2p::data::CAPS_FLAG_LOW_BANDWIDTH2);
|
2020-05-05 02:36:34 +03:00
|
|
|
}
|
2016-06-13 18:34:44 +03:00
|
|
|
}
|
2021-02-01 14:36:51 +03:00
|
|
|
}
|
|
|
|
else if (isFloodfill)
|
|
|
|
{
|
2021-11-27 22:53:53 +03:00
|
|
|
LogPrint(eLogInfo, "Daemon: Floodfill bandwidth set to 'extra'");
|
2021-03-28 20:13:00 +03:00
|
|
|
i2p::context.SetBandwidth (i2p::data::CAPS_FLAG_EXTRA_BANDWIDTH2);
|
2021-02-01 14:36:51 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LogPrint(eLogInfo, "Daemon: bandwidth set to 'low'");
|
|
|
|
i2p::context.SetBandwidth (i2p::data::CAPS_FLAG_LOW_BANDWIDTH2);
|
|
|
|
}
|
2015-12-18 15:21:37 +03:00
|
|
|
|
2021-02-01 14:36:51 +03:00
|
|
|
int shareRatio; i2p::config::GetOption("share", shareRatio);
|
|
|
|
i2p::context.SetShareRatio (shareRatio);
|
2020-10-04 04:58:20 +03:00
|
|
|
|
2021-02-01 14:36:51 +03:00
|
|
|
std::string family; i2p::config::GetOption("family", family);
|
|
|
|
i2p::context.SetFamily (family);
|
|
|
|
if (family.length () > 0)
|
2021-11-27 22:53:53 +03:00
|
|
|
LogPrint(eLogInfo, "Daemon: Router family set to ", family);
|
2015-12-18 15:21:37 +03:00
|
|
|
|
2021-02-01 14:36:51 +03:00
|
|
|
bool trust; i2p::config::GetOption("trust.enabled", trust);
|
|
|
|
if (trust)
|
|
|
|
{
|
2021-11-27 22:53:53 +03:00
|
|
|
LogPrint(eLogInfo, "Daemon: Explicit trust enabled");
|
2021-02-01 14:36:51 +03:00
|
|
|
std::string fam; i2p::config::GetOption("trust.family", fam);
|
|
|
|
std::string routers; i2p::config::GetOption("trust.routers", routers);
|
|
|
|
bool restricted = false;
|
|
|
|
if (fam.length() > 0)
|
|
|
|
{
|
|
|
|
std::set<std::string> fams;
|
|
|
|
size_t pos = 0, comma;
|
|
|
|
do
|
2020-05-05 17:16:16 +03:00
|
|
|
{
|
2021-02-01 14:36:51 +03:00
|
|
|
comma = fam.find (',', pos);
|
|
|
|
fams.insert (fam.substr (pos, comma != std::string::npos ? comma - pos : std::string::npos));
|
|
|
|
pos = comma + 1;
|
|
|
|
}
|
|
|
|
while (comma != std::string::npos);
|
|
|
|
i2p::transport::transports.RestrictRoutesToFamilies(fams);
|
|
|
|
restricted = fams.size() > 0;
|
|
|
|
}
|
|
|
|
if (routers.length() > 0) {
|
|
|
|
std::set<i2p::data::IdentHash> idents;
|
|
|
|
size_t pos = 0, comma;
|
|
|
|
do
|
2020-05-05 17:16:16 +03:00
|
|
|
{
|
2021-02-01 14:36:51 +03:00
|
|
|
comma = routers.find (',', pos);
|
|
|
|
i2p::data::IdentHash ident;
|
|
|
|
ident.FromBase64 (routers.substr (pos, comma != std::string::npos ? comma - pos : std::string::npos));
|
|
|
|
idents.insert (ident);
|
|
|
|
pos = comma + 1;
|
2020-05-05 02:36:34 +03:00
|
|
|
}
|
2021-02-01 14:36:51 +03:00
|
|
|
while (comma != std::string::npos);
|
2021-11-27 22:53:53 +03:00
|
|
|
LogPrint(eLogInfo, "Daemon: Setting restricted routes to use ", idents.size(), " trusted routers");
|
2021-02-01 14:36:51 +03:00
|
|
|
i2p::transport::transports.RestrictRoutesToRouters(idents);
|
|
|
|
restricted = idents.size() > 0;
|
2015-11-03 17:15:49 +03:00
|
|
|
}
|
2021-02-01 14:36:51 +03:00
|
|
|
if(!restricted)
|
2023-03-31 15:16:32 +03:00
|
|
|
LogPrint(eLogError, "Daemon: No trusted routers of families specified");
|
2021-02-01 14:36:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool hidden; i2p::config::GetOption("trust.hidden", hidden);
|
|
|
|
if (hidden)
|
|
|
|
{
|
2021-11-27 22:53:53 +03:00
|
|
|
LogPrint(eLogInfo, "Daemon: Hidden mode enabled");
|
2023-02-25 02:33:33 +03:00
|
|
|
i2p::context.SetHidden(true);
|
2021-02-01 14:36:51 +03:00
|
|
|
}
|
2021-05-22 18:29:05 +03:00
|
|
|
|
|
|
|
std::string httpLang; i2p::config::GetOption("http.lang", httpLang);
|
2021-05-25 22:03:29 +03:00
|
|
|
i2p::i18n::SetLanguage(httpLang);
|
2021-05-22 18:29:05 +03:00
|
|
|
|
2021-02-01 14:36:51 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Daemon_Singleton::start()
|
|
|
|
{
|
|
|
|
i2p::log::Logger().Start();
|
2021-11-27 22:53:53 +03:00
|
|
|
LogPrint(eLogInfo, "Daemon: Starting NetDB");
|
2021-02-01 14:36:51 +03:00
|
|
|
i2p::data::netdb.Start();
|
|
|
|
|
|
|
|
bool upnp; i2p::config::GetOption("upnp.enabled", upnp);
|
|
|
|
if (upnp) {
|
|
|
|
d.UPnP = std::unique_ptr<i2p::transport::UPnP>(new i2p::transport::UPnP);
|
|
|
|
d.UPnP->Start ();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nettime; i2p::config::GetOption("nettime.enabled", nettime);
|
|
|
|
if (nettime)
|
|
|
|
{
|
|
|
|
d.m_NTPSync = std::unique_ptr<i2p::util::NTPTimeSync>(new i2p::util::NTPTimeSync);
|
|
|
|
d.m_NTPSync->Start ();
|
2014-04-20 05:54:34 +04:00
|
|
|
}
|
|
|
|
|
2021-02-01 14:36:51 +03:00
|
|
|
bool ntcp2; i2p::config::GetOption("ntcp2.enabled", ntcp2);
|
2022-03-14 04:34:11 +03:00
|
|
|
bool ssu2; i2p::config::GetOption("ssu2.enabled", ssu2);
|
2021-11-27 22:53:53 +03:00
|
|
|
LogPrint(eLogInfo, "Daemon: Starting Transports");
|
2022-11-23 03:29:20 +03:00
|
|
|
if(!ssu2) LogPrint(eLogInfo, "Daemon: SSU2 disabled");
|
2021-11-27 22:53:53 +03:00
|
|
|
if(!ntcp2) LogPrint(eLogInfo, "Daemon: NTCP2 disabled");
|
2021-02-01 14:36:51 +03:00
|
|
|
|
2022-11-23 03:29:20 +03:00
|
|
|
i2p::transport::transports.Start(ntcp2, ssu2);
|
|
|
|
if (i2p::transport::transports.IsBoundSSU2() || i2p::transport::transports.IsBoundNTCP2())
|
2021-02-01 14:36:51 +03:00
|
|
|
LogPrint(eLogInfo, "Daemon: Transports started");
|
|
|
|
else
|
2014-04-20 05:54:34 +04:00
|
|
|
{
|
2023-03-31 14:29:04 +03:00
|
|
|
LogPrint(eLogCritical, "Daemon: Failed to start Transports");
|
2021-02-01 14:36:51 +03:00
|
|
|
/** shut down netdb right away */
|
|
|
|
i2p::transport::transports.Stop();
|
|
|
|
i2p::data::netdb.Stop();
|
|
|
|
return false;
|
|
|
|
}
|
2016-07-12 03:00:00 +03:00
|
|
|
|
2021-02-01 14:36:51 +03:00
|
|
|
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);
|
2021-11-27 22:53:53 +03:00
|
|
|
LogPrint(eLogInfo, "Daemon: Starting Webconsole at ", httpAddr, ":", httpPort);
|
2021-02-01 14:36:51 +03:00
|
|
|
try
|
2018-11-16 20:49:04 +03:00
|
|
|
{
|
2021-02-01 14:36:51 +03:00
|
|
|
d.httpServer = std::unique_ptr<i2p::http::HTTPServer>(new i2p::http::HTTPServer(httpAddr, httpPort));
|
|
|
|
d.httpServer->Start();
|
2016-07-12 03:00:00 +03:00
|
|
|
}
|
2021-02-01 14:36:51 +03:00
|
|
|
catch (std::exception& ex)
|
2018-11-16 20:49:04 +03:00
|
|
|
{
|
2023-03-31 14:29:04 +03:00
|
|
|
LogPrint (eLogCritical, "Daemon: Failed to start Webconsole: ", ex.what ());
|
2021-02-01 14:36:51 +03:00
|
|
|
ThrowFatal ("Unable to start webconsole at ", httpAddr, ":", httpPort, ": ", ex.what ());
|
2018-11-16 20:49:04 +03:00
|
|
|
}
|
2021-02-01 14:36:51 +03:00
|
|
|
}
|
2018-11-16 20:49:04 +03:00
|
|
|
|
2021-11-27 22:53:53 +03:00
|
|
|
LogPrint(eLogInfo, "Daemon: Starting Tunnels");
|
2021-02-01 14:36:51 +03:00
|
|
|
i2p::tunnel::tunnels.Start();
|
|
|
|
|
2023-02-23 21:58:06 +03:00
|
|
|
LogPrint(eLogInfo, "Daemon: Starting Router context");
|
2023-03-31 14:29:04 +03:00
|
|
|
i2p::context.Start();
|
|
|
|
|
2021-11-27 22:53:53 +03:00
|
|
|
LogPrint(eLogInfo, "Daemon: Starting Client");
|
2021-02-01 14:36:51 +03:00
|
|
|
i2p::client::context.Start ();
|
|
|
|
|
|
|
|
// I2P Control Protocol
|
|
|
|
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);
|
2021-11-27 22:53:53 +03:00
|
|
|
LogPrint(eLogInfo, "Daemon: Starting I2PControl at ", i2pcpAddr, ":", i2pcpPort);
|
2021-02-01 14:36:51 +03:00
|
|
|
try
|
|
|
|
{
|
|
|
|
d.m_I2PControlService = std::unique_ptr<i2p::client::I2PControlService>(new i2p::client::I2PControlService (i2pcpAddr, i2pcpPort));
|
|
|
|
d.m_I2PControlService->Start ();
|
2016-02-03 14:30:00 +03:00
|
|
|
}
|
2021-02-01 14:36:51 +03:00
|
|
|
catch (std::exception& ex)
|
2015-11-03 17:15:49 +03:00
|
|
|
{
|
2023-03-31 14:29:04 +03:00
|
|
|
LogPrint (eLogCritical, "Daemon: Failed to start I2PControl: ", ex.what ());
|
2021-02-01 14:36:51 +03:00
|
|
|
ThrowFatal ("Unable to start I2PControl service at ", i2pcpAddr, ":", i2pcpPort, ": ", ex.what ());
|
2016-10-20 16:12:15 +03:00
|
|
|
}
|
2021-02-01 14:36:51 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2014-08-14 18:20:22 +04:00
|
|
|
|
2021-02-01 14:36:51 +03:00
|
|
|
bool Daemon_Singleton::stop()
|
|
|
|
{
|
2021-11-27 22:53:53 +03:00
|
|
|
LogPrint(eLogInfo, "Daemon: Shutting down");
|
|
|
|
LogPrint(eLogInfo, "Daemon: Stopping Client");
|
2021-02-01 14:36:51 +03:00
|
|
|
i2p::client::context.Stop();
|
2023-02-23 21:58:06 +03:00
|
|
|
LogPrint(eLogInfo, "Daemon: Stopping Router context");
|
|
|
|
i2p::context.Stop();
|
2021-11-27 22:53:53 +03:00
|
|
|
LogPrint(eLogInfo, "Daemon: Stopping Tunnels");
|
2021-02-01 14:36:51 +03:00
|
|
|
i2p::tunnel::tunnels.Stop();
|
|
|
|
|
|
|
|
if (d.UPnP)
|
|
|
|
{
|
|
|
|
d.UPnP->Stop ();
|
|
|
|
d.UPnP = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d.m_NTPSync)
|
|
|
|
{
|
|
|
|
d.m_NTPSync->Stop ();
|
|
|
|
d.m_NTPSync = nullptr;
|
2014-04-20 05:54:34 +04:00
|
|
|
}
|
2021-02-01 14:36:51 +03:00
|
|
|
|
2021-11-27 22:53:53 +03:00
|
|
|
LogPrint(eLogInfo, "Daemon: Stopping Transports");
|
2021-02-01 14:36:51 +03:00
|
|
|
i2p::transport::transports.Stop();
|
2021-11-27 22:53:53 +03:00
|
|
|
LogPrint(eLogInfo, "Daemon: Stopping NetDB");
|
2021-02-01 14:36:51 +03:00
|
|
|
i2p::data::netdb.Stop();
|
|
|
|
if (d.httpServer) {
|
2021-11-27 22:53:53 +03:00
|
|
|
LogPrint(eLogInfo, "Daemon: Stopping HTTP Server");
|
2021-02-01 14:36:51 +03:00
|
|
|
d.httpServer->Stop();
|
|
|
|
d.httpServer = nullptr;
|
|
|
|
}
|
|
|
|
if (d.m_I2PControlService)
|
|
|
|
{
|
2021-11-27 22:53:53 +03:00
|
|
|
LogPrint(eLogInfo, "Daemon: Stopping I2PControl");
|
2021-02-01 14:36:51 +03:00
|
|
|
d.m_I2PControlService->Stop ();
|
|
|
|
d.m_I2PControlService = nullptr;
|
|
|
|
}
|
|
|
|
i2p::crypto::TerminateCrypto ();
|
|
|
|
i2p::log::Logger().Stop();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-11-01 17:26:40 +03:00
|
|
|
}
|
2014-04-23 02:37:24 +04:00
|
|
|
}
|