Architecture & Internals
Detailed walkthrough of main.c supervision, vsi_transport.c L4 sockets, http1_codec.c streaming, and WorkerManager.c.
Source Module Layout
| Path | Responsibility |
|---|---|
| src/main.c | CLI 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 / Limit | Value | Defined In |
|---|---|---|
| HTTP1_HEADER_BUFFER_SIZE | 16384 bytes (16 KB) | http1_x/http1_codec.h |
| HTTP1_READ_BUFFER_SIZE / STREAM | 65536 bytes (64 KB) | http1_x/http1_codec.h |
| TUNNEL_BUFFER_SIZE | 65536 bytes (64 KB) | services/forwardProxy/forwardProxy.c |
| MAX_HEADERS_COUNT | 32 headers | http1_x/parser_http_1_0.h |
| MAX_URI_LEN | 1024 bytes | http1_x/parser_http_1_0.h |
| VSI_MAX_RP_MAPPINGS | 16 mappings | CoreEngine/config/vsi_config.h |