Browse Source

handle .i2p addresses

pull/46/head
orignal 10 years ago
parent
commit
6066b7073f
  1. 31
      HTTPServer.cpp
  2. 2
      HTTPServer.h

31
HTTPServer.cpp

@ -197,14 +197,31 @@ namespace util @@ -197,14 +197,31 @@ namespace util
s << "<p><a href=\"zmw2cyw2vj7f6obx3msmdvdepdhnw2ctc4okza2zjxlukkdfckhq\">Flibusta</a></p>";
}
void HTTPConnection::HandleDestinationRequest (const std::string& b32, const std::string& uri)
void HTTPConnection::HandleDestinationRequest (const std::string& address, const std::string& uri)
{
uint8_t destination[32];
if (i2p::data::Base32ToByteStream (b32.c_str (), b32.length (), destination, 32) != 32)
{
LogPrint ("Invalid Base32 address ", b32);
return;
i2p::data::IdentHash destination;
std::string fullAddress;
if (address.find (".i2p") != std::string::npos)
{
auto addr = i2p::data::netdb.FindAddress(address);
if (!addr)
{
LogPrint ("Unknown address ", address);
return;
}
destination = *addr;
fullAddress = address;
}
else
{
if (i2p::data::Base32ToByteStream (address.c_str (), address.length (), (uint8_t *)destination, 32) != 32)
{
LogPrint ("Invalid Base32 address ", address);
return;
}
fullAddress = address + ".b32.i2p";
}
auto leaseSet = i2p::data::netdb.FindLeaseSet (destination);
if (!leaseSet || !leaseSet->HasNonExpiredLeases ())
{
@ -225,7 +242,7 @@ namespace util @@ -225,7 +242,7 @@ namespace util
auto s = i2p::stream::CreateStream (*leaseSet);
if (s)
{
std::string request = "GET " + uri + " HTTP/1.1\n Host:" + b32 + ".b32.i2p\n";
std::string request = "GET " + uri + " HTTP/1.1\n Host:" + fullAddress + "\n";
s->Send ((uint8_t *)request.c_str (), request.length (), 10);
std::stringstream ss;
uint8_t buf[8192];

2
HTTPServer.h

@ -48,7 +48,7 @@ namespace util @@ -48,7 +48,7 @@ namespace util
void HandleWrite(const boost::system::error_code& ecode);
void HandleRequest ();
void HandleDestinationRequest (const std::string& b32, const std::string& uri);
void HandleDestinationRequest (const std::string& address, const std::string& uri);
void FillContent (std::stringstream& s);
std::string ExtractAddress ();

Loading…
Cancel
Save