From 85c0377e87e82ad609be692b57109f39d1c5d96e Mon Sep 17 00:00:00 2001 From: faumaray Date: Tue, 23 Jun 2026 13:49:26 +0300 Subject: [PATCH] Drop HTTP/proxy mirror types; speak Void::Net directly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Delete Api::HttpMethod/Header/Request/Response/ProxyConfig/ProxyType + RetryConfig — they duplicated Void::Net::* and Void::Retry. INetworkClient now takes/returns Void::Net::Request/Response/Header/ProxyConfig (retry tuning drops off the public interface; it was unused and lives inside the client now). NetworkConfig.proxy becomes Void::Net::ProxyConfig, and NetworkTypes.hpp is a thin forwarder to . Co-Authored-By: Claude Opus 4.8 --- include/echoion/api/config/ConfigTypes.hpp | 2 +- .../echoion/api/network/NetworkInterface.hpp | 41 +++-- include/echoion/api/network/NetworkTypes.hpp | 169 +----------------- 3 files changed, 25 insertions(+), 187 deletions(-) diff --git a/include/echoion/api/config/ConfigTypes.hpp b/include/echoion/api/config/ConfigTypes.hpp index 1f9f681..830194b 100644 --- a/include/echoion/api/config/ConfigTypes.hpp +++ b/include/echoion/api/config/ConfigTypes.hpp @@ -57,7 +57,7 @@ namespace Echoion::Api // Network & Proxy Settings struct NetworkConfig { - std::optional proxy; + std::optional proxy; bool rpcEnabled = true; uint16_t rpcPort = 8765; std::string rpcBindAddress = "127.0.0.1"; diff --git a/include/echoion/api/network/NetworkInterface.hpp b/include/echoion/api/network/NetworkInterface.hpp index 2f8f67e..88cd1bf 100644 --- a/include/echoion/api/network/NetworkInterface.hpp +++ b/include/echoion/api/network/NetworkInterface.hpp @@ -1,7 +1,7 @@ #pragma once -#include "NetworkTypes.hpp" #include "Types.hpp" +#include #include #include #include @@ -10,7 +10,8 @@ namespace Echoion::Api { - // Network client interface + // Network client interface. Speaks Void::Net types directly — there is no + // echoion-side HTTP/proxy mirror. class INetworkClient { public: @@ -19,38 +20,36 @@ namespace Echoion::Api // Initialize with optional proxy virtual Result initialize( - const std::optional& proxy = std::nullopt) = 0; + const std::optional& proxy = + std::nullopt) = 0; virtual void shutdown() = 0; // Synchronous requests - [[nodiscard]] virtual Result + [[nodiscard]] virtual Result get(std::string_view url, - const std::vector& headers = {}) = 0; - [[nodiscard]] virtual Result + const std::vector& headers = {}) = 0; + [[nodiscard]] virtual Result post(std::string_view url, std::string_view body, - const std::vector& headers = {}) = 0; - [[nodiscard]] virtual Result - request(const HttpRequest& req) = 0; + const std::vector& headers = {}) = 0; + [[nodiscard]] virtual Result + request(const Void::Net::Request& req) = 0; // Asynchronous requests - [[nodiscard]] virtual std::future> + [[nodiscard]] virtual std::future> getAsync(std::string_view url, - const std::vector& headers = {}) = 0; - [[nodiscard]] virtual std::future> + const std::vector& headers = {}) = 0; + [[nodiscard]] virtual std::future> postAsync(std::string_view url, std::string_view body, - const std::vector& headers = {}) = 0; - [[nodiscard]] virtual std::future> - requestAsync(const HttpRequest& req) = 0; + const std::vector& headers = {}) = 0; + [[nodiscard]] virtual std::future> + requestAsync(const Void::Net::Request& req) = 0; // Proxy configuration - virtual void setProxy(const std::optional& proxy) = 0; - [[nodiscard]] virtual std::optional + virtual void + setProxy(const std::optional& proxy) = 0; + [[nodiscard]] virtual std::optional getProxy() const = 0; virtual void clearProxy() = 0; - - // Retry configuration - virtual void setRetryConfig(const RetryConfig& config) = 0; - [[nodiscard]] virtual RetryConfig getRetryConfig() const = 0; }; } // namespace Echoion::Api diff --git a/include/echoion/api/network/NetworkTypes.hpp b/include/echoion/api/network/NetworkTypes.hpp index 1336a69..84c13bc 100644 --- a/include/echoion/api/network/NetworkTypes.hpp +++ b/include/echoion/api/network/NetworkTypes.hpp @@ -1,167 +1,6 @@ #pragma once -#include "Types.hpp" -#include -#include -#include -#include -#include -#include - -namespace Echoion::Api -{ - - enum class HttpMethod : uint8_t { - GET = 0, - POST, - PUT, - DELETE, - PATCH, - HEAD, - OPTIONS - }; - - enum class ProxyType : uint8_t { HTTP = 0, SOCKS5 }; - - struct ProxyConfig { - ProxyType type = ProxyType::HTTP; - std::string host; - uint16_t port; - std::optional username; - std::optional password; - std::optional timeout; - - [[nodiscard]] bool isValid() const noexcept - { - return !host.empty() && port > 0; - } - - [[nodiscard]] bool requiresAuth() const noexcept - { - return username.has_value() && password.has_value(); - } - - [[nodiscard]] bool isSocks5() const noexcept - { - return type == ProxyType::SOCKS5; - } - - [[nodiscard]] bool - operator==(const ProxyConfig& other) const = default; - [[nodiscard]] bool - operator!=(const ProxyConfig& other) const = default; - }; - - struct HttpHeader { - std::string name; - std::string value; - }; - - struct HttpRequest { - std::string url; - HttpMethod method = HttpMethod::GET; - std::vector headers; - std::optional> body; - std::optional proxy; - std::chrono::milliseconds timeout = 30000ms; - bool followRedirects = true; - uint32_t maxRedirects = 10; - }; - - struct HttpResponse { - int32_t statusCode; - // Using vector to support multiple headers with same name (e.g., - // Set-Cookie) - std::vector> headers; - std::string body; - std::chrono::milliseconds responseTime; - std::optional contentType; - bool fromCache = false; - - [[nodiscard]] bool isSuccess() const noexcept - { - return statusCode >= 200 && statusCode < 300; - } - - [[nodiscard]] bool isRedirect() const noexcept - { - return statusCode >= 300 && statusCode < 400; - } - - [[nodiscard]] bool isError() const noexcept - { - return statusCode >= 400 || statusCode == 0; - } - - [[nodiscard]] std::string bodyAsString() const - { - return std::string(body.begin(), body.end()); - } - - // Helper to get first header value by name (case-insensitive) - [[nodiscard]] std::optional - getHeader(std::string_view name) const - { - for (const auto& [key, value] : headers) { - if (key.size() == name.size()) { - bool match = true; - for (size_t i = 0; i < key.size(); ++i) { - if (std::tolower( - static_cast(key[i])) != - std::tolower( - static_cast(name[i]))) { - match = false; - break; - } - } - if (match) { - return value; - } - } - } - return std::nullopt; - } - - // Helper to get all header values by name (case-insensitive) - - // useful for Set-Cookie - [[nodiscard]] std::vector - getHeaders(std::string_view name) const - { - std::vector result; - for (const auto& [key, value] : headers) { - if (key.size() == name.size()) { - bool match = true; - for (size_t i = 0; i < key.size(); ++i) { - if (std::tolower( - static_cast(key[i])) != - std::tolower( - static_cast(name[i]))) { - match = false; - break; - } - } - if (match) { - result.push_back(value); - } - } - } - return result; - } - }; - - struct RateLimitInfo { - uint32_t limit; - uint32_t remaining; - std::optional resetTime; - }; - - struct RetryConfig { - uint32_t maxRetries = 3; - std::chrono::milliseconds initialDelay = 1000ms; - std::chrono::milliseconds maxDelay = 30000ms; - float backoffMultiplier = 2.0f; - std::vector retryableStatusCodes = {408, 429, 500, - 502, 503, 504}; - }; - -} // namespace Echoion::Api +// echoion no longer mirrors HTTP/proxy types — they are Void::Net's. This +// header forwards to Void::Net so existing includes keep resolving +// Void::Net::Request / Response / Header / Method / ProxyConfig. +#include