mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-06-08 07:06:52 +02:00
modulize client protocols
Signed-off-by: R4SAS <r4sas@i2pmail.org>
This commit is contained in:
parent
18cb3912e5
commit
3ab5ac66b6
15 changed files with 184 additions and 72 deletions
|
@ -26,7 +26,9 @@
|
|||
#include "Streaming.h"
|
||||
#include "Destination.h"
|
||||
#include "HTTPServer.h"
|
||||
#ifdef WITH_I2PC
|
||||
#include "I2PControl.h"
|
||||
#endif
|
||||
#include "ClientContext.h"
|
||||
#include "Crypto.h"
|
||||
#include "UPnP.h"
|
||||
|
@ -45,7 +47,9 @@ namespace util
|
|||
~Daemon_Singleton_Private() {};
|
||||
|
||||
std::unique_ptr<i2p::http::HTTPServer> httpServer;
|
||||
#ifdef WITH_I2PC
|
||||
std::unique_ptr<i2p::client::I2PControlService> m_I2PControlService;
|
||||
#endif
|
||||
std::unique_ptr<i2p::transport::UPnP> UPnP;
|
||||
std::unique_ptr<i2p::util::NTPTimeSync> m_NTPSync;
|
||||
};
|
||||
|
@ -441,6 +445,7 @@ namespace util
|
|||
LogPrint(eLogInfo, "Daemon: Starting Client");
|
||||
i2p::client::context.Start ();
|
||||
|
||||
#ifdef WITH_I2PC
|
||||
// I2P Control Protocol
|
||||
bool i2pcontrol; i2p::config::GetOption("i2pcontrol.enabled", i2pcontrol);
|
||||
if (i2pcontrol) {
|
||||
|
@ -458,6 +463,7 @@ namespace util
|
|||
ThrowFatal ("Unable to start I2PControl service at ", i2pcpAddr, ":", i2pcpPort, ": ", ex.what ());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -490,12 +496,14 @@ namespace util
|
|||
d.httpServer->Stop();
|
||||
d.httpServer = nullptr;
|
||||
}
|
||||
#ifdef WITH_I2PC
|
||||
if (d.m_I2PControlService)
|
||||
{
|
||||
LogPrint(eLogInfo, "Daemon: Stopping I2PControl");
|
||||
d.m_I2PControlService->Stop ();
|
||||
d.m_I2PControlService = nullptr;
|
||||
}
|
||||
#endif
|
||||
i2p::crypto::TerminateCrypto ();
|
||||
i2p::log::Logger().Stop();
|
||||
|
||||
|
|
|
@ -68,9 +68,13 @@ namespace http {
|
|||
const char HTTP_PAGE_TRANSPORTS[] = "transports";
|
||||
const char HTTP_PAGE_LOCAL_DESTINATIONS[] = "local_destinations";
|
||||
const char HTTP_PAGE_LOCAL_DESTINATION[] = "local_destination";
|
||||
#ifdef WITH_I2CP
|
||||
const char HTTP_PAGE_I2CP_LOCAL_DESTINATION[] = "i2cp_local_destination";
|
||||
#endif
|
||||
#ifdef WITH_SAM
|
||||
const char HTTP_PAGE_SAM_SESSIONS[] = "sam_sessions";
|
||||
const char HTTP_PAGE_SAM_SESSION[] = "sam_session";
|
||||
#endif
|
||||
const char HTTP_PAGE_I2P_TUNNELS[] = "i2p_tunnels";
|
||||
const char HTTP_PAGE_COMMANDS[] = "commands";
|
||||
const char HTTP_PAGE_LEASESETS[] = "leasesets";
|
||||
|
@ -87,7 +91,9 @@ namespace http {
|
|||
const char HTTP_COMMAND_GET_REG_STRING[] = "get_reg_string";
|
||||
const char HTTP_COMMAND_SETLANGUAGE[] = "setlanguage";
|
||||
const char HTTP_COMMAND_RELOAD_CSS[] = "reload_css";
|
||||
#ifdef WITH_SAM
|
||||
const char HTTP_PARAM_SAM_SESSION_ID[] = "id";
|
||||
#endif
|
||||
const char HTTP_PARAM_ADDRESS[] = "address";
|
||||
|
||||
static std::string ConvertTime (uint64_t time)
|
||||
|
@ -202,8 +208,10 @@ namespace http {
|
|||
s <<
|
||||
" <a href=\"" << webroot << "?page=" << HTTP_PAGE_TRANSPORTS << "\">" << tr ("Transports") << "</a><br>\r\n"
|
||||
" <a href=\"" << webroot << "?page=" << HTTP_PAGE_I2P_TUNNELS << "\">" << tr("I2P tunnels") << "</a><br>\r\n";
|
||||
#ifdef WITH_SAM
|
||||
if (i2p::client::context.GetSAMBridge ())
|
||||
s << " <a href=\"" << webroot << "?page=" << HTTP_PAGE_SAM_SESSIONS << "\">" << tr("SAM sessions") << "</a><br>\r\n";
|
||||
#endif
|
||||
s <<
|
||||
"</div>\r\n"
|
||||
"<div class=\"content\">";
|
||||
|
@ -361,17 +369,25 @@ namespace http {
|
|||
if (outputFormat==OutputFormatEnum::forWebConsole) {
|
||||
bool httpproxy = i2p::client::context.GetHttpProxy () ? true : false;
|
||||
bool socksproxy = i2p::client::context.GetSocksProxy () ? true : false;
|
||||
bool bob = i2p::client::context.GetBOBCommandChannel () ? true : false;
|
||||
bool sam = i2p::client::context.GetSAMBridge () ? true : false;
|
||||
bool i2cp = i2p::client::context.GetI2CPServer () ? true : false;
|
||||
bool i2pcontrol; i2p::config::GetOption("i2pcontrol.enabled", i2pcontrol);
|
||||
s << "<table class=\"services\"><caption>" << tr("Services") << "</caption><tbody>\r\n";
|
||||
s << "<tr><td>" << "HTTP " << tr("Proxy") << "</td><td class='" << (httpproxy ? "enabled" : "disabled") << "'>" << (httpproxy ? tr("Enabled") : tr("Disabled")) << "</td></tr>\r\n";
|
||||
s << "<tr><td>" << "SOCKS " << tr("Proxy") << "</td><td class='" << (socksproxy ? "enabled" : "disabled") << "'>" << (socksproxy ? tr("Enabled") : tr("Disabled")) << "</td></tr>\r\n";
|
||||
#ifdef WITH_BOB
|
||||
bool bob = i2p::client::context.GetBOBCommandChannel () ? true : false;
|
||||
s << "<tr><td>" << "BOB" << "</td><td class='" << (bob ? "enabled" : "disabled") << "'>" << (bob ? tr("Enabled") : tr("Disabled")) << "</td></tr>\r\n";
|
||||
#endif
|
||||
#ifdef WITH_SAM
|
||||
bool sam = i2p::client::context.GetSAMBridge () ? true : false;
|
||||
s << "<tr><td>" << "SAM" << "</td><td class='" << (sam ? "enabled" : "disabled") << "'>" << (sam ? tr("Enabled") : tr("Disabled")) << "</td></tr>\r\n";
|
||||
#endif
|
||||
#ifdef WITH_I2CP
|
||||
bool i2cp = i2p::client::context.GetI2CPServer () ? true : false;
|
||||
s << "<tr><td>" << "I2CP" << "</td><td class='" << (i2cp ? "enabled" : "disabled") << "'>" << (i2cp ? tr("Enabled") : tr("Disabled")) << "</td></tr>\r\n";
|
||||
#endif
|
||||
#ifdef WITH_I2PC
|
||||
bool i2pcontrol; i2p::config::GetOption("i2pcontrol.enabled", i2pcontrol);
|
||||
s << "<tr><td>" << "I2PControl" << "</td><td class='" << (i2pcontrol ? "enabled" : "disabled") << "'>" << (i2pcontrol ? tr("Enabled") : tr("Disabled")) << "</td></tr>\r\n";
|
||||
#endif
|
||||
s << "</tbody></table>\r\n";
|
||||
}
|
||||
}
|
||||
|
@ -388,6 +404,7 @@ namespace http {
|
|||
}
|
||||
s << "</div>\r\n";
|
||||
|
||||
#ifdef WITH_I2CP
|
||||
auto i2cpServer = i2p::client::context.GetI2CPServer ();
|
||||
if (i2cpServer && !(i2cpServer->GetSessions ().empty ()))
|
||||
{
|
||||
|
@ -405,6 +422,7 @@ namespace http {
|
|||
}
|
||||
s << "</div>\r\n";
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void ShowLeaseSetDestination (std::stringstream& s, std::shared_ptr<const i2p::client::LeaseSetDestination> dest, uint32_t token)
|
||||
|
@ -572,6 +590,7 @@ namespace http {
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef WITH_I2CP
|
||||
void ShowI2CPLocalDestination (std::stringstream& s, const std::string& id)
|
||||
{
|
||||
auto i2cpServer = i2p::client::context.GetI2CPServer ();
|
||||
|
@ -587,6 +606,7 @@ namespace http {
|
|||
else
|
||||
ShowError(s, tr("I2CP is not enabled"));
|
||||
}
|
||||
#endif
|
||||
|
||||
void ShowLeasesSets(std::stringstream& s)
|
||||
{
|
||||
|
@ -879,6 +899,7 @@ namespace http {
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef WITH_SAM
|
||||
void ShowSAMSessions (std::stringstream& s)
|
||||
{
|
||||
std::string webroot; i2p::config::GetOption("http.webroot", webroot);
|
||||
|
@ -941,6 +962,7 @@ namespace http {
|
|||
}
|
||||
s << "</div>\r\n";
|
||||
}
|
||||
#endif
|
||||
|
||||
void ShowI2PTunnels (std::stringstream& s)
|
||||
{
|
||||
|
@ -1194,12 +1216,16 @@ namespace http {
|
|||
uint32_t token = CreateToken ();
|
||||
ShowLocalDestination (s, params["b32"], token);
|
||||
}
|
||||
#ifdef WITH_I2CP
|
||||
else if (page == HTTP_PAGE_I2CP_LOCAL_DESTINATION)
|
||||
ShowI2CPLocalDestination (s, params["i2cp_id"]);
|
||||
#endif
|
||||
#ifdef WITH_SAM
|
||||
else if (page == HTTP_PAGE_SAM_SESSIONS)
|
||||
ShowSAMSessions (s);
|
||||
else if (page == HTTP_PAGE_SAM_SESSION)
|
||||
ShowSAMSession (s, params["sam_id"]);
|
||||
#endif
|
||||
else if (page == HTTP_PAGE_I2P_TUNNELS)
|
||||
ShowI2PTunnels (s);
|
||||
else if (page == HTTP_PAGE_LEASESETS)
|
||||
|
|
|
@ -95,11 +95,15 @@ namespace http
|
|||
void ShowTunnels (std::stringstream& s);
|
||||
void ShowTransitTunnels (std::stringstream& s);
|
||||
void ShowTransports (std::stringstream& s);
|
||||
void ShowSAMSessions (std::stringstream& s);
|
||||
void ShowI2PTunnels (std::stringstream& s);
|
||||
void ShowLocalDestination (std::stringstream& s, const std::string& b32, uint32_t token);
|
||||
void ShowSAMSession (std::stringstream& s, const std::string& id);
|
||||
void ShowI2CPLocalDestination (std::stringstream& s, const std::string& id);
|
||||
#ifdef WITH_SAM
|
||||
void ShowSAMSessions (std::stringstream& s);
|
||||
void ShowSAMSession (std::stringstream& s, const std::string& id);
|
||||
#endif
|
||||
#ifdef WITH_I2CP
|
||||
void ShowI2CPLocalDestination (std::stringstream& s, const std::string& id);
|
||||
#endif
|
||||
} // http
|
||||
} // i2p
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
* See full license text in LICENSE file at top of project tree
|
||||
*/
|
||||
|
||||
#ifdef WITH_I2PC
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sstream>
|
||||
#include <openssl/x509.h>
|
||||
|
@ -87,8 +89,7 @@ namespace client
|
|||
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.tunnels.successrate"] = &I2PControlService::TunnelsSuccessRateHandler;
|
||||
m_RouterInfoHandlers["i2p.router.net.total.received.bytes"] = &I2PControlService::NetTotalReceivedBytes;
|
||||
m_RouterInfoHandlers["i2p.router.net.total.sent.bytes"] = &I2PControlService::NetTotalSentBytes;
|
||||
|
||||
|
@ -105,9 +106,15 @@ namespace client
|
|||
m_ClientServicesInfoHandlers["I2PTunnel"] = &I2PControlService::I2PTunnelInfoHandler;
|
||||
m_ClientServicesInfoHandlers["HTTPProxy"] = &I2PControlService::HTTPProxyInfoHandler;
|
||||
m_ClientServicesInfoHandlers["SOCKS"] = &I2PControlService::SOCKSInfoHandler;
|
||||
#ifdef WITH_SAM
|
||||
m_ClientServicesInfoHandlers["SAM"] = &I2PControlService::SAMInfoHandler;
|
||||
#endif
|
||||
#ifdef WITH_BOB
|
||||
m_ClientServicesInfoHandlers["BOB"] = &I2PControlService::BOBInfoHandler;
|
||||
#endif
|
||||
#ifdef WITH_I2CP
|
||||
m_ClientServicesInfoHandlers["I2CP"] = &I2PControlService::I2CPInfoHandler;
|
||||
#endif
|
||||
}
|
||||
|
||||
I2PControlService::~I2PControlService ()
|
||||
|
@ -346,8 +353,7 @@ namespace client
|
|||
}
|
||||
}
|
||||
|
||||
// handlers
|
||||
|
||||
// handlers
|
||||
void I2PControlService::AuthenticateHandler (const boost::property_tree::ptree& params, std::ostringstream& results)
|
||||
{
|
||||
int api = params.get<int> ("API");
|
||||
|
@ -372,8 +378,7 @@ namespace client
|
|||
}
|
||||
|
||||
|
||||
// I2PControl
|
||||
|
||||
// I2PControl
|
||||
void I2PControlService::I2PControlHandler (const boost::property_tree::ptree& params, std::ostringstream& results)
|
||||
{
|
||||
for (auto& it: params)
|
||||
|
@ -507,7 +512,7 @@ namespace client
|
|||
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;
|
||||
});
|
||||
}
|
||||
|
@ -521,7 +526,7 @@ namespace client
|
|||
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;
|
||||
});
|
||||
}
|
||||
|
@ -533,7 +538,7 @@ namespace client
|
|||
i2p::data::netdb.Reseed ();
|
||||
}
|
||||
|
||||
// network setting
|
||||
// network setting
|
||||
void I2PControlService::NetworkSettingHandler (const boost::property_tree::ptree& params, std::ostringstream& results)
|
||||
{
|
||||
for (auto it = params.begin (); it != params.end (); it++)
|
||||
|
@ -613,8 +618,7 @@ namespace client
|
|||
EVP_PKEY_free (pkey);
|
||||
}
|
||||
|
||||
// ClientServicesInfo
|
||||
|
||||
// ClientServicesInfo
|
||||
void I2PControlService::ClientServicesInfoHandler (const boost::property_tree::ptree& params, std::ostringstream& results)
|
||||
{
|
||||
for (auto it = params.begin (); it != params.end (); it++)
|
||||
|
@ -720,6 +724,7 @@ namespace client
|
|||
InsertParam (results, "SOCKS", pt);
|
||||
}
|
||||
|
||||
#ifdef WITH_SAM
|
||||
void I2PControlService::SAMInfoHandler (std::ostringstream& results)
|
||||
{
|
||||
boost::property_tree::ptree pt;
|
||||
|
@ -755,7 +760,9 @@ namespace client
|
|||
|
||||
InsertParam (results, "SAM", pt);
|
||||
}
|
||||
#endif // WITH_SAM
|
||||
|
||||
#ifdef WITH_BOB
|
||||
void I2PControlService::BOBInfoHandler (std::ostringstream& results)
|
||||
{
|
||||
boost::property_tree::ptree pt;
|
||||
|
@ -770,7 +777,9 @@ namespace client
|
|||
|
||||
InsertParam (results, "BOB", pt);
|
||||
}
|
||||
#endif // WITH_BOB
|
||||
|
||||
#ifdef WITH_I2CP
|
||||
void I2PControlService::I2CPInfoHandler (std::ostringstream& results)
|
||||
{
|
||||
boost::property_tree::ptree pt;
|
||||
|
@ -785,5 +794,7 @@ namespace client
|
|||
|
||||
InsertParam (results, "I2CP", pt);
|
||||
}
|
||||
#endif // WITH_I2CP
|
||||
}
|
||||
}
|
||||
#endif // WITH_I2PC
|
|
@ -6,6 +6,8 @@
|
|||
* See full license text in LICENSE file at top of project tree
|
||||
*/
|
||||
|
||||
#ifdef WITH_I2PC
|
||||
|
||||
#ifndef I2P_CONTROL_H__
|
||||
#define I2P_CONTROL_H__
|
||||
|
||||
|
@ -114,9 +116,15 @@ namespace client
|
|||
void I2PTunnelInfoHandler (std::ostringstream& results);
|
||||
void HTTPProxyInfoHandler (std::ostringstream& results);
|
||||
void SOCKSInfoHandler (std::ostringstream& results);
|
||||
#ifdef WITH_SAM
|
||||
void SAMInfoHandler (std::ostringstream& results);
|
||||
#endif
|
||||
#ifdef WITH_BOB
|
||||
void BOBInfoHandler (std::ostringstream& results);
|
||||
#endif
|
||||
#ifdef WITH_I2CP
|
||||
void I2CPInfoHandler (std::ostringstream& results);
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
|
@ -141,3 +149,4 @@ namespace client
|
|||
}
|
||||
|
||||
#endif
|
||||
#endif // WITH_I2PC
|
Loading…
Add table
Add a link
Reference in a new issue