Browse Source

jump services

pull/410/head
xcps 9 years ago
parent
commit
400e3d21f9
  1. 20
      HTTPProxy.cpp
  2. 22
      HTTPServer.cpp
  3. 1
      HTTPServer.h

20
HTTPProxy.cpp

@ -12,6 +12,7 @@
#include "ClientContext.h" #include "ClientContext.h"
#include "I2PEndian.h" #include "I2PEndian.h"
#include "I2PTunnel.h" #include "I2PTunnel.h"
#include "Config.h"
namespace i2p namespace i2p
{ {
@ -36,6 +37,7 @@ namespace proxy
void Terminate(); void Terminate();
void AsyncSockRead(); void AsyncSockRead();
void HTTPRequestFailed(/*std::string message*/); void HTTPRequestFailed(/*std::string message*/);
void RedirectToJumpService();
void ExtractRequest(); void ExtractRequest();
bool ValidateHTTPRequest(); bool ValidateHTTPRequest();
void HandleJumpServices(); void HandleJumpServices();
@ -95,6 +97,17 @@ namespace proxy
std::bind(&HTTPProxyHandler::SentHTTPFailed, shared_from_this(), std::placeholders::_1)); std::bind(&HTTPProxyHandler::SentHTTPFailed, shared_from_this(), std::placeholders::_1));
} }
void HTTPProxyHandler::RedirectToJumpService(/*HTTPProxyHandler::errTypes error*/)
{
std::stringstream response;
std::string httpAddr; i2p::config::GetOption("http.address", httpAddr);
uint16_t httpPort; i2p::config::GetOption("http.port", httpPort);
response << "HTTP/1.1 302 Found\r\nLocation: http://" << httpAddr << ":" << httpPort << "/?jumpservices=&address=" << m_address << "\r\n\r\n";
boost::asio::async_write(*m_sock, boost::asio::buffer(response.str (),response.str ().length ()),
std::bind(&HTTPProxyHandler::SentHTTPFailed, shared_from_this(), std::placeholders::_1));
}
void HTTPProxyHandler::EnterState(HTTPProxyHandler::state nstate) void HTTPProxyHandler::EnterState(HTTPProxyHandler::state nstate)
{ {
m_state = nstate; m_state = nstate;
@ -168,6 +181,13 @@ namespace proxy
ExtractRequest(); //TODO: parse earlier ExtractRequest(); //TODO: parse earlier
if (!ValidateHTTPRequest()) return false; if (!ValidateHTTPRequest()) return false;
HandleJumpServices(); HandleJumpServices();
i2p::data::IdentHash identHash;
if (!i2p::client::context.GetAddressBook ().GetIdentHash (m_address, identHash)){
RedirectToJumpService();
return false;
}
m_request = m_method; m_request = m_method;
m_request.push_back(' '); m_request.push_back(' ');
m_request += m_path; m_request += m_path;

22
HTTPServer.cpp

@ -203,6 +203,9 @@ namespace util
const char HTTP_COMMAND_SAM_SESSION[] = "sam_session"; const char HTTP_COMMAND_SAM_SESSION[] = "sam_session";
const char HTTP_PARAM_SAM_SESSION_ID[] = "id"; const char HTTP_PARAM_SAM_SESSION_ID[] = "id";
const char HTTP_COMMAND_I2P_TUNNELS[] = "i2p_tunnels"; const char HTTP_COMMAND_I2P_TUNNELS[] = "i2p_tunnels";
const char HTTP_COMMAND_JUMPSERVICES[] = "jumpservices=";
const char HTTP_PARAM_ADDRESS[] = "address";
namespace misc_strings namespace misc_strings
{ {
@ -393,6 +396,7 @@ namespace util
else else
s << "<a href=/?" << HTTP_COMMAND_START_ACCEPTING_TUNNELS << ">Start accepting tunnels</a><br>\r\n<br>\r\n"; s << "<a href=/?" << HTTP_COMMAND_START_ACCEPTING_TUNNELS << ">Start accepting tunnels</a><br>\r\n<br>\r\n";
s << "<a href=/?" << HTTP_COMMAND_RUN_PEER_TEST << ">Run peer test</a><br>\r\n<br>\r\n"; s << "<a href=/?" << HTTP_COMMAND_RUN_PEER_TEST << ">Run peer test</a><br>\r\n<br>\r\n";
s << "<a href=/?" << HTTP_COMMAND_JUMPSERVICES << "&address=example.i2p>Jump services</a><br>\r\n<br>\r\n";
s << "</div><div class=right>"; s << "</div><div class=right>";
if (address.length () > 1) if (address.length () > 1)
HandleCommand (address.substr (2), s); HandleCommand (address.substr (2), s);
@ -464,7 +468,13 @@ namespace util
ShowTransports (s); ShowTransports (s);
else if (cmd == HTTP_COMMAND_TUNNELS) else if (cmd == HTTP_COMMAND_TUNNELS)
ShowTunnels (s); ShowTunnels (s);
else if (cmd == HTTP_COMMAND_TRANSIT_TUNNELS) else if (cmd == HTTP_COMMAND_JUMPSERVICES)
{
std::map<std::string, std::string> params;
ExtractParams (command.substr (paramsPos), params);
auto address = params[HTTP_PARAM_ADDRESS];
ShowJumpServices (address, s);
} else if (cmd == HTTP_COMMAND_TRANSIT_TUNNELS)
ShowTransitTunnels (s); ShowTransitTunnels (s);
else if (cmd == HTTP_COMMAND_START_ACCEPTING_TUNNELS) else if (cmd == HTTP_COMMAND_START_ACCEPTING_TUNNELS)
StartAcceptingTunnels (s); StartAcceptingTunnels (s);
@ -494,6 +504,16 @@ namespace util
ShowI2PTunnels (s); ShowI2PTunnels (s);
} }
void HTTPConnection::ShowJumpServices (const std::string& address, std::stringstream& s)
{
s << "<form type=\"get\" action=\"/\">";
s << "<input type=\"hidden\" name=\"jumpservices\">";
s << "<input type=\"text\" value=\"" << address << "\" name=\"address\"> </form><br>\r\n";
s << "<b>Jump services for " << address << "</b>";
s << "<ul><li><a href=\"http://inr.i2p/search/?q=" << address << "\">Slow jump service</a> <br>\r\n";
s << "<li><a href=\"http://stats.i2p/cgi-bin/jump.cgi?a=" << address << "\">zzz jump service</a></ul>";
}
void HTTPConnection::ShowLocalDestinations (std::stringstream& s) void HTTPConnection::ShowLocalDestinations (std::stringstream& s)
{ {
s << "<b>Local Destinations:</b><br>\r\n<br>\r\n"; s << "<b>Local Destinations:</b><br>\r\n<br>\r\n";

1
HTTPServer.h

@ -62,6 +62,7 @@ namespace util
void HandleRequest (const std::string& address); void HandleRequest (const std::string& address);
void HandleCommand (const std::string& command, std::stringstream& s); void HandleCommand (const std::string& command, std::stringstream& s);
void ShowJumpServices (const std::string& address, std::stringstream& s);
void ShowTransports (std::stringstream& s); void ShowTransports (std::stringstream& s);
void ShowTunnels (std::stringstream& s); void ShowTunnels (std::stringstream& s);
void ShowTransitTunnels (std::stringstream& s); void ShowTransitTunnels (std::stringstream& s);

Loading…
Cancel
Save