From 706da6e4318558e6d9b9d5e2ca53557013ac1e31 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 2 Apr 2019 13:11:49 -0400 Subject: [PATCH] allow .b32.i2p in jump links --- libi2pd_client/AddressBook.cpp | 26 ++++++++++++++++++++------ libi2pd_client/AddressBook.h | 2 +- libi2pd_client/HTTPProxy.cpp | 11 +++++------ 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/libi2pd_client/AddressBook.cpp b/libi2pd_client/AddressBook.cpp index bf22c279..04e5d6bf 100644 --- a/libi2pd_client/AddressBook.cpp +++ b/libi2pd_client/AddressBook.cpp @@ -347,13 +347,27 @@ namespace client return nullptr; } - void AddressBook::InsertAddress (const std::string& address, const std::string& base64) + void AddressBook::InsertAddress (const std::string& address, const std::string& jump) { - auto ident = std::make_shared(); - ident->FromBase64 (base64); - m_Storage->AddAddress (ident); - m_Addresses[address] = std::make_shared
(ident->GetIdentHash ()); - LogPrint (eLogInfo, "Addressbook: added ", address," -> ", ToAddress(ident->GetIdentHash ())); + auto pos = jump.find(".b32.i2p"); + if (pos != std::string::npos) + { + m_Addresses[address] = std::make_shared
(jump.substr (0, pos)); + LogPrint (eLogInfo, "Addressbook: added ", address," -> ", jump); + } + else + { + // assume base64 + auto ident = std::make_shared(); + if (ident->FromBase64 (jump)) + { + m_Storage->AddAddress (ident); + m_Addresses[address] = std::make_shared
(ident->GetIdentHash ()); + LogPrint (eLogInfo, "Addressbook: added ", address," -> ", ToAddress(ident->GetIdentHash ())); + } + else + LogPrint (eLogError, "Addressbook: malformed address ", jump); + } } void AddressBook::InsertFullAddress (std::shared_ptr address) diff --git a/libi2pd_client/AddressBook.h b/libi2pd_client/AddressBook.h index b3dfef47..47ad9993 100644 --- a/libi2pd_client/AddressBook.h +++ b/libi2pd_client/AddressBook.h @@ -78,7 +78,7 @@ namespace client std::shared_ptr GetFullAddress (const std::string& address); std::shared_ptr FindAddress (const std::string& address); void LookupAddress (const std::string& address); - void InsertAddress (const std::string& address, const std::string& base64); // for jump service + void InsertAddress (const std::string& address, const std::string& jump); // for jump links void InsertFullAddress (std::shared_ptr address); bool LoadHostsFromStream (std::istream& f, bool is_update); diff --git a/libi2pd_client/HTTPProxy.cpp b/libi2pd_client/HTTPProxy.cpp index ee1b241d..1485f5d5 100644 --- a/libi2pd_client/HTTPProxy.cpp +++ b/libi2pd_client/HTTPProxy.cpp @@ -234,8 +234,6 @@ namespace proxy { */ bool HTTPReqHandler::HandleRequest() { - std::string b64; - m_req_len = m_ClientRequest.parse(m_recv_buf); if (m_req_len == 0) @@ -252,7 +250,8 @@ namespace proxy { m_RequestURL.parse(m_ClientRequest.uri); bool m_Confirm; - if (ExtractAddressHelper(m_RequestURL, b64, m_Confirm)) + std::string jump; + if (ExtractAddressHelper(m_RequestURL, jump, m_Confirm)) { bool addresshelper; i2p::config::GetOption("httpproxy.addresshelper", addresshelper); if (!addresshelper) @@ -263,8 +262,8 @@ namespace proxy { } if (!i2p::client::context.GetAddressBook ().FindAddress (m_RequestURL.host) || m_Confirm) { - i2p::client::context.GetAddressBook ().InsertAddress (m_RequestURL.host, b64); - LogPrint (eLogInfo, "HTTPProxy: added b64 from addresshelper for ", m_RequestURL.host); + i2p::client::context.GetAddressBook ().InsertAddress (m_RequestURL.host, jump); + LogPrint (eLogInfo, "HTTPProxy: added address from addresshelper for ", m_RequestURL.host); std::string full_url = m_RequestURL.to_string(); std::stringstream ss; ss << "Host " << m_RequestURL.host << " added to router's addressbook from helper. " @@ -276,7 +275,7 @@ namespace proxy { { std::stringstream ss; ss << "Host " << m_RequestURL.host << " already in router's addressbook. " - << "Click here to update record."; + << "Click here to update record."; GenericProxyInfo("Addresshelper found", ss.str().c_str()); return true; /* request processed */ }