mirror of https://github.com/PurpleI2P/i2pd.git
I2P: End-to-End encrypted and anonymous Internet
https://i2pd.website/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
147 lines
4.5 KiB
147 lines
4.5 KiB
11 years ago
|
#include <thread>
|
||
|
|
||
11 years ago
|
#include "Daemon.h"
|
||
|
|
||
9 years ago
|
#include "util/Log.h"
|
||
10 years ago
|
#include "version.h"
|
||
9 years ago
|
#include "transport/Transports.h"
|
||
|
#include "transport/NTCPSession.h"
|
||
11 years ago
|
#include "RouterInfo.h"
|
||
|
#include "RouterContext.h"
|
||
9 years ago
|
#include "tunnel/Tunnel.h"
|
||
11 years ago
|
#include "NetDb.h"
|
||
|
#include "Garlic.h"
|
||
9 years ago
|
#include "util/util.h"
|
||
11 years ago
|
#include "Streaming.h"
|
||
10 years ago
|
#include "Destination.h"
|
||
11 years ago
|
#include "HTTPServer.h"
|
||
10 years ago
|
#include "ClientContext.h"
|
||
11 years ago
|
|
||
|
namespace i2p
|
||
|
{
|
||
10 years ago
|
namespace util
|
||
|
{
|
||
|
class Daemon_Singleton::Daemon_Singleton_Private
|
||
|
{
|
||
|
public:
|
||
|
Daemon_Singleton_Private() : httpServer(nullptr)
|
||
|
{};
|
||
|
~Daemon_Singleton_Private()
|
||
|
{
|
||
|
delete httpServer;
|
||
|
};
|
||
|
|
||
|
i2p::util::HTTPServer *httpServer;
|
||
|
};
|
||
|
|
||
|
Daemon_Singleton::Daemon_Singleton() : running(1), d(*new Daemon_Singleton_Private()) {};
|
||
|
Daemon_Singleton::~Daemon_Singleton() {
|
||
|
delete &d;
|
||
|
};
|
||
|
|
||
|
bool Daemon_Singleton::IsService () const
|
||
|
{
|
||
10 years ago
|
#ifndef _WIN32
|
||
10 years ago
|
return i2p::util::config::GetArg("-service", 0);
|
||
10 years ago
|
#else
|
||
10 years ago
|
return false;
|
||
10 years ago
|
#endif
|
||
10 years ago
|
}
|
||
|
|
||
|
bool Daemon_Singleton::init(int argc, char* argv[])
|
||
|
{
|
||
|
i2p::util::config::OptionParser(argc, argv);
|
||
|
i2p::context.Init ();
|
||
|
|
||
|
LogPrint("\n\n\n\ni2pd starting\n");
|
||
|
LogPrint("Version ", VERSION);
|
||
|
LogPrint("data directory: ", i2p::util::filesystem::GetDataDir().string());
|
||
|
i2p::util::filesystem::ReadConfigFile(i2p::util::config::mapArgs, i2p::util::config::mapMultiArgs);
|
||
|
|
||
|
isDaemon = i2p::util::config::GetArg("-daemon", 0);
|
||
|
isLogging = i2p::util::config::GetArg("-log", 1);
|
||
|
|
||
|
int port = i2p::util::config::GetArg("-port", 0);
|
||
|
if (port)
|
||
|
i2p::context.UpdatePort (port);
|
||
|
const char * host = i2p::util::config::GetCharArg("-host", "");
|
||
|
if (host && host[0])
|
||
|
i2p::context.UpdateAddress (boost::asio::ip::address::from_string (host));
|
||
|
|
||
|
i2p::context.SetSupportsV6 (i2p::util::config::GetArg("-v6", 0));
|
||
|
i2p::context.SetFloodfill (i2p::util::config::GetArg("-floodfill", 0));
|
||
|
auto bandwidth = i2p::util::config::GetArg("-bandwidth", "");
|
||
|
if (bandwidth.length () > 0)
|
||
|
{
|
||
|
if (bandwidth[0] > 'L')
|
||
|
i2p::context.SetHighBandwidth ();
|
||
|
else
|
||
|
i2p::context.SetLowBandwidth ();
|
||
|
}
|
||
|
|
||
|
LogPrint("CMD parameters:");
|
||
|
for (int i = 0; i < argc; ++i)
|
||
|
LogPrint(i, " ", argv[i]);
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool Daemon_Singleton::start()
|
||
|
{
|
||
|
// initialize log
|
||
|
if (isLogging)
|
||
|
{
|
||
|
if (isDaemon)
|
||
|
{
|
||
|
std::string logfile_path = IsService () ? "/var/log" : i2p::util::filesystem::GetDataDir().string();
|
||
10 years ago
|
#ifndef _WIN32
|
||
10 years ago
|
logfile_path.append("/i2pd.log");
|
||
10 years ago
|
#else
|
||
10 years ago
|
logfile_path.append("\\i2pd.log");
|
||
10 years ago
|
#endif
|
||
10 years ago
|
StartLog (logfile_path);
|
||
|
}
|
||
|
else
|
||
|
StartLog (""); // write to stdout
|
||
|
}
|
||
|
|
||
9 years ago
|
d.httpServer = new i2p::util::HTTPServer(
|
||
|
i2p::util::config::GetArg("-httpaddress", "127.0.0.1"),
|
||
|
i2p::util::config::GetArg("-httpport", 7070)
|
||
|
);
|
||
10 years ago
|
d.httpServer->Start();
|
||
|
LogPrint("HTTP Server started");
|
||
|
i2p::data::netdb.Start();
|
||
|
LogPrint("NetDB started");
|
||
|
i2p::transport::transports.Start();
|
||
|
LogPrint("Transports started");
|
||
|
i2p::tunnel::tunnels.Start();
|
||
|
LogPrint("Tunnels started");
|
||
|
i2p::client::context.Start ();
|
||
|
LogPrint("Client started");
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool Daemon_Singleton::stop()
|
||
|
{
|
||
|
LogPrint("Shutdown started.");
|
||
|
i2p::client::context.Stop();
|
||
|
LogPrint("Client stopped");
|
||
|
i2p::tunnel::tunnels.Stop();
|
||
|
LogPrint("Tunnels stopped");
|
||
|
i2p::transport::transports.Stop();
|
||
|
LogPrint("Transports stopped");
|
||
|
i2p::data::netdb.Stop();
|
||
|
LogPrint("NetDB stopped");
|
||
|
d.httpServer->Stop();
|
||
|
LogPrint("HTTP Server stopped");
|
||
|
|
||
|
StopLog ();
|
||
|
|
||
|
delete d.httpServer; d.httpServer = nullptr;
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
11 years ago
|
}
|