From 6066b7073ff5d0961ba6304b865121d771defe4c Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 16 Mar 2014 21:18:23 -0400 Subject: [PATCH] handle .i2p addresses --- HTTPServer.cpp | 31 ++++++++++++++++++++++++------- HTTPServer.h | 2 +- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/HTTPServer.cpp b/HTTPServer.cpp index f02b0ba9..f914fefd 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -197,14 +197,31 @@ namespace util s << "

Flibusta

"; } - 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 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]; diff --git a/HTTPServer.h b/HTTPServer.h index a62a2074..546f5bc2 100644 --- a/HTTPServer.h +++ b/HTTPServer.h @@ -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 ();