// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "zenserver.h" #include "proxy/tcpproxy.h" #include #include #include #include namespace zen { class HttpApiService; class HttpFrontendService; class HttpProxyStatsService; } // namespace zen namespace cxxopts { class Options; } namespace zen::LuaConfig { struct Options; } namespace zen { struct ZenProxyServerConfig : public ZenServerConfig { static constexpr int kDefaultProxyPort = 8118; std::vector ProxyMappings; }; struct ZenProxyServerConfigurator : public ZenServerConfiguratorBase { ZenProxyServerConfigurator(ZenProxyServerConfig& ServerOptions) : ZenServerConfiguratorBase(ServerOptions) , m_ServerOptions(ServerOptions) { } ~ZenProxyServerConfigurator() = default; private: virtual void AddCliOptions(cxxopts::Options& Options) override; virtual void AddConfigOptions(LuaConfig::Options& Options) override; virtual void ApplyOptions(cxxopts::Options& Options) override; virtual void OnConfigFileParsed(LuaConfig::Options& LuaOptions) override; virtual void ValidateOptions() override; ZenProxyServerConfig& m_ServerOptions; std::vector m_RawProxyMappings; }; class ZenProxyServerMain : public ZenServerMain { public: ZenProxyServerMain(ZenProxyServerConfig& ServerOptions); virtual void DoRun(ZenServerState::ZenServerEntry* Entry) override; ZenProxyServerMain(const ZenProxyServerMain&) = delete; ZenProxyServerMain& operator=(const ZenProxyServerMain&) = delete; typedef ZenProxyServerConfig Config; typedef ZenProxyServerConfigurator Configurator; private: ZenProxyServerConfig& m_ServerOptions; }; class ZenProxyServer : public ZenServerBase { ZenProxyServer& operator=(ZenProxyServer&&) = delete; ZenProxyServer(ZenProxyServer&&) = delete; public: ZenProxyServer(); ~ZenProxyServer(); int Initialize(const ZenProxyServerConfig& ServerConfig, ZenServerState::ZenServerEntry* ServerEntry); void Run(); void Cleanup(); private: asio::io_context m_ProxyIoContext; std::optional> m_ProxyIoWorkGuard; std::vector m_ProxyIoThreads; std::vector> m_ProxyServices; std::unique_ptr m_ApiService; std::unique_ptr m_FrontendService; std::unique_ptr m_ProxyStatsService; }; } // namespace zen