Skip to content
Docs / Architecture & Internals

Architecture & Internals

Detailed walkthrough of main.c supervision, vsi_transport.c L4 sockets, http1_codec.c streaming, and WorkerManager.c.

Source Module Layout

PathResponsibility
src/main.cCLI entry point, banner output, single-service vs. multi-service fork() supervisor, signal forwarding
CoreEngine/config/vsi_config.{h,c}cJSON config loader, CLI override parser, IPv4 & port-conflict validator, mode-to-callback resolver
CoreEngine/transport/vsi_transport.{h,c}Layer 4 TCP socket(), SO_REUSEADDR, bind(), listen(), accept() loop, detached pthread worker dispatch
services/forwardProxy/forwardProxy.{h,c}Forward proxy request transformer, CONNECT select() tunnel, streamed HTTP relay
services/reverseProxy/reverseProxy.{h,c}In-place V2 request transformation, response Host/Location rewriter, 502 handling
http1_x/parser_http_1_0.{h,c}HTTP/1.x request line & header state-machine parser (up to 32 headers)
http1_x/http1_codec.{h,c}16 KB header reader and constant-memory Content-Length / chunked body streamer
http1_x/outboundEngine.{h,c}Upstream TCP IPv4 connector (outbound_connect_tcp) and relay helpers
http1_x/WorkerManager.{h,c}Bounded circular WorkerQueue (MAX_WORKERS = 64) — In Development, not yet wired to transport
utils/vsi_metrics.{h,c} & utils/cJSON.{h,c}Shared mmap atomic counters, HTTP JSON metrics server, vendored cJSON parser

Supervision & Concurrency Model

If active_service_count == 1, vsi_ngine runs the enabled service directly inside the main process. If both Forward Proxy and Reverse Proxy are enabled, run_multi_service_supervisor() forks a dedicated child process for each service while still single-threaded, then starts the metrics server thread in the supervisor and monitors children via waitpid().

Inside each listener, vsi_transport_start() creates a blocking IPv4 TCP socket with SO_REUSEADDR, ignores SIGPIPE so aborted client writes do not terminate the process, and spawns a detached POSIX thread (PTHREAD_CREATE_DETACHED) per accepted client_fd.

HTTP/1.x Codec & Buffer Limits

Constant / LimitValueDefined In
HTTP1_HEADER_BUFFER_SIZE16384 bytes (16 KB)http1_x/http1_codec.h
HTTP1_READ_BUFFER_SIZE / STREAM65536 bytes (64 KB)http1_x/http1_codec.h
TUNNEL_BUFFER_SIZE65536 bytes (64 KB)services/forwardProxy/forwardProxy.c
MAX_HEADERS_COUNT32 headershttp1_x/parser_http_1_0.h
MAX_URI_LEN1024 byteshttp1_x/parser_http_1_0.h
VSI_MAX_RP_MAPPINGS16 mappingsCoreEngine/config/vsi_config.h