From 90005c8237c013ab268b20a33d926e3d781890cf Mon Sep 17 00:00:00 2001 From: "Francisco Blas (klondike) Izquierdo Riera" Date: Wed, 7 Jan 2015 20:44:24 +0100 Subject: [PATCH] Migrate to I2Pservice --- Destination.cpp | 12 ------------ Destination.h | 6 +++--- HTTPProxy.cpp | 3 +-- I2PService.cpp | 12 ++++++++++++ I2PService.h | 1 + SOCKS.cpp | 3 +-- 6 files changed, 18 insertions(+), 19 deletions(-) diff --git a/Destination.cpp b/Destination.cpp index 154cfee0..abaf0de0 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -387,18 +387,6 @@ namespace client } } - void ClientDestination::CreateStream (StreamRequestComplete streamRequestComplete, const std::string& dest, int port) { - assert(streamRequestComplete); - i2p::data::IdentHash identHash; - if (i2p::client::context.GetAddressBook ().GetIdentHash (dest, identHash)) - CreateStream (streamRequestComplete, identHash, port); - else - { - LogPrint (eLogWarning, "Remote destination ", dest, " not found"); - streamRequestComplete (nullptr); - } - } - void ClientDestination::CreateStream (StreamRequestComplete streamRequestComplete, const i2p::data::IdentHash& dest, int port) { assert(streamRequestComplete); const i2p::data::LeaseSet * leaseSet = FindLeaseSet (dest); diff --git a/Destination.h b/Destination.h index b4d910ad..14580e6b 100644 --- a/Destination.h +++ b/Destination.h @@ -36,7 +36,9 @@ namespace client const char I2CP_PARAM_OUTBOUND_TUNNEL_LENGTH[] = "outbound.length"; const int DEFAULT_OUTBOUND_TUNNEL_LENGTH = 3; const int STREAM_REQUEST_TIMEOUT = 60; //in seconds - + + typedef std::function stream)> StreamRequestComplete; + class ClientDestination: public i2p::garlic::GarlicDestination { typedef std::function RequestComplete; @@ -49,7 +51,6 @@ namespace client RequestComplete requestComplete; }; - typedef std::function stream)> StreamRequestComplete; public: @@ -67,7 +68,6 @@ namespace client // streaming i2p::stream::StreamingDestination * GetStreamingDestination () const { return m_StreamingDestination; }; - void CreateStream (StreamRequestComplete streamRequestComplete, const std::string& dest, int port = 0); void CreateStream (StreamRequestComplete streamRequestComplete, const i2p::data::IdentHash& dest, int port = 0); std::shared_ptr CreateStream (const i2p::data::LeaseSet& remote, int port = 0); void AcceptStreams (const i2p::stream::StreamingDestination::Acceptor& acceptor); diff --git a/HTTPProxy.cpp b/HTTPProxy.cpp index 8f3bf835..22940592 100644 --- a/HTTPProxy.cpp +++ b/HTTPProxy.cpp @@ -196,8 +196,7 @@ namespace proxy if (HandleData(m_http_buff, len)) { if (m_state == DONE) { LogPrint(eLogInfo,"--- HTTP Proxy requested: ", m_url); - GetOwner()->GetLocalDestination ()->CreateStream ( - std::bind (&HTTPProxyHandler::HandleStreamRequestComplete, + GetOwner()->CreateStream (std::bind (&HTTPProxyHandler::HandleStreamRequestComplete, this, std::placeholders::_1), m_address, m_port); } else { AsyncSockRead(); diff --git a/I2PService.cpp b/I2PService.cpp index 04eca700..062713a0 100644 --- a/I2PService.cpp +++ b/I2PService.cpp @@ -15,5 +15,17 @@ namespace client i2p::client::context.CreateNewLocalDestination (false, I2P_SERVICE_DEFAULT_KEY_TYPE)) { } + + void ClientDestination::CreateStream (StreamRequestComplete streamRequestComplete, const std::string& dest, int port) { + assert(streamRequestComplete); + i2p::data::IdentHash identHash; + if (i2p::client::context.GetAddressBook ().GetIdentHash (dest, identHash)) + localDestination->CreateStream (streamRequestComplete, identHash, port); + else + { + LogPrint (eLogWarning, "Remote destination ", dest, " not found"); + streamRequestComplete (nullptr); + } + } } } diff --git a/I2PService.h b/I2PService.h index cbdbc82d..91835565 100644 --- a/I2PService.h +++ b/I2PService.h @@ -35,6 +35,7 @@ namespace client inline ClientDestination * GetLocalDestination () { return m_LocalDestination; }; inline void SetLocalDestination (ClientDestination * dest) { m_LocalDestination = dest; }; + void CreateStream (StreamRequestComplete streamRequestComplete, const std::string& dest, int port = 0); inline boost::asio::io_service& GetService () { return m_LocalDestination->GetService (); }; diff --git a/SOCKS.cpp b/SOCKS.cpp index be6c4824..0bc2e051 100644 --- a/SOCKS.cpp +++ b/SOCKS.cpp @@ -454,8 +454,7 @@ namespace proxy if (HandleData(m_sock_buff, len)) { if (m_state == DONE) { LogPrint(eLogInfo,"--- SOCKS requested ", m_address.dns.ToString(), ":" , m_port); - GetOwner()->GetLocalDestination ()->CreateStream ( - std::bind (&SOCKSHandler::HandleStreamRequestComplete, + GetOwner()->CreateStream ( std::bind (&SOCKSHandler::HandleStreamRequestComplete, this, std::placeholders::_1), m_address.dns.ToString(), m_port); } else { AsyncSockRead();