diff --git a/ClientContext.cpp b/ClientContext.cpp index 95d2d0a1..dacba5cd 100644 --- a/ClientContext.cpp +++ b/ClientContext.cpp @@ -261,7 +261,7 @@ namespace client std::shared_ptr localDestination = nullptr; if (keys.length () > 0) localDestination = LoadLocalDestination (keys, false, sigType); - auto clientTunnel = new I2PClientTunnel (dest, address, port, localDestination, destinationPort); + auto clientTunnel = new I2PClientTunnel (name, dest, address, port, localDestination, destinationPort); if (m_ClientTunnels.insert (std::make_pair (port, std::unique_ptr(clientTunnel))).second) clientTunnel->Start (); else @@ -280,7 +280,9 @@ namespace client i2p::data::SigningKeyType sigType = section.second.get (I2P_SERVER_TUNNEL_SIGNATURE_TYPE, i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256); auto localDestination = LoadLocalDestination (keys, true, sigType); - I2PServerTunnel * serverTunnel = (type == I2P_TUNNELS_SECTION_TYPE_HTTP) ? new I2PServerTunnelHTTP (host, port, localDestination, inPort) : new I2PServerTunnel (host, port, localDestination, inPort); + I2PServerTunnel * serverTunnel = (type == I2P_TUNNELS_SECTION_TYPE_HTTP) ? + new I2PServerTunnelHTTP (name, host, port, localDestination, inPort) : + new I2PServerTunnel (name, host, port, localDestination, inPort); if (accessList.length () > 0) { std::set idents; diff --git a/ClientContext.h b/ClientContext.h index 44e3f5b9..4495d505 100644 --- a/ClientContext.h +++ b/ClientContext.h @@ -78,6 +78,8 @@ namespace client public: // for HTTP const decltype(m_Destinations)& GetDestinations () const { return m_Destinations; }; + const decltype(m_ClientTunnels)& GetClientTunnels () const { return m_ClientTunnels; }; + const decltype(m_ServerTunnels)& GetServerTunnels () const { return m_ServerTunnels; }; }; extern ClientContext context; diff --git a/HTTPServer.cpp b/HTTPServer.cpp index 40edd5c7..e6099053 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -201,6 +201,7 @@ namespace util const char HTTP_COMMAND_SAM_SESSIONS[] = "sam_sessions"; const char HTTP_COMMAND_SAM_SESSION[] = "sam_session"; const char HTTP_PARAM_SAM_SESSION_ID[] = "id"; + const char HTTP_COMMAND_I2P_TUNNELS[] = "i2p_tunnels"; namespace misc_strings { @@ -385,6 +386,7 @@ namespace util s << "Tunnels
"; s << "Transit tunnels
"; s << "Transports

"; + s << "I2P tunnels
"; if (i2p::client::context.GetSAMBridge ()) s << "SAM sessions

"; if (i2p::context.AcceptsTunnels ()) @@ -482,6 +484,8 @@ namespace util auto id = params[HTTP_PARAM_SAM_SESSION_ID]; ShowSAMSession (id, s); } + else if (cmd == HTTP_COMMAND_I2P_TUNNELS) + ShowI2PTunnels (s); } void HTTPConnection::ShowLocalDestinations (std::stringstream& s) @@ -691,6 +695,30 @@ namespace util } } + void HTTPConnection::ShowI2PTunnels (std::stringstream& s) + { + s << "Client Tunnels:

"; + for (auto& it: i2p::client::context.GetClientTunnels ()) + { + s << it.second->GetName () << "<--"; + auto& ident = it.second->GetLocalDestination ()->GetIdentHash(); + s << ""; + s << i2p::client::context.GetAddressBook ().ToAddress(ident); + s << "
"<< std::endl; + } + s << "
Server Tunnels:

"; + for (auto& it: i2p::client::context.GetServerTunnels ()) + { + s << it.second->GetName () << "-->"; + auto& ident = it.second->GetLocalDestination ()->GetIdentHash(); + s << ""; + s << i2p::client::context.GetAddressBook ().ToAddress(ident); + s << "
"<< std::endl; + } + } + void HTTPConnection::StopAcceptingTunnels (std::stringstream& s) { s << "Stop Accepting Tunnels:

"; diff --git a/HTTPServer.h b/HTTPServer.h index b4349c5b..702e3191 100644 --- a/HTTPServer.h +++ b/HTTPServer.h @@ -69,6 +69,7 @@ namespace util void ShowLocalDestination (const std::string& b32, std::stringstream& s); void ShowSAMSessions (std::stringstream& s); void ShowSAMSession (const std::string& id, std::stringstream& s); + void ShowI2PTunnels (std::stringstream& s); void StartAcceptingTunnels (std::stringstream& s); void StopAcceptingTunnels (std::stringstream& s); void RunPeerTest (std::stringstream& s); diff --git a/I2PTunnel.cpp b/I2PTunnel.cpp index f6f5806f..a281334f 100644 --- a/I2PTunnel.cpp +++ b/I2PTunnel.cpp @@ -262,8 +262,12 @@ namespace client Done(shared_from_this()); } - I2PClientTunnel::I2PClientTunnel (const std::string& destination, const std::string& address, int port, std::shared_ptr localDestination, int destinationPort): - TCPIPAcceptor (address, port, localDestination), m_Destination (destination), m_DestinationIdentHash (nullptr), m_DestinationPort (destinationPort) {} + I2PClientTunnel::I2PClientTunnel (const std::string& name, const std::string& destination, + const std::string& address, int port, std::shared_ptr localDestination, int destinationPort): + TCPIPAcceptor (address, port, localDestination), m_Name (name), m_Destination (destination), + m_DestinationIdentHash (nullptr), m_DestinationPort (destinationPort) + { + } void I2PClientTunnel::Start () { @@ -302,9 +306,9 @@ namespace client return nullptr; } - I2PServerTunnel::I2PServerTunnel (const std::string& address, int port, - std::shared_ptr localDestination, int inport): - I2PService (localDestination), m_Address (address), m_Port (port), m_IsAccessList (false) + I2PServerTunnel::I2PServerTunnel (const std::string& name, const std::string& address, + int port, std::shared_ptr localDestination, int inport): + I2PService (localDestination), m_Name (name), m_Address (address), m_Port (port), m_IsAccessList (false) { m_PortDestination = localDestination->CreateStreamingDestination (inport > 0 ? inport : port); } @@ -392,8 +396,9 @@ namespace client conn->Connect (); } - I2PServerTunnelHTTP::I2PServerTunnelHTTP (const std::string& address, int port, std::shared_ptr localDestination, int inport): - I2PServerTunnel (address, port, localDestination, inport) + I2PServerTunnelHTTP::I2PServerTunnelHTTP (const std::string& name, const std::string& address, + int port, std::shared_ptr localDestination, int inport): + I2PServerTunnel (name, address, port, localDestination, inport) { } diff --git a/I2PTunnel.h b/I2PTunnel.h index a0716897..146466c5 100644 --- a/I2PTunnel.h +++ b/I2PTunnel.h @@ -86,21 +86,25 @@ namespace client // Implements TCPIPAcceptor std::shared_ptr CreateHandler(std::shared_ptr socket); - const char* GetName() { return "I2P Client Tunnel"; } public: - I2PClientTunnel (const std::string& destination, const std::string& address, int port, std::shared_ptr localDestination, int destinationPort = 0); + I2PClientTunnel (const std::string& name, const std::string& destination, + const std::string& address, int port, std::shared_ptr localDestination, int destinationPort = 0); ~I2PClientTunnel () {} void Start (); void Stop (); + const char* GetName() { return m_Name.c_str (); } + private: const i2p::data::IdentHash * GetIdentHash (); - std::string m_Destination; + private: + + std::string m_Name, m_Destination; const i2p::data::IdentHash * m_DestinationIdentHash; int m_DestinationPort; }; @@ -109,7 +113,7 @@ namespace client { public: - I2PServerTunnel (const std::string& address, int port, + I2PServerTunnel (const std::string& name, const std::string& address, int port, std::shared_ptr localDestination, int inport = 0); void Start (); @@ -121,6 +125,8 @@ namespace client int GetPort () const { return m_Port; }; const boost::asio::ip::tcp::endpoint& GetEndpoint () const { return m_Endpoint; } + const char* GetName() { return m_Name.c_str (); } + private: void HandleResolve (const boost::system::error_code& ecode, boost::asio::ip::tcp::resolver::iterator it, @@ -132,7 +138,7 @@ namespace client private: - std::string m_Address; + std::string m_Name, m_Address; int m_Port; boost::asio::ip::tcp::endpoint m_Endpoint; std::shared_ptr m_PortDestination; @@ -144,7 +150,7 @@ namespace client { public: - I2PServerTunnelHTTP (const std::string& address, int port, + I2PServerTunnelHTTP (const std::string& name, const std::string& address, int port, std::shared_ptr localDestination, int inport = 0); private: