mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
jump services
This commit is contained in:
parent
8f3daad502
commit
400e3d21f9
3 changed files with 42 additions and 1 deletions
|
@ -12,6 +12,7 @@
|
|||
#include "ClientContext.h"
|
||||
#include "I2PEndian.h"
|
||||
#include "I2PTunnel.h"
|
||||
#include "Config.h"
|
||||
|
||||
namespace i2p
|
||||
{
|
||||
|
@ -36,6 +37,7 @@ namespace proxy
|
|||
void Terminate();
|
||||
void AsyncSockRead();
|
||||
void HTTPRequestFailed(/*std::string message*/);
|
||||
void RedirectToJumpService();
|
||||
void ExtractRequest();
|
||||
bool ValidateHTTPRequest();
|
||||
void HandleJumpServices();
|
||||
|
@ -95,6 +97,17 @@ namespace proxy
|
|||
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)
|
||||
{
|
||||
m_state = nstate;
|
||||
|
@ -168,6 +181,13 @@ namespace proxy
|
|||
ExtractRequest(); //TODO: parse earlier
|
||||
if (!ValidateHTTPRequest()) return false;
|
||||
HandleJumpServices();
|
||||
|
||||
i2p::data::IdentHash identHash;
|
||||
if (!i2p::client::context.GetAddressBook ().GetIdentHash (m_address, identHash)){
|
||||
RedirectToJumpService();
|
||||
return false;
|
||||
}
|
||||
|
||||
m_request = m_method;
|
||||
m_request.push_back(' ');
|
||||
m_request += m_path;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue