diff options
| author | Stefan Boberg <[email protected]> | 2026-03-12 15:03:03 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2026-03-12 15:03:03 +0100 |
| commit | 81bc43aa96f0059cecb28d1bd88338b7d84667f9 (patch) | |
| tree | a3428cb7fddceae0b284d33562af5bf3e64a367e /src/zenserver/proxy/zenproxyserver.h | |
| parent | update fmt 12.0.0 -> 12.1.0 (#828) (diff) | |
| download | zen-81bc43aa96f0059cecb28d1bd88338b7d84667f9.tar.xz zen-81bc43aa96f0059cecb28d1bd88338b7d84667f9.zip | |
Transparent proxy mode (#823)
Adds a **transparent TCP proxy mode** to zenserver (activated via `zenserver proxy`), allowing it to sit between clients and upstream Zen servers to inspect and monitor HTTP/1.x traffic in real time. Primarily useful during development, to be able to observe multi-server/client interactions in one place.
- **Dedicated proxy port** -- Proxy mode defaults to port 8118 with its own data directory to avoid collisions with a normal zenserver instance.
- **TCP proxy core** (`src/zenserver/proxy/`) -- A new transparent TCP proxy that forwards connections to upstream targets, with support for both TCP/IP and Unix socket listeners. Multi-threaded I/O for connection handling. Supports Unix domain sockets for both upstream/downstream.
- **HTTP traffic inspection** -- Parses HTTP/1.x request/response streams inline to extract method, path, status, content length, and WebSocket upgrades without breaking the proxied data.
- **Proxy dashboard** -- A web UI showing live connection stats, per-target request counts, active connections, bytes transferred, and client IP/session ID rollups.
- **Server mode display** -- Dashboard banner now shows the running server mode (Zen Proxy, Zen Compute, etc.).
Supporting changes included in this branch:
- **Wildcard log level matching** -- Log levels can now be set per-category using wildcard patterns (e.g. `proxy.*=debug`).
- **`zen down --all`** -- New flag to shut down all running zenserver instances; also used by the new `xmake kill` task.
- Minor test stability fixes (flaky hash collisions, per-thread RNG seeds).
- Support ZEN_MALLOC environment variable for default allocator selection and switch default to rpmalloc
- Fixed sentry-native build to allow LTO on Windows
Diffstat (limited to 'src/zenserver/proxy/zenproxyserver.h')
| -rw-r--r-- | src/zenserver/proxy/zenproxyserver.h | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/zenserver/proxy/zenproxyserver.h b/src/zenserver/proxy/zenproxyserver.h new file mode 100644 index 000000000..7dad748cf --- /dev/null +++ b/src/zenserver/proxy/zenproxyserver.h @@ -0,0 +1,96 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#pragma once + +#include "zenserver.h" + +#include "proxy/tcpproxy.h" + +#include <memory> +#include <thread> +#include <vector> + +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<ProxyMapping> 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<std::string> 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::unique_ptr<asio::io_context::work> m_ProxyIoWorkGuard; + std::vector<std::thread> m_ProxyIoThreads; + std::vector<std::unique_ptr<TcpProxyService>> m_ProxyServices; + std::unique_ptr<HttpApiService> m_ApiService; + std::unique_ptr<HttpFrontendService> m_FrontendService; + std::unique_ptr<HttpProxyStatsService> m_ProxyStatsService; +}; + +} // namespace zen |