Skip to content

Commit

Permalink
process b32 address with path
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Feb 17, 2014
1 parent 10c7e05 commit f5fa953
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
27 changes: 21 additions & 6 deletions HTTPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,20 @@ namespace util
{
m_Buffer[bytes_transferred] = 0;
auto address = ExtractAddress ();
//LogPrint (address);
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
HandleRequest ();
boost::asio::async_write (*m_Socket, m_Reply.to_buffers(),
Expand Down Expand Up @@ -149,10 +160,14 @@ namespace util
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];
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);
if (!leaseSet || !leaseSet->HasNonExpiredLeases ())
{
Expand All @@ -173,7 +188,7 @@ namespace util
auto s = i2p::stream::CreateStream (leaseSet);
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);
std::stringstream ss;
uint8_t buf[8192];
Expand All @@ -193,7 +208,7 @@ namespace util
else // nothing received
ss << "<html>Not responding</html>";
s->Close ();
//DeleteStream (s);
DeleteStream (s);

m_Reply.content = ss.str ();
m_Reply.headers.resize(2);
Expand Down
2 changes: 1 addition & 1 deletion HTTPServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace util
void HandleWrite(const boost::system::error_code& ecode);

void HandleRequest ();
void HandleDestinationRequest (std::string b32);
void HandleDestinationRequest (const std::string& b32, const std::string& uri);
void FillContent (std::stringstream& s);
std::string ExtractAddress ();

Expand Down
2 changes: 1 addition & 1 deletion Streaming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ namespace stream

void StreamingDestination::HandleNextPacket (Packet * packet)
{
uint32_t sendStreamID = be32toh (*(uint32_t *)(packet->buf));
uint32_t sendStreamID = packet->GetSendStreamID ();
auto it = m_Streams.find (sendStreamID);
if (it != m_Streams.end ())
it->second->HandleNextPacket (packet);
Expand Down

0 comments on commit f5fa953

Please sign in to comment.