From cc4c80a5cad4c51c43545de108a77c99b8c4fd6f Mon Sep 17 00:00:00 2001 From: PobreGato <315121269+pobregat0@users.noreply.github.com> Date: Sun, 16 Aug 2026 02:38:47 +0300 Subject: [PATCH] round-robin over several outproxies in http proxy --- libi2pd_client/HTTPProxy.cpp | 16 +++++++++++++++- libi2pd_client/HTTPProxy.h | 6 ++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/libi2pd_client/HTTPProxy.cpp b/libi2pd_client/HTTPProxy.cpp index c9447d6d..f3d162be 100644 --- a/libi2pd_client/HTTPProxy.cpp +++ b/libi2pd_client/HTTPProxy.cpp @@ -6,6 +6,7 @@ * See full license text in LICENSE file at top of project tree */ +#include #include #include #include @@ -14,6 +15,7 @@ #include #include #include +#include #include #include @@ -792,8 +794,20 @@ namespace proxy HTTPProxy::HTTPProxy(const std::string& name, const std::string& address, uint16_t port, const std::string & outproxy, bool addresshelper, bool senduseragent, std::shared_ptr localDestination): TCPIPAcceptor (address, port, localDestination ? localDestination : i2p::client::context.GetSharedLocalDestination ()), - m_Name (name), m_OutproxyUrl (outproxy), m_Addresshelper (addresshelper), m_SendUserAgent (senduseragent) + m_Name (name), m_NextOutproxy (0), m_Addresshelper (addresshelper), m_SendUserAgent (senduseragent) { + // outproxy is a comma separated list, the same way a client tunnel takes several destinations + boost::split (m_OutproxyUrls, outproxy, boost::is_any_of (","), boost::token_compress_on); + for (auto& it: m_OutproxyUrls) boost::trim (it); + m_OutproxyUrls.erase (std::remove (m_OutproxyUrls.begin (), m_OutproxyUrls.end (), ""), m_OutproxyUrls.end ()); + } + + std::string HTTPProxy::GetOutproxyURL () + { + if (m_OutproxyUrls.empty ()) return ""; + auto url = m_OutproxyUrls[m_NextOutproxy]; + m_NextOutproxy = (m_NextOutproxy + 1) % m_OutproxyUrls.size (); + return url; } std::shared_ptr HTTPProxy::CreateHandler(std::shared_ptr socket) diff --git a/libi2pd_client/HTTPProxy.h b/libi2pd_client/HTTPProxy.h index 06ebe9e5..ea9a6aab 100644 --- a/libi2pd_client/HTTPProxy.h +++ b/libi2pd_client/HTTPProxy.h @@ -23,7 +23,8 @@ namespace proxy HTTPProxy(name, address, port, "", true, false, localDestination) {} ; ~HTTPProxy() {}; - std::string GetOutproxyURL() const { return m_OutproxyUrl; } + // picks the next outproxy, so several of them are used in turn + std::string GetOutproxyURL(); bool GetHelperSupport() const { return m_Addresshelper; } bool GetSendUserAgent () const { return m_SendUserAgent; } @@ -36,7 +37,8 @@ namespace proxy private: std::string m_Name; - std::string m_OutproxyUrl; + std::vector m_OutproxyUrls; + size_t m_NextOutproxy; bool m_Addresshelper, m_SendUserAgent; }; } // http