|
|
@ -60,9 +60,20 @@ namespace util |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_Buffer[bytes_transferred] = 0; |
|
|
|
m_Buffer[bytes_transferred] = 0; |
|
|
|
auto address = ExtractAddress (); |
|
|
|
auto address = ExtractAddress (); |
|
|
|
//LogPrint (address);
|
|
|
|
|
|
|
|
if (address.length () > 1) // not just '/'
|
|
|
|
if (address.length () > 1) // not just '/'
|
|
|
|
HandleDestinationRequest (address.substr (1)); // exclude '/'
|
|
|
|
{ |
|
|
|
|
|
|
|
std::string uri ("/"), b32; |
|
|
|
|
|
|
|
size_t pos = address.find ('/', 1); |
|
|
|
|
|
|
|
if (pos == std::string::npos) |
|
|
|
|
|
|
|
b32 = address.substr (1); // excluding leading '/' to end of line
|
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
b32 = address.substr (1, pos - 1); // excluding leading '/' to next '/'
|
|
|
|
|
|
|
|
uri = address.substr (pos); // rest of line
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HandleDestinationRequest (b32, uri); |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
HandleRequest (); |
|
|
|
HandleRequest (); |
|
|
|
boost::asio::async_write (*m_Socket, m_Reply.to_buffers(), |
|
|
|
boost::asio::async_write (*m_Socket, m_Reply.to_buffers(), |
|
|
@ -149,10 +160,14 @@ namespace util |
|
|
|
s << "<p><a href=\"zmw2cyw2vj7f6obx3msmdvdepdhnw2ctc4okza2zjxlukkdfckhq\">Flibusta</a></p>"; |
|
|
|
s << "<p><a href=\"zmw2cyw2vj7f6obx3msmdvdepdhnw2ctc4okza2zjxlukkdfckhq\">Flibusta</a></p>"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void HTTPConnection::HandleDestinationRequest (std::string b32) |
|
|
|
void HTTPConnection::HandleDestinationRequest (const std::string& b32, const std::string& uri) |
|
|
|
{ |
|
|
|
{ |
|
|
|
uint8_t destination[32]; |
|
|
|
uint8_t destination[32]; |
|
|
|
i2p::data::Base32ToByteStream (b32.c_str (), b32.length (), destination, 32); |
|
|
|
if (i2p::data::Base32ToByteStream (b32.c_str (), b32.length (), destination, 32) != 32) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LogPrint ("Invalid Base32 address ", b32); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
auto leaseSet = i2p::data::netdb.FindLeaseSet (destination); |
|
|
|
auto leaseSet = i2p::data::netdb.FindLeaseSet (destination); |
|
|
|
if (!leaseSet || !leaseSet->HasNonExpiredLeases ()) |
|
|
|
if (!leaseSet || !leaseSet->HasNonExpiredLeases ()) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -173,7 +188,7 @@ namespace util |
|
|
|
auto s = i2p::stream::CreateStream (leaseSet); |
|
|
|
auto s = i2p::stream::CreateStream (leaseSet); |
|
|
|
if (s) |
|
|
|
if (s) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::string request = "GET / HTTP/1.1\n Host:" + b32 + ".b32.i2p\n"; |
|
|
|
std::string request = "GET " + uri + " HTTP/1.1\n Host:" + b32 + ".b32.i2p\n"; |
|
|
|
s->Send ((uint8_t *)request.c_str (), request.length (), 10); |
|
|
|
s->Send ((uint8_t *)request.c_str (), request.length (), 10); |
|
|
|
std::stringstream ss; |
|
|
|
std::stringstream ss; |
|
|
|
uint8_t buf[8192]; |
|
|
|
uint8_t buf[8192]; |
|
|
@ -193,7 +208,7 @@ namespace util |
|
|
|
else // nothing received
|
|
|
|
else // nothing received
|
|
|
|
ss << "<html>Not responding</html>"; |
|
|
|
ss << "<html>Not responding</html>"; |
|
|
|
s->Close (); |
|
|
|
s->Close (); |
|
|
|
//DeleteStream (s);
|
|
|
|
DeleteStream (s); |
|
|
|
|
|
|
|
|
|
|
|
m_Reply.content = ss.str (); |
|
|
|
m_Reply.content = ss.str (); |
|
|
|
m_Reply.headers.resize(2); |
|
|
|
m_Reply.headers.resize(2); |
|
|
|