From d7deb938c59d1ac150f26e95e58677e985c7f18c Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 2 Jun 2015 16:21:38 -0400 Subject: [PATCH] catch HTTP header of HTTP server tunnel connection --- I2PTunnel.cpp | 14 +++++++++++++- I2PTunnel.h | 10 ++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/I2PTunnel.cpp b/I2PTunnel.cpp index 9bf5c658..b6cabd30 100644 --- a/I2PTunnel.cpp +++ b/I2PTunnel.cpp @@ -165,10 +165,22 @@ namespace client I2PTunnelConnectionHTTP::I2PTunnelConnectionHTTP (I2PService * owner, std::shared_ptr stream, std::shared_ptr socket, const boost::asio::ip::tcp::endpoint& target, const std::string& host): - I2PTunnelConnection (owner, stream, socket, target) + I2PTunnelConnection (owner, stream, socket, target), m_HeaderSent (false) { } + void I2PTunnelConnectionHTTP::Write (const uint8_t * buf, size_t len) + { + if (m_HeaderSent) + I2PTunnelConnection::Write (buf, len); + else + { + m_Header.write ((const char *)buf, len); + I2PTunnelConnection::Write ((uint8_t *)m_Header.str ().c_str (), m_Header.str ().length ()); + m_HeaderSent = true; + } + } + /* This handler tries to stablish a connection with the desired server and dies if it fails to do so */ class I2PClientTunnelHandler: public I2PServiceHandler, public std::enable_shared_from_this { diff --git a/I2PTunnel.h b/I2PTunnel.h index f6f9d3ec..127f5c4f 100644 --- a/I2PTunnel.h +++ b/I2PTunnel.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "Identity.h" #include "Destination.h" @@ -63,6 +64,15 @@ namespace client I2PTunnelConnectionHTTP (I2PService * owner, std::shared_ptr stream, std::shared_ptr socket, const boost::asio::ip::tcp::endpoint& target, const std::string& host); + + protected: + + void Write (const uint8_t * buf, size_t len); + + private: + + std::stringstream m_Header; + bool m_HeaderSent; }; class I2PClientTunnel: public TCPIPAcceptor