Browse Source

show I2P tunnels at web console

pull/320/head
orignal 9 years ago
parent
commit
8fa053f7c7
  1. 6
      ClientContext.cpp
  2. 2
      ClientContext.h
  3. 28
      HTTPServer.cpp
  4. 1
      HTTPServer.h
  5. 19
      I2PTunnel.cpp
  6. 18
      I2PTunnel.h

6
ClientContext.cpp

@ -261,7 +261,7 @@ namespace client @@ -261,7 +261,7 @@ namespace client
std::shared_ptr<ClientDestination> 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<I2PClientTunnel>(clientTunnel))).second)
clientTunnel->Start ();
else
@ -280,7 +280,9 @@ namespace client @@ -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<i2p::data::IdentHash> idents;

2
ClientContext.h

@ -78,6 +78,8 @@ namespace client @@ -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;

28
HTTPServer.cpp

@ -201,6 +201,7 @@ namespace util @@ -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 @@ -385,6 +386,7 @@ namespace util
s << "<a href=/?" << HTTP_COMMAND_TUNNELS << ">Tunnels</a><br>";
s << "<a href=/?" << HTTP_COMMAND_TRANSIT_TUNNELS << ">Transit tunnels</a><br>";
s << "<a href=/?" << HTTP_COMMAND_TRANSPORTS << ">Transports</a><br><br>";
s << "<a href=/?" << HTTP_COMMAND_I2P_TUNNELS << ">I2P tunnels</a><br>";
if (i2p::client::context.GetSAMBridge ())
s << "<a href=/?" << HTTP_COMMAND_SAM_SESSIONS << ">SAM sessions</a><br><br>";
if (i2p::context.AcceptsTunnels ())
@ -482,6 +484,8 @@ namespace util @@ -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 @@ -691,6 +695,30 @@ namespace util
}
}
void HTTPConnection::ShowI2PTunnels (std::stringstream& s)
{
s << "<b>Client Tunnels:</b><br><br>";
for (auto& it: i2p::client::context.GetClientTunnels ())
{
s << it.second->GetName () << "<--";
auto& ident = it.second->GetLocalDestination ()->GetIdentHash();
s << "<a href=/?" << HTTP_COMMAND_LOCAL_DESTINATION;
s << "&" << HTTP_PARAM_BASE32_ADDRESS << "=" << ident.ToBase32 () << ">";
s << i2p::client::context.GetAddressBook ().ToAddress(ident);
s << "</a><br>"<< std::endl;
}
s << "<br><b>Server Tunnels:</b><br><br>";
for (auto& it: i2p::client::context.GetServerTunnels ())
{
s << it.second->GetName () << "-->";
auto& ident = it.second->GetLocalDestination ()->GetIdentHash();
s << "<a href=/?" << HTTP_COMMAND_LOCAL_DESTINATION;
s << "&" << HTTP_PARAM_BASE32_ADDRESS << "=" << ident.ToBase32 () << ">";
s << i2p::client::context.GetAddressBook ().ToAddress(ident);
s << "</a><br>"<< std::endl;
}
}
void HTTPConnection::StopAcceptingTunnels (std::stringstream& s)
{
s << "<b>Stop Accepting Tunnels:</b><br><br>";

1
HTTPServer.h

@ -69,6 +69,7 @@ namespace util @@ -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);

19
I2PTunnel.cpp

@ -262,8 +262,12 @@ namespace client @@ -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<ClientDestination> 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<ClientDestination> 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 @@ -302,9 +306,9 @@ namespace client
return nullptr;
}
I2PServerTunnel::I2PServerTunnel (const std::string& address, int port,
std::shared_ptr<ClientDestination> 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<ClientDestination> 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 @@ -392,8 +396,9 @@ namespace client
conn->Connect ();
}
I2PServerTunnelHTTP::I2PServerTunnelHTTP (const std::string& address, int port, std::shared_ptr<ClientDestination> localDestination, int inport):
I2PServerTunnel (address, port, localDestination, inport)
I2PServerTunnelHTTP::I2PServerTunnelHTTP (const std::string& name, const std::string& address,
int port, std::shared_ptr<ClientDestination> localDestination, int inport):
I2PServerTunnel (name, address, port, localDestination, inport)
{
}

18
I2PTunnel.h

@ -86,21 +86,25 @@ namespace client @@ -86,21 +86,25 @@ namespace client
// Implements TCPIPAcceptor
std::shared_ptr<I2PServiceHandler> CreateHandler(std::shared_ptr<boost::asio::ip::tcp::socket> socket);
const char* GetName() { return "I2P Client Tunnel"; }
public:
I2PClientTunnel (const std::string& destination, const std::string& address, int port, std::shared_ptr<ClientDestination> localDestination, int destinationPort = 0);
I2PClientTunnel (const std::string& name, const std::string& destination,
const std::string& address, int port, std::shared_ptr<ClientDestination> 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 @@ -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<ClientDestination> localDestination, int inport = 0);
void Start ();
@ -121,6 +125,8 @@ namespace client @@ -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 @@ -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<i2p::stream::StreamingDestination> m_PortDestination;
@ -144,7 +150,7 @@ namespace client @@ -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<ClientDestination> localDestination, int inport = 0);
private:

Loading…
Cancel
Save