diff --git a/libi2pd_client/AddressBook.cpp b/libi2pd_client/AddressBook.cpp index 4eed9601..247e2fda 100644 --- a/libi2pd_client/AddressBook.cpp +++ b/libi2pd_client/AddressBook.cpp @@ -357,6 +357,22 @@ namespace client identHash = hash; } + std::string Address::ToBase32 () const + { + switch (addressType) + { + case eAddressIndentHash: + return identHash.ToBase32 (); + break; + case eAddressBlindedPublicKey: + if (blindedPublicKey) + return blindedPublicKey->ToB33 (); + break; + default: ; + } + return ""; + } + AddressBook::AddressBook (): m_Storage(nullptr), m_IsLoaded (false), m_NumRetries (0), m_DefaultSubscription (nullptr), m_SubscriptionsUpdateTimer (nullptr), m_IsEnabled (true) diff --git a/libi2pd_client/AddressBook.h b/libi2pd_client/AddressBook.h index 1b2672b5..5b89717a 100644 --- a/libi2pd_client/AddressBook.h +++ b/libi2pd_client/AddressBook.h @@ -53,6 +53,7 @@ namespace client Address (const i2p::data::IdentHash& hash); bool IsIdentHash () const { return addressType == eAddressIndentHash; }; bool IsValid () const { return addressType != eAddressInvalid; }; + std::string ToBase32 () const; }; inline std::string GetB32Address(const i2p::data::IdentHash& ident) { return ident.ToBase32().append(".b32.i2p"); } diff --git a/libi2pd_client/HTTPProxy.cpp b/libi2pd_client/HTTPProxy.cpp index 9cf7a1df..578e6d7e 100644 --- a/libi2pd_client/HTTPProxy.cpp +++ b/libi2pd_client/HTTPProxy.cpp @@ -501,19 +501,39 @@ namespace proxy } } /* check dest_host really exists and inside I2P network */ - if (str_rmatch(dest_host, ".i2p")) { - if (!i2p::client::context.GetAddressBook ().GetAddress (dest_host)) { + if (str_rmatch(dest_host, ".i2p")) + { + auto addr = i2p::client::context.GetAddressBook ().GetAddress (dest_host); + if (addr) + { + auto b32Host = addr->ToBase32 (); + if (!b32Host.empty ()) + m_ClientRequest.UpdateHeader("Host", b32Host + ".b32.i2p"); // replace our name to .b32.i2p address + else + { + // invaild address + HostNotFound(dest_host); + return true; + } + } + else + { HostNotFound(dest_host); return true; /* request processed */ } - } else { - if(m_OutproxyUrl.size()) { + } + else + { + if(m_OutproxyUrl.size()) + { LogPrint (eLogDebug, "HTTPProxy: Using outproxy ", m_OutproxyUrl); if(m_ProxyURL.parse(m_OutproxyUrl)) ForwardToUpstreamProxy(); else GenericProxyError(tr("Outproxy failure"), tr("Bad outproxy settings")); - } else { + } + else + { LogPrint (eLogWarning, "HTTPProxy: Outproxy failure for ", dest_host, ": no outproxy enabled"); std::stringstream ss; ss << tr("Host %s is not inside I2P network, but outproxy is not enabled", dest_host.c_str ()); GenericProxyError(tr("Outproxy failure"), ss.str());