ls;
+ if (storeType == dotnet::data::NETDB_STORE_TYPE_LEASESET)
+ ls.reset (new dotnet::data::LeaseSet (leaseSet->GetBuffer(), leaseSet->GetBufferLen()));
else
- ls.reset (new i2p::data::LeaseSet2 (storeType, leaseSet->GetBuffer(), leaseSet->GetBufferLen()));
+ ls.reset (new dotnet::data::LeaseSet2 (storeType, leaseSet->GetBuffer(), leaseSet->GetBufferLen()));
if (!ls) return;
s << "\r\n\r\n";
s << "Store type: " << (int)storeType << "
\r\n";
s << "Expires: " << ConvertTime(ls->GetExpirationTime()) << "
\r\n";
- if (storeType == i2p::data::NETDB_STORE_TYPE_LEASESET || storeType == i2p::data::NETDB_STORE_TYPE_STANDARD_LEASESET2)
+ if (storeType == dotnet::data::NETDB_STORE_TYPE_LEASESET || storeType == dotnet::data::NETDB_STORE_TYPE_STANDARD_LEASESET2)
{
// leases information is available
auto leases = ls->GetNonExpiredLeases();
@@ -500,12 +500,12 @@ namespace http {
void ShowTunnels (std::stringstream& s)
{
s << "Tunnels:
\r\n
\r\n";
- s << "Queue size: " << i2p::tunnel::tunnels.GetQueueSize () << "
\r\n";
+ s << "Queue size: " << dotnet::tunnel::tunnels.GetQueueSize () << "
\r\n";
- auto ExplPool = i2p::tunnel::tunnels.GetExploratoryPool ();
+ auto ExplPool = dotnet::tunnel::tunnels.GetExploratoryPool ();
s << "Inbound tunnels:
\r\n";
- for (auto & it : i2p::tunnel::tunnels.GetInboundTunnels ()) {
+ for (auto & it : dotnet::tunnel::tunnels.GetInboundTunnels ()) {
it->Print(s);
if(it->LatencyIsKnown())
s << " ( " << it->GetMeanLatency() << "ms )";
@@ -513,7 +513,7 @@ namespace http {
}
s << "
\r\n";
s << "Outbound tunnels:
\r\n";
- for (auto & it : i2p::tunnel::tunnels.GetOutboundTunnels ()) {
+ for (auto & it : dotnet::tunnel::tunnels.GetOutboundTunnels ()) {
it->Print(s);
if(it->LatencyIsKnown())
s << " ( " << it->GetMeanLatency() << "ms )";
@@ -524,12 +524,12 @@ namespace http {
static void ShowCommands (std::stringstream& s, uint32_t token)
{
- std::string webroot; i2p::config::GetOption("http.webroot", webroot);
+ std::string webroot; dotnet::config::GetOption("http.webroot", webroot);
/* commands */
s << "Router Commands
\r\n
\r\n";
s << " Run peer test
\r\n";
//s << " Reload config
\r\n";
- if (i2p::context.AcceptsTunnels ())
+ if (dotnet::context.AcceptsTunnels ())
s << " Decline transit tunnels
\r\n";
else
s << " Accept transit tunnels
\r\n";
@@ -539,7 +539,7 @@ namespace http {
else
s << " Start graceful shutdown
\r\n";
#elif defined(WIN32_APP)
- if (i2p::util::DaemonWin32::Instance().isGraceful)
+ if (dotnet::util::DaemonWin32::Instance().isGraceful)
s << " Cancel graceful shutdown
";
else
s << " Graceful shutdown
\r\n";
@@ -557,11 +557,11 @@ namespace http {
void ShowTransitTunnels (std::stringstream& s)
{
s << "Transit tunnels:
\r\n
\r\n";
- for (const auto& it: i2p::tunnel::tunnels.GetTransitTunnels ())
+ for (const auto& it: dotnet::tunnel::tunnels.GetTransitTunnels ())
{
- if (std::dynamic_pointer_cast(it))
+ if (std::dynamic_pointer_cast(it))
s << it->GetTunnelID () << " ⇒ ";
- else if (std::dynamic_pointer_cast(it))
+ else if (std::dynamic_pointer_cast(it))
s << " ⇒ " << it->GetTunnelID ();
else
s << " ⇒ " << it->GetTunnelID () << " ⇒ ";
@@ -579,7 +579,7 @@ namespace http {
{
// incoming connection doesn't have remote RI
if (it.second->IsOutgoing ()) tmp_s << " ⇒ ";
- tmp_s << i2p::data::GetIdentHashAbbreviation (it.second->GetRemoteIdentity ()->GetIdentHash ()) << ": "
+ tmp_s << dotnet::data::GetIdentHashAbbreviation (it.second->GetRemoteIdentity ()->GetIdentHash ()) << ": "
<< it.second->GetSocket ().remote_endpoint().address ().to_string ();
if (!it.second->IsOutgoing ()) tmp_s << " ⇒ ";
tmp_s << " [" << it.second->GetNumSentBytes () << ":" << it.second->GetNumReceivedBytes () << "]";
@@ -589,7 +589,7 @@ namespace http {
if (it.second && it.second->IsEstablished () && it.second->GetSocket ().remote_endpoint ().address ().is_v6 ())
{
if (it.second->IsOutgoing ()) tmp_s6 << " ⇒ ";
- tmp_s6 << i2p::data::GetIdentHashAbbreviation (it.second->GetRemoteIdentity ()->GetIdentHash ()) << ": "
+ tmp_s6 << dotnet::data::GetIdentHashAbbreviation (it.second->GetRemoteIdentity ()->GetIdentHash ()) << ": "
<< "[" << it.second->GetSocket ().remote_endpoint().address ().to_string () << "]";
if (!it.second->IsOutgoing ()) tmp_s6 << " ⇒ ";
tmp_s6 << " [" << it.second->GetNumSentBytes () << ":" << it.second->GetNumReceivedBytes () << "]";
@@ -612,21 +612,21 @@ namespace http {
void ShowTransports (std::stringstream& s)
{
s << "Transports:
\r\n
\r\n";
- auto ntcpServer = i2p::transport::transports.GetNTCPServer ();
+ auto ntcpServer = dotnet::transport::transports.GetNTCPServer ();
if (ntcpServer)
{
auto sessions = ntcpServer->GetNTCPSessions ();
if (!sessions.empty ())
ShowNTCPTransports (s, sessions, "NTCP");
}
- auto ntcp2Server = i2p::transport::transports.GetNTCP2Server ();
+ auto ntcp2Server = dotnet::transport::transports.GetNTCP2Server ();
if (ntcp2Server)
{
auto sessions = ntcp2Server->GetNTCP2Sessions ();
if (!sessions.empty ())
ShowNTCPTransports (s, sessions, "NTCP2");
}
- auto ssuServer = i2p::transport::transports.GetSSUServer ();
+ auto ssuServer = dotnet::transport::transports.GetSSUServer ();
if (ssuServer)
{
auto sessions = ssuServer->GetSessions ();
@@ -668,8 +668,8 @@ namespace http {
void ShowSAMSessions (std::stringstream& s)
{
- std::string webroot; i2p::config::GetOption("http.webroot", webroot);
- auto sam = i2p::client::context.GetSAMBridge ();
+ std::string webroot; dotnet::config::GetOption("http.webroot", webroot);
+ auto sam = dotnet::client::context.GetSAMBridge ();
if (!sam) {
ShowError(s, "SAM disabled");
return;
@@ -685,9 +685,9 @@ namespace http {
static void ShowSAMSession (std::stringstream& s, const std::string& id)
{
- std::string webroot; i2p::config::GetOption("http.webroot", webroot);
+ std::string webroot; dotnet::config::GetOption("http.webroot", webroot);
s << "SAM Session:
\r\n
\r\n";
- auto sam = i2p::client::context.GetSAMBridge ();
+ auto sam = dotnet::client::context.GetSAMBridge ();
if (!sam) {
ShowError(s, "SAM disabled");
return;
@@ -699,16 +699,16 @@ namespace http {
}
auto& ident = session->localDestination->GetIdentHash();
s << "";
- s << i2p::client::context.GetAddressBook ().ToAddress(ident) << "
\r\n";
+ s << dotnet::client::context.GetAddressBook ().ToAddress(ident) << "
\r\n";
s << "
\r\n";
s << "Streams:
\r\n";
for (const auto& it: sam->ListSockets(id))
{
switch (it->GetSocketType ())
{
- case i2p::client::eSAMSocketTypeSession : s << "session"; break;
- case i2p::client::eSAMSocketTypeStream : s << "stream"; break;
- case i2p::client::eSAMSocketTypeAcceptor : s << "acceptor"; break;
+ case dotnet::client::eSAMSocketTypeSession : s << "session"; break;
+ case dotnet::client::eSAMSocketTypeStream : s << "stream"; break;
+ case dotnet::client::eSAMSocketTypeAcceptor : s << "acceptor"; break;
default: s << "unknown"; break;
}
s << " [" << it->GetSocket ().remote_endpoint() << "]";
@@ -716,37 +716,37 @@ namespace http {
}
}
- void ShowI2PTunnels (std::stringstream& s)
+ void ShowDotNetTunnels (std::stringstream& s)
{
- std::string webroot; i2p::config::GetOption("http.webroot", webroot);
+ std::string webroot; dotnet::config::GetOption("http.webroot", webroot);
s << "Client Tunnels:
\r\n
\r\n";
- for (auto& it: i2p::client::context.GetClientTunnels ())
+ for (auto& it: dotnet::client::context.GetClientTunnels ())
{
auto& ident = it.second->GetLocalDestination ()->GetIdentHash();
s << "";
s << it.second->GetName () << " ⇐ ";
- s << i2p::client::context.GetAddressBook ().ToAddress(ident);
+ s << dotnet::client::context.GetAddressBook ().ToAddress(ident);
s << "
\r\n"<< std::endl;
}
- auto httpProxy = i2p::client::context.GetHttpProxy ();
+ auto httpProxy = dotnet::client::context.GetHttpProxy ();
if (httpProxy)
{
auto& ident = httpProxy->GetLocalDestination ()->GetIdentHash();
s << "";
s << "HTTP Proxy" << " ⇐ ";
- s << i2p::client::context.GetAddressBook ().ToAddress(ident);
+ s << dotnet::client::context.GetAddressBook ().ToAddress(ident);
s << "
\r\n"<< std::endl;
}
- auto socksProxy = i2p::client::context.GetSocksProxy ();
+ auto socksProxy = dotnet::client::context.GetSocksProxy ();
if (socksProxy)
{
auto& ident = socksProxy->GetLocalDestination ()->GetIdentHash();
s << "";
s << "SOCKS Proxy" << " ⇐ ";
- s << i2p::client::context.GetAddressBook ().ToAddress(ident);
+ s << dotnet::client::context.GetAddressBook ().ToAddress(ident);
s << "
\r\n"<< std::endl;
}
- auto& serverTunnels = i2p::client::context.GetServerTunnels ();
+ auto& serverTunnels = dotnet::client::context.GetServerTunnels ();
if (!serverTunnels.empty ()) {
s << "
\r\nServer Tunnels:
\r\n
\r\n";
for (auto& it: serverTunnels)
@@ -754,12 +754,12 @@ namespace http {
auto& ident = it.second->GetLocalDestination ()->GetIdentHash();
s << "";
s << it.second->GetName () << " ⇒ ";
- s << i2p::client::context.GetAddressBook ().ToAddress(ident);
+ s << dotnet::client::context.GetAddressBook ().ToAddress(ident);
s << ":" << it.second->GetLocalPort ();
s << "
\r\n"<< std::endl;
}
}
- auto& clientForwards = i2p::client::context.GetClientForwards ();
+ auto& clientForwards = dotnet::client::context.GetClientForwards ();
if (!clientForwards.empty ())
{
s << "
\r\nClient Forwards:
\r\n
\r\n";
@@ -768,11 +768,11 @@ namespace http {
auto& ident = it.second->GetLocalDestination ()->GetIdentHash();
s << "";
s << it.second->GetName () << " ⇐ ";
- s << i2p::client::context.GetAddressBook ().ToAddress(ident);
+ s << dotnet::client::context.GetAddressBook ().ToAddress(ident);
s << "
\r\n"<< std::endl;
}
}
- auto& serverForwards = i2p::client::context.GetServerForwards ();
+ auto& serverForwards = dotnet::client::context.GetServerForwards ();
if (!serverForwards.empty ())
{
s << "
\r\nServer Forwards:
\r\n
\r\n";
@@ -781,7 +781,7 @@ namespace http {
auto& ident = it.second->GetLocalDestination ()->GetIdentHash();
s << "";
s << it.second->GetName () << " ⇐ ";
- s << i2p::client::context.GetAddressBook ().ToAddress(ident);
+ s << dotnet::client::context.GetAddressBook ().ToAddress(ident);
s << "
\r\n"<< std::endl;
}
}
@@ -801,9 +801,9 @@ namespace http {
m_Socket (socket), m_BufferLen (0), expected_host(hostname)
{
/* cache options */
- i2p::config::GetOption("http.auth", needAuth);
- i2p::config::GetOption("http.user", user);
- i2p::config::GetOption("http.pass", pass);
+ dotnet::config::GetOption("http.auth", needAuth);
+ dotnet::config::GetOption("http.user", user);
+ dotnet::config::GetOption("http.pass", pass);
}
void HTTPConnection::Receive ()
@@ -861,7 +861,7 @@ namespace http {
auto provided = req.GetHeader ("Authorization");
if (provided.length () > 0)
{
- std::string expected = "Basic " + i2p::data::ToBase64Standard (user + ":" + pass);
+ std::string expected = "Basic " + dotnet::data::ToBase64Standard (user + ":" + pass);
if (expected == provided) return true;
}
@@ -884,11 +884,11 @@ namespace http {
return;
}
bool strictheaders;
- i2p::config::GetOption("http.strictheaders", strictheaders);
+ dotnet::config::GetOption("http.strictheaders", strictheaders);
if (strictheaders)
{
std::string http_hostname;
- i2p::config::GetOption("http.hostname", http_hostname);
+ dotnet::config::GetOption("http.hostname", http_hostname);
std::string host = req.GetHeader("Host");
auto idx = host.find(':');
/* strip out port so it's just host */
@@ -912,7 +912,7 @@ namespace http {
} else if (req.uri.find("cmd=") != std::string::npos) {
HandleCommand (req, res, s);
} else {
- ShowStatus (s, true, i2p::http::OutputFormatEnum::forWebConsole);
+ ShowStatus (s, true, dotnet::http::OutputFormatEnum::forWebConsole);
res.add_header("Refresh", "10");
}
ShowPageTail (s);
@@ -942,7 +942,7 @@ namespace http {
uint32_t token;
RAND_bytes ((uint8_t *)&token, 4);
token &= 0x7FFFFFFF; // clear first bit
- auto ts = i2p::util::GetSecondsSinceEpoch ();
+ auto ts = dotnet::util::GetSecondsSinceEpoch ();
for (auto it = m_Tokens.begin (); it != m_Tokens.end (); )
{
if (ts > it->second + TOKEN_EXPIRATION_TIMEOUT)
@@ -959,14 +959,14 @@ namespace http {
ShowLocalDestinations (s);
else if (page == HTTP_PAGE_LOCAL_DESTINATION)
ShowLocalDestination (s, params["b32"]);
- else if (page == HTTP_PAGE_I2CP_LOCAL_DESTINATION)
- ShowI2CPLocalDestination (s, params["i2cp_id"]);
+ else if (page == HTTP_PAGE_DNCP_LOCAL_DESTINATION)
+ ShowDNCPLocalDestination (s, params["dncp_id"]);
else if (page == HTTP_PAGE_SAM_SESSIONS)
ShowSAMSessions (s);
else if (page == HTTP_PAGE_SAM_SESSION)
ShowSAMSession (s, params["sam_id"]);
- else if (page == HTTP_PAGE_I2P_TUNNELS)
- ShowI2PTunnels (s);
+ else if (page == HTTP_PAGE_DOTNET_TUNNELS)
+ ShowDotNetTunnels (s);
else if (page == HTTP_PAGE_LEASESETS)
ShowLeasesSets(s);
else {
@@ -993,32 +993,32 @@ namespace http {
std::string cmd = params["cmd"];
if (cmd == HTTP_COMMAND_RUN_PEER_TEST)
- i2p::transport::transports.PeerTest ();
+ dotnet::transport::transports.PeerTest ();
else if (cmd == HTTP_COMMAND_RELOAD_CONFIG)
- i2p::client::context.ReloadConfig ();
+ dotnet::client::context.ReloadConfig ();
else if (cmd == HTTP_COMMAND_ENABLE_TRANSIT)
- i2p::context.SetAcceptsTunnels (true);
+ dotnet::context.SetAcceptsTunnels (true);
else if (cmd == HTTP_COMMAND_DISABLE_TRANSIT)
- i2p::context.SetAcceptsTunnels (false);
+ dotnet::context.SetAcceptsTunnels (false);
else if (cmd == HTTP_COMMAND_SHUTDOWN_START) {
- i2p::context.SetAcceptsTunnels (false);
+ dotnet::context.SetAcceptsTunnels (false);
#if ((!defined(WIN32) && !defined(QT_GUI_LIB) && !defined(ANDROID)) || defined(ANDROID_BINARY))
Daemon.gracefulShutdownInterval = 10*60;
#elif defined(WIN32_APP)
- i2p::win32::GracefulShutdown ();
+ dotnet::win32::GracefulShutdown ();
#endif
} else if (cmd == HTTP_COMMAND_SHUTDOWN_CANCEL) {
- i2p::context.SetAcceptsTunnels (true);
+ dotnet::context.SetAcceptsTunnels (true);
#if ((!defined(WIN32) && !defined(QT_GUI_LIB) && !defined(ANDROID)) || defined(ANDROID_BINARY))
Daemon.gracefulShutdownInterval = 0;
#elif defined(WIN32_APP)
- i2p::win32::StopGracefulShutdown ();
+ dotnet::win32::StopGracefulShutdown ();
#endif
} else if (cmd == HTTP_COMMAND_SHUTDOWN_NOW) {
#ifndef WIN32_APP
Daemon.running = false;
#else
- i2p::win32::StopWin32App ();
+ dotnet::win32::StopWin32App ();
#endif
} else if (cmd == HTTP_COMMAND_LOGLEVEL){
std::string level = params["level"];
@@ -1028,7 +1028,7 @@ namespace http {
ShowError(s, "Unknown command: " + cmd);
return;
}
- std::string webroot; i2p::config::GetOption("http.webroot", webroot);
+ std::string webroot; dotnet::config::GetOption("http.webroot", webroot);
std::string redirect = "5; url=" + webroot + "?page=commands";
s << "SUCCESS: Command accepted
\r\n";
s << "Back to commands list
\r\n";
@@ -1061,9 +1061,9 @@ namespace http {
void HTTPServer::Start ()
{
- bool needAuth; i2p::config::GetOption("http.auth", needAuth);
- std::string user; i2p::config::GetOption("http.user", user);
- std::string pass; i2p::config::GetOption("http.pass", pass);
+ bool needAuth; dotnet::config::GetOption("http.auth", needAuth);
+ std::string user; dotnet::config::GetOption("http.user", user);
+ std::string pass; dotnet::config::GetOption("http.pass", pass);
/* generate pass if needed */
if (needAuth && pass == "") {
uint8_t random[16];
@@ -1075,7 +1075,7 @@ namespace http {
for (size_t i = 0; i < sizeof(random); i++) {
pass[i] = alnum[random[i] % (sizeof(alnum) - 1)];
}
- i2p::config::SetOption("http.pass", pass);
+ dotnet::config::SetOption("http.pass", pass);
LogPrint(eLogInfo, "HTTPServer: password set to ", pass);
}
m_IsRunning = true;
@@ -1139,4 +1139,4 @@ namespace http {
conn->Receive ();
}
} // http
-} // i2p
+} // dotnet
diff --git a/daemon/HTTPServer.h b/daemon/HTTPServer.h
index 3d32ed2b..661fab9b 100644
--- a/daemon/HTTPServer.h
+++ b/daemon/HTTPServer.h
@@ -10,7 +10,7 @@
#include
#include "HTTP.h"
-namespace i2p
+namespace dotnet
{
namespace http
{
@@ -87,9 +87,9 @@ namespace http
void ShowTransitTunnels (std::stringstream& s);
void ShowTransports (std::stringstream& s);
void ShowSAMSessions (std::stringstream& s);
- void ShowI2PTunnels (std::stringstream& s);
+ void ShowDotNetTunnels (std::stringstream& s);
void ShowLocalDestination (std::stringstream& s, const std::string& b32);
} // http
-} // i2p
+} // dotnet
#endif /* HTTP_SERVER_H__ */
diff --git a/daemon/I2PControl.cpp b/daemon/I2PControl.cpp
deleted file mode 100644
index 572292ee..00000000
--- a/daemon/I2PControl.cpp
+++ /dev/null
@@ -1,780 +0,0 @@
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-// There is bug in boost 1.49 with gcc 4.7 coming with Debian Wheezy
-#define GCC47_BOOST149 ((BOOST_VERSION == 104900) && (__GNUC__ == 4) && (__GNUC_MINOR__ >= 7))
-#if !GCC47_BOOST149
-#include
-#endif
-
-#include "Crypto.h"
-#include "FS.h"
-#include "Log.h"
-#include "Config.h"
-#include "NetDb.hpp"
-#include "RouterContext.h"
-#include "Daemon.h"
-#include "Tunnel.h"
-#include "Timestamp.h"
-#include "Transports.h"
-#include "version.h"
-#include "util.h"
-#include "ClientContext.h"
-#include "I2PControl.h"
-
-namespace i2p
-{
-namespace client
-{
- I2PControlService::I2PControlService (const std::string& address, int port):
- m_IsRunning (false), m_Thread (nullptr),
- m_Acceptor (m_Service, boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(address), port)),
- m_SSLContext (boost::asio::ssl::context::sslv23),
- m_ShutdownTimer (m_Service)
- {
- i2p::config::GetOption("i2pcontrol.password", m_Password);
-
- // certificate / keys
- std::string i2pcp_crt; i2p::config::GetOption("i2pcontrol.cert", i2pcp_crt);
- std::string i2pcp_key; i2p::config::GetOption("i2pcontrol.key", i2pcp_key);
-
- if (i2pcp_crt.at(0) != '/')
- i2pcp_crt = i2p::fs::DataDirPath(i2pcp_crt);
- if (i2pcp_key.at(0) != '/')
- i2pcp_key = i2p::fs::DataDirPath(i2pcp_key);
- if (!i2p::fs::Exists (i2pcp_crt) || !i2p::fs::Exists (i2pcp_key)) {
- LogPrint (eLogInfo, "I2PControl: creating new certificate for control connection");
- CreateCertificate (i2pcp_crt.c_str(), i2pcp_key.c_str());
- } else {
- LogPrint(eLogDebug, "I2PControl: using cert from ", i2pcp_crt);
- }
- m_SSLContext.set_options (boost::asio::ssl::context::default_workarounds | boost::asio::ssl::context::no_sslv2 | boost::asio::ssl::context::single_dh_use);
- m_SSLContext.use_certificate_file (i2pcp_crt, boost::asio::ssl::context::pem);
- m_SSLContext.use_private_key_file (i2pcp_key, boost::asio::ssl::context::pem);
-
- // handlers
- m_MethodHandlers["Authenticate"] = &I2PControlService::AuthenticateHandler;
- m_MethodHandlers["Echo"] = &I2PControlService::EchoHandler;
- m_MethodHandlers["I2PControl"] = &I2PControlService::I2PControlHandler;
- m_MethodHandlers["RouterInfo"] = &I2PControlService::RouterInfoHandler;
- m_MethodHandlers["RouterManager"] = &I2PControlService::RouterManagerHandler;
- m_MethodHandlers["NetworkSetting"] = &I2PControlService::NetworkSettingHandler;
- m_MethodHandlers["ClientServicesInfo"] = &I2PControlService::ClientServicesInfoHandler;
-
- // I2PControl
- m_I2PControlHandlers["i2pcontrol.password"] = &I2PControlService::PasswordHandler;
-
- // RouterInfo
- m_RouterInfoHandlers["i2p.router.uptime"] = &I2PControlService::UptimeHandler;
- m_RouterInfoHandlers["i2p.router.version"] = &I2PControlService::VersionHandler;
- m_RouterInfoHandlers["i2p.router.status"] = &I2PControlService::StatusHandler;
- m_RouterInfoHandlers["i2p.router.netdb.knownpeers"] = &I2PControlService::NetDbKnownPeersHandler;
- m_RouterInfoHandlers["i2p.router.netdb.activepeers"] = &I2PControlService::NetDbActivePeersHandler;
- m_RouterInfoHandlers["i2p.router.net.bw.inbound.1s"] = &I2PControlService::InboundBandwidth1S;
- m_RouterInfoHandlers["i2p.router.net.bw.outbound.1s"] = &I2PControlService::OutboundBandwidth1S;
- m_RouterInfoHandlers["i2p.router.net.status"] = &I2PControlService::NetStatusHandler;
- m_RouterInfoHandlers["i2p.router.net.tunnels.participating"] = &I2PControlService::TunnelsParticipatingHandler;
- m_RouterInfoHandlers["i2p.router.net.tunnels.successrate"] =
-&I2PControlService::TunnelsSuccessRateHandler;
- m_RouterInfoHandlers["i2p.router.net.total.received.bytes"] = &I2PControlService::NetTotalReceivedBytes;
- m_RouterInfoHandlers["i2p.router.net.total.sent.bytes"] = &I2PControlService::NetTotalSentBytes;
-
- // RouterManager
- m_RouterManagerHandlers["Reseed"] = &I2PControlService::ReseedHandler;
- m_RouterManagerHandlers["Shutdown"] = &I2PControlService::ShutdownHandler;
- m_RouterManagerHandlers["ShutdownGraceful"] = &I2PControlService::ShutdownGracefulHandler;
-
- // NetworkSetting
- m_NetworkSettingHandlers["i2p.router.net.bw.in"] = &I2PControlService::InboundBandwidthLimit;
- m_NetworkSettingHandlers["i2p.router.net.bw.out"] = &I2PControlService::OutboundBandwidthLimit;
-
- // ClientServicesInfo
- m_ClientServicesInfoHandlers["I2PTunnel"] = &I2PControlService::I2PTunnelInfoHandler;
- m_ClientServicesInfoHandlers["HTTPProxy"] = &I2PControlService::HTTPProxyInfoHandler;
- m_ClientServicesInfoHandlers["SOCKS"] = &I2PControlService::SOCKSInfoHandler;
- m_ClientServicesInfoHandlers["SAM"] = &I2PControlService::SAMInfoHandler;
- m_ClientServicesInfoHandlers["BOB"] = &I2PControlService::BOBInfoHandler;
- m_ClientServicesInfoHandlers["I2CP"] = &I2PControlService::I2CPInfoHandler;
- }
-
- I2PControlService::~I2PControlService ()
- {
- Stop ();
- }
-
- void I2PControlService::Start ()
- {
- if (!m_IsRunning)
- {
- Accept ();
- m_IsRunning = true;
- m_Thread = new std::thread (std::bind (&I2PControlService::Run, this));
- }
- }
-
- void I2PControlService::Stop ()
- {
- if (m_IsRunning)
- {
- m_IsRunning = false;
- m_Acceptor.cancel ();
- m_Service.stop ();
- if (m_Thread)
- {
- m_Thread->join ();
- delete m_Thread;
- m_Thread = nullptr;
- }
- }
- }
-
- void I2PControlService::Run ()
- {
- while (m_IsRunning)
- {
- try {
- m_Service.run ();
- } catch (std::exception& ex) {
- LogPrint (eLogError, "I2PControl: runtime exception: ", ex.what ());
- }
- }
- }
-
- void I2PControlService::Accept ()
- {
- auto newSocket = std::make_shared (m_Service, m_SSLContext);
- m_Acceptor.async_accept (newSocket->lowest_layer(), std::bind (&I2PControlService::HandleAccept, this,
- std::placeholders::_1, newSocket));
- }
-
- void I2PControlService::HandleAccept(const boost::system::error_code& ecode, std::shared_ptr socket)
- {
- if (ecode != boost::asio::error::operation_aborted)
- Accept ();
-
- if (ecode) {
- LogPrint (eLogError, "I2PControl: accept error: ", ecode.message ());
- return;
- }
- LogPrint (eLogDebug, "I2PControl: new request from ", socket->lowest_layer ().remote_endpoint ());
- Handshake (socket);
- }
-
- void I2PControlService::Handshake (std::shared_ptr socket)
- {
- socket->async_handshake(boost::asio::ssl::stream_base::server,
- std::bind( &I2PControlService::HandleHandshake, this, std::placeholders::_1, socket));
- }
-
- void I2PControlService::HandleHandshake (const boost::system::error_code& ecode, std::shared_ptr socket)
- {
- if (ecode) {
- LogPrint (eLogError, "I2PControl: handshake error: ", ecode.message ());
- return;
- }
- //std::this_thread::sleep_for (std::chrono::milliseconds(5));
- ReadRequest (socket);
- }
-
- void I2PControlService::ReadRequest (std::shared_ptr socket)
- {
- auto request = std::make_shared();
- socket->async_read_some (
-#if defined(BOOST_ASIO_HAS_STD_ARRAY)
- boost::asio::buffer (*request),
-#else
- boost::asio::buffer (request->data (), request->size ()),
-#endif
- std::bind(&I2PControlService::HandleRequestReceived, this,
- std::placeholders::_1, std::placeholders::_2, socket, request));
- }
-
- void I2PControlService::HandleRequestReceived (const boost::system::error_code& ecode,
- size_t bytes_transferred, std::shared_ptr socket,
- std::shared_ptr buf)
- {
- if (ecode)
- {
- LogPrint (eLogError, "I2PControl: read error: ", ecode.message ());
- return;
- }
- else
- {
- bool isHtml = !memcmp (buf->data (), "POST", 4);
- try
- {
- std::stringstream ss;
- ss.write (buf->data (), bytes_transferred);
- if (isHtml)
- {
- std::string header;
- size_t contentLength = 0;
- while (!ss.eof () && header != "\r")
- {
- std::getline(ss, header);
- auto colon = header.find (':');
- if (colon != std::string::npos && header.substr (0, colon) == "Content-Length")
- contentLength = std::stoi (header.substr (colon + 1));
- }
- if (ss.eof ())
- {
- LogPrint (eLogError, "I2PControl: malformed request, HTTP header expected");
- return; // TODO:
- }
- std::streamoff rem = contentLength + ss.tellg () - bytes_transferred; // more bytes to read
- if (rem > 0)
- {
- bytes_transferred = boost::asio::read (*socket, boost::asio::buffer (buf->data (), rem));
- ss.write (buf->data (), bytes_transferred);
- }
- }
- std::ostringstream response;
-#if GCC47_BOOST149
- LogPrint (eLogError, "I2PControl: json_read is not supported due bug in boost 1.49 with gcc 4.7");
- response << "{\"id\":null,\"error\":";
- response << "{\"code\":-32603,\"message\":\"JSON requests is not supported with this version of boost\"},";
- response << "\"jsonrpc\":\"2.0\"}";
-#else
- boost::property_tree::ptree pt;
- boost::property_tree::read_json (ss, pt);
-
- std::string id = pt.get("id");
- std::string method = pt.get("method");
- auto it = m_MethodHandlers.find (method);
- if (it != m_MethodHandlers.end ())
- {
- response << "{\"id\":" << id << ",\"result\":{";
- (this->*(it->second))(pt.get_child ("params"), response);
- response << "},\"jsonrpc\":\"2.0\"}";
- }
- else
- {
- LogPrint (eLogWarning, "I2PControl: unknown method ", method);
- response << "{\"id\":null,\"error\":";
- response << "{\"code\":-32601,\"message\":\"Method not found\"},";
- response << "\"jsonrpc\":\"2.0\"}";
- }
-#endif
- SendResponse (socket, buf, response, isHtml);
- }
- catch (std::exception& ex)
- {
- LogPrint (eLogError, "I2PControl: exception when handle request: ", ex.what ());
- std::ostringstream response;
- response << "{\"id\":null,\"error\":";
- response << "{\"code\":-32700,\"message\":\"" << ex.what () << "\"},";
- response << "\"jsonrpc\":\"2.0\"}";
- SendResponse (socket, buf, response, isHtml);
- }
- catch (...)
- {
- LogPrint (eLogError, "I2PControl: handle request unknown exception");
- }
- }
- }
-
- void I2PControlService::InsertParam (std::ostringstream& ss, const std::string& name, int value) const
- {
- ss << "\"" << name << "\":" << value;
- }
-
- void I2PControlService::InsertParam (std::ostringstream& ss, const std::string& name, const std::string& value) const
- {
- ss << "\"" << name << "\":";
- if (value.length () > 0)
- ss << "\"" << value << "\"";
- else
- ss << "null";
- }
-
- void I2PControlService::InsertParam (std::ostringstream& ss, const std::string& name, double value) const
- {
- ss << "\"" << name << "\":" << std::fixed << std::setprecision(2) << value;
- }
-
- void I2PControlService::InsertParam (std::ostringstream& ss, const std::string& name, const boost::property_tree::ptree& value) const
- {
- std::ostringstream buf;
- boost::property_tree::write_json (buf, value, false);
- ss << "\"" << name << "\":" << buf.str();
- }
-
- void I2PControlService::SendResponse (std::shared_ptr socket,
- std::shared_ptr buf, std::ostringstream& response, bool isHtml)
- {
- size_t len = response.str ().length (), offset = 0;
- if (isHtml)
- {
- std::ostringstream header;
- header << "HTTP/1.1 200 OK\r\n";
- header << "Connection: close\r\n";
- header << "Content-Length: " << boost::lexical_cast(len) << "\r\n";
- header << "Content-Type: application/json\r\n";
- header << "Date: ";
- auto facet = new boost::local_time::local_time_facet ("%a, %d %b %Y %H:%M:%S GMT");
- header.imbue(std::locale (header.getloc(), facet));
- header << boost::posix_time::second_clock::local_time() << "\r\n";
- header << "\r\n";
- offset = header.str ().size ();
- memcpy (buf->data (), header.str ().c_str (), offset);
- }
- memcpy (buf->data () + offset, response.str ().c_str (), len);
- boost::asio::async_write (*socket, boost::asio::buffer (buf->data (), offset + len),
- boost::asio::transfer_all (),
- std::bind(&I2PControlService::HandleResponseSent, this,
- std::placeholders::_1, std::placeholders::_2, socket, buf));
- }
-
- void I2PControlService::HandleResponseSent (const boost::system::error_code& ecode, std::size_t bytes_transferred,
- std::shared_ptr socket, std::shared_ptr buf)
- {
- if (ecode) {
- LogPrint (eLogError, "I2PControl: write error: ", ecode.message ());
- }
- }
-
-// handlers
-
- void I2PControlService::AuthenticateHandler (const boost::property_tree::ptree& params, std::ostringstream& results)
- {
- int api = params.get ("API");
- auto password = params.get ("Password");
- LogPrint (eLogDebug, "I2PControl: Authenticate API=", api, " Password=", password);
- if (password != m_Password) {
- LogPrint (eLogError, "I2PControl: Authenticate - Invalid password: ", password);
- return;
- }
- InsertParam (results, "API", api);
- results << ",";
- std::string token = boost::lexical_cast(i2p::util::GetSecondsSinceEpoch ());
- m_Tokens.insert (token);
- InsertParam (results, "Token", token);
- }
-
- void I2PControlService::EchoHandler (const boost::property_tree::ptree& params, std::ostringstream& results)
- {
- auto echo = params.get ("Echo");
- LogPrint (eLogDebug, "I2PControl Echo Echo=", echo);
- InsertParam (results, "Result", echo);
- }
-
-
-// I2PControl
-
- void I2PControlService::I2PControlHandler (const boost::property_tree::ptree& params, std::ostringstream& results)
- {
- for (auto& it: params)
- {
- LogPrint (eLogDebug, "I2PControl: I2PControl request: ", it.first);
- auto it1 = m_I2PControlHandlers.find (it.first);
- if (it1 != m_I2PControlHandlers.end ())
- {
- (this->*(it1->second))(it.second.data ());
- InsertParam (results, it.first, "");
- }
- else
- LogPrint (eLogError, "I2PControl: I2PControl unknown request: ", it.first);
- }
- }
-
- void I2PControlService::PasswordHandler (const std::string& value)
- {
- LogPrint (eLogWarning, "I2PControl: new password=", value, ", to make it persistent you should update your config!");
- m_Password = value;
- m_Tokens.clear ();
- }
-
-// RouterInfo
-
- void I2PControlService::RouterInfoHandler (const boost::property_tree::ptree& params, std::ostringstream& results)
- {
- for (auto it = params.begin (); it != params.end (); it++)
- {
- LogPrint (eLogDebug, "I2PControl: RouterInfo request: ", it->first);
- auto it1 = m_RouterInfoHandlers.find (it->first);
- if (it1 != m_RouterInfoHandlers.end ())
- {
- if (it != params.begin ()) results << ",";
- (this->*(it1->second))(results);
- }
- else
- LogPrint (eLogError, "I2PControl: RouterInfo unknown request ", it->first);
- }
- }
-
- void I2PControlService::UptimeHandler (std::ostringstream& results)
- {
- InsertParam (results, "i2p.router.uptime", (int)i2p::context.GetUptime ()*1000);
- }
-
- void I2PControlService::VersionHandler (std::ostringstream& results)
- {
- InsertParam (results, "i2p.router.version", VERSION);
- }
-
- void I2PControlService::StatusHandler (std::ostringstream& results)
- {
- auto dest = i2p::client::context.GetSharedLocalDestination ();
- InsertParam (results, "i2p.router.status", (dest && dest->IsReady ()) ? "1" : "0");
- }
-
- void I2PControlService::NetDbKnownPeersHandler (std::ostringstream& results)
- {
- InsertParam (results, "i2p.router.netdb.knownpeers", i2p::data::netdb.GetNumRouters ());
- }
-
- void I2PControlService::NetDbActivePeersHandler (std::ostringstream& results)
- {
- InsertParam (results, "i2p.router.netdb.activepeers", (int)i2p::transport::transports.GetPeers ().size ());
- }
-
- void I2PControlService::NetStatusHandler (std::ostringstream& results)
- {
- InsertParam (results, "i2p.router.net.status", (int)i2p::context.GetStatus ());
- }
-
- void I2PControlService::TunnelsParticipatingHandler (std::ostringstream& results)
- {
- int transit = i2p::tunnel::tunnels.GetTransitTunnels ().size ();
- InsertParam (results, "i2p.router.net.tunnels.participating", transit);
- }
-
- void I2PControlService::TunnelsSuccessRateHandler (std::ostringstream& results)
- {
- int rate = i2p::tunnel::tunnels.GetTunnelCreationSuccessRate ();
- InsertParam (results, "i2p.router.net.tunnels.successrate", rate);
- }
-
- void I2PControlService::InboundBandwidth1S (std::ostringstream& results)
- {
- double bw = i2p::transport::transports.GetInBandwidth ();
- InsertParam (results, "i2p.router.net.bw.inbound.1s", bw);
- }
-
- void I2PControlService::OutboundBandwidth1S (std::ostringstream& results)
- {
- double bw = i2p::transport::transports.GetOutBandwidth ();
- InsertParam (results, "i2p.router.net.bw.outbound.1s", bw);
- }
-
- void I2PControlService::NetTotalReceivedBytes (std::ostringstream& results)
- {
- InsertParam (results, "i2p.router.net.total.received.bytes", (double)i2p::transport::transports.GetTotalReceivedBytes ());
- }
-
- void I2PControlService::NetTotalSentBytes (std::ostringstream& results)
- {
- InsertParam (results, "i2p.router.net.total.sent.bytes", (double)i2p::transport::transports.GetTotalSentBytes ());
- }
-
-
-// RouterManager
-
- void I2PControlService::RouterManagerHandler (const boost::property_tree::ptree& params, std::ostringstream& results)
- {
- for (auto it = params.begin (); it != params.end (); it++)
- {
- if (it != params.begin ()) results << ",";
- LogPrint (eLogDebug, "I2PControl: RouterManager request: ", it->first);
- auto it1 = m_RouterManagerHandlers.find (it->first);
- if (it1 != m_RouterManagerHandlers.end ()) {
- (this->*(it1->second))(results);
- } else
- LogPrint (eLogError, "I2PControl: RouterManager unknown request: ", it->first);
- }
- }
-
-
- void I2PControlService::ShutdownHandler (std::ostringstream& results)
- {
- LogPrint (eLogInfo, "I2PControl: Shutdown requested");
- InsertParam (results, "Shutdown", "");
- m_ShutdownTimer.expires_from_now (boost::posix_time::seconds(1)); // 1 second to make sure response has been sent
- m_ShutdownTimer.async_wait (
- [](const boost::system::error_code& ecode)
- {
- Daemon.running = 0;
- });
- }
-
- void I2PControlService::ShutdownGracefulHandler (std::ostringstream& results)
- {
- i2p::context.SetAcceptsTunnels (false);
- int timeout = i2p::tunnel::tunnels.GetTransitTunnelsExpirationTimeout ();
- LogPrint (eLogInfo, "I2PControl: Graceful shutdown requested, ", timeout, " seconds remains");
- InsertParam (results, "ShutdownGraceful", "");
- m_ShutdownTimer.expires_from_now (boost::posix_time::seconds(timeout + 1)); // + 1 second
- m_ShutdownTimer.async_wait (
- [](const boost::system::error_code& ecode)
- {
- Daemon.running = 0;
- });
- }
-
- void I2PControlService::ReseedHandler (std::ostringstream& results)
- {
- LogPrint (eLogInfo, "I2PControl: Reseed requested");
- InsertParam (results, "Reseed", "");
- i2p::data::netdb.Reseed ();
- }
-
-// network setting
- void I2PControlService::NetworkSettingHandler (const boost::property_tree::ptree& params, std::ostringstream& results)
- {
- for (auto it = params.begin (); it != params.end (); it++)
- {
- LogPrint (eLogDebug, "I2PControl: NetworkSetting request: ", it->first);
- auto it1 = m_NetworkSettingHandlers.find (it->first);
- if (it1 != m_NetworkSettingHandlers.end ()) {
- if (it != params.begin ()) results << ",";
- (this->*(it1->second))(it->second.data (), results);
- } else
- LogPrint (eLogError, "I2PControl: NetworkSetting unknown request: ", it->first);
- }
- }
-
- void I2PControlService::InboundBandwidthLimit (const std::string& value, std::ostringstream& results)
- {
- if (value != "null")
- i2p::context.SetBandwidth (std::atoi(value.c_str()));
- int bw = i2p::context.GetBandwidthLimit();
- InsertParam (results, "i2p.router.net.bw.in", bw);
- }
-
- void I2PControlService::OutboundBandwidthLimit (const std::string& value, std::ostringstream& results)
- {
- if (value != "null")
- i2p::context.SetBandwidth (std::atoi(value.c_str()));
- int bw = i2p::context.GetBandwidthLimit();
- InsertParam (results, "i2p.router.net.bw.out", bw);
- }
-
- // certificate
- void I2PControlService::CreateCertificate (const char *crt_path, const char *key_path)
- {
- FILE *f = NULL;
- EVP_PKEY * pkey = EVP_PKEY_new ();
- RSA * rsa = RSA_new ();
- BIGNUM * e = BN_dup (i2p::crypto::GetRSAE ());
- RSA_generate_key_ex (rsa, 4096, e, NULL);
- BN_free (e);
- if (rsa)
- {
- EVP_PKEY_assign_RSA (pkey, rsa);
- X509 * x509 = X509_new ();
- ASN1_INTEGER_set (X509_get_serialNumber (x509), 1);
- X509_gmtime_adj (X509_getm_notBefore (x509), 0);
- X509_gmtime_adj (X509_getm_notAfter (x509), I2P_CONTROL_CERTIFICATE_VALIDITY*24*60*60); // expiration
- X509_set_pubkey (x509, pkey); // public key
- X509_NAME * name = X509_get_subject_name (x509);
- X509_NAME_add_entry_by_txt (name, "C", MBSTRING_ASC, (unsigned char *)"A1", -1, -1, 0); // country (Anonymous proxy)
- X509_NAME_add_entry_by_txt (name, "O", MBSTRING_ASC, (unsigned char *)I2P_CONTROL_CERTIFICATE_ORGANIZATION, -1, -1, 0); // organization
- X509_NAME_add_entry_by_txt (name, "CN", MBSTRING_ASC, (unsigned char *)I2P_CONTROL_CERTIFICATE_COMMON_NAME, -1, -1, 0); // common name
- X509_set_issuer_name (x509, name); // set issuer to ourselves
- X509_sign (x509, pkey, EVP_sha1 ()); // sign
-
- // save cert
- if ((f = fopen (crt_path, "wb")) != NULL) {
- LogPrint (eLogInfo, "I2PControl: saving new cert to ", crt_path);
- PEM_write_X509 (f, x509);
- fclose (f);
- } else {
- LogPrint (eLogError, "I2PControl: can't write cert: ", strerror(errno));
- }
-
- // save key
- if ((f = fopen (key_path, "wb")) != NULL) {
- LogPrint (eLogInfo, "I2PControl: saving cert key to ", key_path);
- PEM_write_PrivateKey (f, pkey, NULL, NULL, 0, NULL, NULL);
- fclose (f);
- } else {
- LogPrint (eLogError, "I2PControl: can't write key: ", strerror(errno));
- }
-
- X509_free (x509);
- } else {
- LogPrint (eLogError, "I2PControl: can't create RSA key for certificate");
- }
- EVP_PKEY_free (pkey);
- }
-
-// ClientServicesInfo
-
- void I2PControlService::ClientServicesInfoHandler (const boost::property_tree::ptree& params, std::ostringstream& results)
- {
- for (auto it = params.begin (); it != params.end (); it++)
- {
- LogPrint (eLogDebug, "I2PControl: ClientServicesInfo request: ", it->first);
- auto it1 = m_ClientServicesInfoHandlers.find (it->first);
- if (it1 != m_ClientServicesInfoHandlers.end ())
- {
- if (it != params.begin ()) results << ",";
- (this->*(it1->second))(results);
- }
- else
- LogPrint (eLogError, "I2PControl: ClientServicesInfo unknown request ", it->first);
- }
- }
-
- void I2PControlService::I2PTunnelInfoHandler (std::ostringstream& results)
- {
- boost::property_tree::ptree pt;
- boost::property_tree::ptree client_tunnels, server_tunnels;
-
- for (auto& it: i2p::client::context.GetClientTunnels ())
- {
- auto& ident = it.second->GetLocalDestination ()->GetIdentHash();
- boost::property_tree::ptree ct;
- ct.put("address", i2p::client::context.GetAddressBook ().ToAddress(ident));
- client_tunnels.add_child(it.second->GetName (), ct);
- }
-
- auto& serverTunnels = i2p::client::context.GetServerTunnels ();
- if (!serverTunnels.empty ()) {
- for (auto& it: serverTunnels)
- {
- auto& ident = it.second->GetLocalDestination ()->GetIdentHash();
- boost::property_tree::ptree st;
- st.put("address", i2p::client::context.GetAddressBook ().ToAddress(ident));
- st.put("port", it.second->GetLocalPort ());
- server_tunnels.add_child(it.second->GetName (), st);
- }
- }
-
- auto& clientForwards = i2p::client::context.GetClientForwards ();
- if (!clientForwards.empty ())
- {
- for (auto& it: clientForwards)
- {
- auto& ident = it.second->GetLocalDestination ()->GetIdentHash();
- boost::property_tree::ptree ct;
- ct.put("address", i2p::client::context.GetAddressBook ().ToAddress(ident));
- client_tunnels.add_child(it.second->GetName (), ct);
- }
- }
-
- auto& serverForwards = i2p::client::context.GetServerForwards ();
- if (!serverForwards.empty ())
- {
- for (auto& it: serverForwards)
- {
- auto& ident = it.second->GetLocalDestination ()->GetIdentHash();
- boost::property_tree::ptree st;
- st.put("address", i2p::client::context.GetAddressBook ().ToAddress(ident));
- server_tunnels.add_child(it.second->GetName (), st);
- }
- }
-
- pt.add_child("client", client_tunnels);
- pt.add_child("server", server_tunnels);
-
- InsertParam (results, "I2PTunnel", pt);
- }
-
- void I2PControlService::HTTPProxyInfoHandler (std::ostringstream& results)
- {
- boost::property_tree::ptree pt;
-
- auto httpProxy = i2p::client::context.GetHttpProxy ();
- if (httpProxy)
- {
- auto& ident = httpProxy->GetLocalDestination ()->GetIdentHash();
- pt.put("enabled", true);
- pt.put("address", i2p::client::context.GetAddressBook ().ToAddress(ident));
- }
- else
- pt.put("enabled", false);
-
- InsertParam (results, "HTTPProxy", pt);
- }
-
- void I2PControlService::SOCKSInfoHandler (std::ostringstream& results)
- {
- boost::property_tree::ptree pt;
-
- auto socksProxy = i2p::client::context.GetSocksProxy ();
- if (socksProxy)
- {
- auto& ident = socksProxy->GetLocalDestination ()->GetIdentHash();
- pt.put("enabled", true);
- pt.put("address", i2p::client::context.GetAddressBook ().ToAddress(ident));
- }
- else
- pt.put("enabled", false);
-
- InsertParam (results, "SOCKS", pt);
- }
-
- void I2PControlService::SAMInfoHandler (std::ostringstream& results)
- {
- boost::property_tree::ptree pt;
- auto sam = i2p::client::context.GetSAMBridge ();
- if (sam)
- {
- pt.put("enabled", true);
- boost::property_tree::ptree sam_sessions;
- for (auto& it: sam->GetSessions ())
- {
- boost::property_tree::ptree sam_session, sam_session_sockets;
- auto& name = it.second->localDestination->GetNickname ();
- auto& ident = it.second->localDestination->GetIdentHash();
- sam_session.put("name", name);
- sam_session.put("address", i2p::client::context.GetAddressBook ().ToAddress(ident));
-
- for (const auto& socket: sam->ListSockets(it.first))
- {
- boost::property_tree::ptree stream;
- stream.put("type", socket->GetSocketType ());
- stream.put("peer", socket->GetSocket ().remote_endpoint());
-
- sam_session_sockets.push_back(std::make_pair("", stream));
- }
- sam_session.add_child("sockets", sam_session_sockets);
- sam_sessions.add_child(it.first, sam_session);
- }
-
- pt.add_child("sessions", sam_sessions);
- }
- else
- pt.put("enabled", false);
-
- InsertParam (results, "SAM", pt);
- }
-
- void I2PControlService::BOBInfoHandler (std::ostringstream& results)
- {
- boost::property_tree::ptree pt;
- auto bob = i2p::client::context.GetBOBCommandChannel ();
- if (bob)
- {
- /* TODO more info */
- pt.put("enabled", true);
- }
- else
- pt.put("enabled", false);
-
- InsertParam (results, "BOB", pt);
- }
-
- void I2PControlService::I2CPInfoHandler (std::ostringstream& results)
- {
- boost::property_tree::ptree pt;
- auto i2cp = i2p::client::context.GetI2CPServer ();
- if (i2cp)
- {
- /* TODO more info */
- pt.put("enabled", true);
- }
- else
- pt.put("enabled", false);
-
- InsertParam (results, "I2CP", pt);
- }
-}
-}
diff --git a/daemon/UPnP.cpp b/daemon/UPnP.cpp
index 3aad19c6..0e9abe42 100644
--- a/daemon/UPnP.cpp
+++ b/daemon/UPnP.cpp
@@ -18,7 +18,7 @@
#include
#include
-namespace i2p
+namespace dotnet
{
namespace transport
{
@@ -121,7 +121,7 @@ namespace transport
// UPnP discovered
LogPrint (eLogDebug, "UPnP: ExternalIPAddress is ", m_externalIPAddress);
- i2p::context.UpdateAddress (boost::asio::ip::address::from_string (m_externalIPAddress));
+ dotnet::context.UpdateAddress (boost::asio::ip::address::from_string (m_externalIPAddress));
// port mapping
PortMapping ();
}
@@ -153,11 +153,11 @@ namespace transport
}
}
- void UPnP::TryPortMapping (std::shared_ptr address)
+ void UPnP::TryPortMapping (std::shared_ptr address)
{
std::string strType (GetProto (address)), strPort (std::to_string (address->port));
int r;
- std::string strDesc; i2p::config::GetOption("upnp.name", strDesc);
+ std::string strDesc; dotnet::config::GetOption("upnp.name", strDesc);
#ifdef UPNPDISCOVER_SUCCESS
r = UPNP_AddPortMapping (m_upnpUrls.controlURL, m_upnpData.first.servicetype, strPort.c_str (), strPort.c_str (), m_NetworkAddr, strDesc.c_str (), strType.c_str (), 0, "0");
#else
@@ -175,7 +175,7 @@ namespace transport
}
}
- void UPnP::CloseMapping (std::shared_ptr address)
+ void UPnP::CloseMapping (std::shared_ptr address)
{
std::string strType (GetProto (address)), strPort (std::to_string (address->port));
int r = 0;
@@ -190,14 +190,14 @@ namespace transport
FreeUPNPUrls (&m_upnpUrls);
}
- std::string UPnP::GetProto (std::shared_ptr address)
+ std::string UPnP::GetProto (std::shared_ptr address)
{
switch (address->transportStyle)
{
- case i2p::data::RouterInfo::eTransportNTCP:
+ case dotnet::data::RouterInfo::eTransportNTCP:
return "TCP";
break;
- case i2p::data::RouterInfo::eTransportSSU:
+ case dotnet::data::RouterInfo::eTransportSSU:
default:
return "UDP";
}
@@ -205,7 +205,7 @@ namespace transport
}
}
#else /* USE_UPNP */
-namespace i2p {
+namespace dotnet {
namespace transport {
}
}
diff --git a/daemon/UPnP.h b/daemon/UPnP.h
index 5313a1c4..7ab856c3 100644
--- a/daemon/UPnP.h
+++ b/daemon/UPnP.h
@@ -15,7 +15,7 @@
#include
-namespace i2p
+namespace dotnet
{
namespace transport
{
@@ -34,12 +34,12 @@ namespace transport
void Discover ();
void PortMapping ();
- void TryPortMapping (std::shared_ptr address);
+ void TryPortMapping (std::shared_ptr address);
void CloseMapping ();
- void CloseMapping (std::shared_ptr address);
+ void CloseMapping (std::shared_ptr address);
void Run ();
- std::string GetProto (std::shared_ptr address);
+ std::string GetProto (std::shared_ptr address);
private:
@@ -63,7 +63,7 @@ namespace transport
}
#else // USE_UPNP
-namespace i2p {
+namespace dotnet {
namespace transport {
/* class stub */
class UPnP {
diff --git a/daemon/UnixDaemon.cpp b/daemon/UnixDaemon.cpp
index 3dd38fba..c88c1165 100644
--- a/daemon/UnixDaemon.cpp
+++ b/daemon/UnixDaemon.cpp
@@ -23,16 +23,16 @@ void handle_signal(int sig)
{
case SIGHUP:
LogPrint(eLogInfo, "Daemon: Got SIGHUP, reopening tunnel configuration...");
- i2p::client::context.ReloadConfig();
+ dotnet::client::context.ReloadConfig();
break;
case SIGUSR1:
LogPrint(eLogInfo, "Daemon: Got SIGUSR1, reopening logs...");
- i2p::log::Logger().Reopen ();
+ dotnet::log::Logger().Reopen ();
break;
case SIGINT:
- if (i2p::context.AcceptsTunnels () && !Daemon.gracefulShutdownInterval)
+ if (dotnet::context.AcceptsTunnels () && !Daemon.gracefulShutdownInterval)
{
- i2p::context.SetAcceptsTunnels (false);
+ dotnet::context.SetAcceptsTunnels (false);
Daemon.gracefulShutdownInterval = 10*60; // 10 minutes
LogPrint(eLogInfo, "Graceful shutdown after ", Daemon.gracefulShutdownInterval, " seconds");
}
@@ -49,7 +49,7 @@ void handle_signal(int sig)
}
}
-namespace i2p
+namespace dotnet
{
namespace util
{
@@ -76,7 +76,7 @@ namespace i2p
LogPrint(eLogError, "Daemon: could not create process group.");
return false;
}
- std::string d = i2p::fs::GetDataDir();
+ std::string d = dotnet::fs::GetDataDir();
if (chdir(d.c_str()) != 0)
{
LogPrint(eLogError, "Daemon: could not chdir: ", strerror(errno));
@@ -91,7 +91,7 @@ namespace i2p
// set proc limits
struct rlimit limit;
- uint16_t nfiles; i2p::config::GetOption("limits.openfiles", nfiles);
+ uint16_t nfiles; dotnet::config::GetOption("limits.openfiles", nfiles);
getrlimit(RLIMIT_NOFILE, &limit);
if (nfiles == 0) {
LogPrint(eLogInfo, "Daemon: using system limit in ", limit.rlim_cur, " max open files");
@@ -106,7 +106,7 @@ namespace i2p
} else {
LogPrint(eLogError, "Daemon: limits.openfiles exceeds system limit: ", limit.rlim_max);
}
- uint32_t cfsize; i2p::config::GetOption("limits.coresize", cfsize);
+ uint32_t cfsize; dotnet::config::GetOption("limits.coresize", cfsize);
if (cfsize) // core file size set
{
cfsize *= 1024;
@@ -127,9 +127,9 @@ namespace i2p
// Pidfile
// this code is c-styled and a bit ugly, but we need fd for locking pidfile
- std::string pidfile; i2p::config::GetOption("pidfile", pidfile);
+ std::string pidfile; dotnet::config::GetOption("pidfile", pidfile);
if (pidfile == "") {
- pidfile = i2p::fs::DataDirPath("i2pd.pid");
+ pidfile = dotnet::fs::DataDirPath("dotnet.pid");
}
if (pidfile != "") {
pidFH = open(pidfile.c_str(), O_RDWR | O_CREAT, 0600);
@@ -174,7 +174,7 @@ namespace i2p
bool DaemonLinux::stop()
{
- i2p::fs::Remove(pidfile);
+ dotnet::fs::Remove(pidfile);
return Daemon_Singleton::stop();
}
@@ -187,7 +187,7 @@ namespace i2p
if (gracefulShutdownInterval)
{
gracefulShutdownInterval--; // - 1 second
- if (gracefulShutdownInterval <= 0 || i2p::tunnel::tunnels.CountTransitTunnels() <= 0)
+ if (gracefulShutdownInterval <= 0 || dotnet::tunnel::tunnels.CountTransitTunnels() <= 0)
{
LogPrint(eLogInfo, "Graceful shutdown");
return;
diff --git a/daemon/i2pd.cpp b/daemon/dotnet.cpp
similarity index 90%
rename from daemon/i2pd.cpp
rename to daemon/dotnet.cpp
index 8718ad0c..952f0118 100644
--- a/daemon/i2pd.cpp
+++ b/daemon/dotnet.cpp
@@ -3,7 +3,7 @@
#if defined(QT_GUI_LIB)
-namespace i2p
+namespace dotnet
{
namespace qt
{
@@ -12,7 +12,7 @@ namespace qt
}
int main( int argc, char* argv[] )
{
- return i2p::qt::RunQT (argc, argv);
+ return dotnet::qt::RunQT (argc, argv);
}
#else
diff --git a/debian/.gitignore b/debian/.gitignore
index b03f9e24..94bb4a50 100644
--- a/debian/.gitignore
+++ b/debian/.gitignore
@@ -1,9 +1,9 @@
debhelper-build-stamp
files
-i2pd-dbg.substvars
-i2pd.postinst.debhelper
-i2pd.postrm.debhelper
-i2pd.prerm.debhelper
-i2pd.substvars
-i2pd/
-i2pd-dbg/
+dotnet-dbg.substvars
+dotnet.postinst.debhelper
+dotnet.postrm.debhelper
+dotnet.prerm.debhelper
+dotnet.substvars
+dotnet/
+dotnet-dbg/
diff --git a/debian/changelog b/debian/changelog
index a0ad2cd5..0882bbfd 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,50 +1,50 @@
-i2pd (2.25.0-1) unstable; urgency=medium
+dotnet (2.25.0-1) unstable; urgency=medium
* updated to version 2.25.0/0.9.40
- -- orignal Thu, 9 May 2019 16:00:00 +0000
+ -- orignal Thu, 9 May 2019 16:00:00 +0000
-i2pd (2.24.0-1) unstable; urgency=medium
+dotnet (2.24.0-1) unstable; urgency=medium
* updated to version 2.24.0/0.9.39
- -- orignal Thu, 21 Mar 2019 16:00:00 +0000
+ -- orignal Thu, 21 Mar 2019 16:00:00 +0000
-i2pd (2.23.0-1) unstable; urgency=medium
+dotnet (2.23.0-1) unstable; urgency=medium
* updated to version 2.23.0/0.9.38
* update docs, dirs, install, links files
- -- orignal Mon, 21 Jan 2019 16:00:00 +0000
+ -- orignal Mon, 21 Jan 2019 16:00:00 +0000
-i2pd (2.22.0-1) unstable; urgency=medium
+dotnet (2.22.0-1) unstable; urgency=medium
* updated to version 2.22.0/0.9.37
* update manpage (1)
* update links, install files to support tunnelsdir option
* renamed and updated patch (#1210)
- -- r4sas Fri, 09 Nov 2018 02:00:00 +0000
+ -- r4sas Fri, 09 Nov 2018 02:00:00 +0000
-i2pd (2.21.1-1) unstable; urgency=medium
+dotnet (2.21.1-1) unstable; urgency=medium
* updated to version 2.21.1
- -- orignal Thu, 22 Oct 2018 16:00:00 +0000
+ -- orignal Thu, 22 Oct 2018 16:00:00 +0000
-i2pd (2.21.0-1) unstable; urgency=medium
+dotnet (2.21.0-1) unstable; urgency=medium
* updated to version 2.21.0/0.9.37
- -- orignal Thu, 4 Oct 2018 16:00:00 +0000
+ -- orignal Thu, 4 Oct 2018 16:00:00 +0000
-i2pd (2.20.0-1) unstable; urgency=medium
+dotnet (2.20.0-1) unstable; urgency=medium
* updated to version 2.20.0/0.9.36
- -- orignal Thu, 23 Aug 2018 16:00:00 +0000
+ -- orignal Thu, 23 Aug 2018 16:00:00 +0000
-i2pd (2.19.0-1) unstable; urgency=medium
+dotnet (2.19.0-1) unstable; urgency=medium
* updated to version 2.19.0/0.9.35
* update manpage (1)
@@ -53,107 +53,107 @@ i2pd (2.19.0-1) unstable; urgency=medium
* fixes in systemd unit (#1089, #1142, #1154, #1155)
* package now building with systemd support
- -- R4SAS Tue, 26 Jun 2018 16:27:45 +0000
+ -- R4SAS Tue, 26 Jun 2018 16:27:45 +0000
-i2pd (2.18.0-1) unstable; urgency=low
+dotnet (2.18.0-1) unstable; urgency=low
* updated to version 2.18.0/0.9.33
- -- orignal Tue, 30 Jan 2018 16:00:00 +0000
+ -- orignal Tue, 30 Jan 2018 16:00:00 +0000
-i2pd (2.17.0-1) unstable; urgency=low
+dotnet (2.17.0-1) unstable; urgency=low
* updated to version 2.17.0/0.9.32
- -- orignal Mon, 4 Dec 2017 18:00:00 +0000
+ -- orignal Mon, 4 Dec 2017 18:00:00 +0000
-i2pd (2.16.0-1) unstable; urgency=low
+dotnet (2.16.0-1) unstable; urgency=low
* updated to version 2.16.0/0.9.32
- -- orignal Mon, 13 Nov 2017 18:00:00 +0000
+ -- orignal Mon, 13 Nov 2017 18:00:00 +0000
-i2pd (2.15.0-1) unstable; urgency=low
+dotnet (2.15.0-1) unstable; urgency=low
* updated to version 2.15.0/0.9.31
- -- orignal Thu, 17 Aug 2017 18:00:00 +0000
+ -- orignal Thu, 17 Aug 2017 18:00:00 +0000
-i2pd (2.14.0-1) unstable; urgency=low
+dotnet (2.14.0-1) unstable; urgency=low
* updated to version 2.14.0/0.9.30
* updated debian/control
- * renamed logrotate to i2pd.logrotate
+ * renamed logrotate to dotnet.logrotate
* fixed init.d script
- -- orignal Thu, 1 Jun 2017 14:00:00 +0000
+ -- orignal Thu, 1 Jun 2017 14:00:00 +0000
-i2pd (2.13.0-1) unstable; urgency=low
+dotnet (2.13.0-1) unstable; urgency=low
* updated to version 2.13.0/0.9.29
* updated debian/control
- * renamed logrotate to i2pd.logrotate
+ * renamed logrotate to dotnet.logrotate
* fixed init.d script
- -- orignal Thu, 6 Apr 2017 14:00:00 +0000
+ -- orignal Thu, 6 Apr 2017 14:00:00 +0000
-i2pd (2.12.0-1) unstable; urgency=low
+dotnet (2.12.0-1) unstable; urgency=low
* updated to version 2.12.0/0.9.28
- -- orignal Tue, 14 Feb 2017 17:59:30 +0000
+ -- orignal Tue, 14 Feb 2017 17:59:30 +0000
-i2pd (2.11.0-1) unstable; urgency=low
+dotnet (2.11.0-1) unstable; urgency=low
* updated to version 2.11.0/0.9.28
- -- orignal Sun, 18 Dec 2016 21:01:30 +0000
+ -- orignal Sun, 18 Dec 2016 21:01:30 +0000
-i2pd (2.10.2-1) unstable; urgency=low
+dotnet (2.10.2-1) unstable; urgency=low
* updated to version 2.10.2
- -- orignal Sun, 4 Dec 2016 19:38:30 +0000
+ -- orignal Sun, 4 Dec 2016 19:38:30 +0000
-i2pd (2.10.1-1) unstable; urgency=low
+dotnet (2.10.1-1) unstable; urgency=low
* updated to version 2.10.1
- -- orignal Mon, 7 Nov 2016 14:18:30 +0000
+ -- orignal Mon, 7 Nov 2016 14:18:30 +0000
-i2pd (2.10.0-1) unstable; urgency=low
+dotnet (2.10.0-1) unstable; urgency=low
* updated to version 2.10.0/0.9.27
* reseed.verify set to true by default
- -- orignal