Protocol Streams
Aegis includes a full protocol streaming engine alongside its HTTP reverse proxy. Streams handle raw TCP and UDP traffic — database connections, game servers, mail relays, SSH tunnels, DNS forwarding, VPN endpoints, or any non-HTTP protocol that needs port-level proxying with access control.
Overview
Streams operate at Layer 4 (transport), forwarding raw bytes between clients and upstreams without HTTP awareness. Each stream binds to a listen address and port, relays traffic to an upstream host and port, and optionally applies TLS termination, access control, bandwidth limits, and health checks.Host header), streams route by listen port — each stream owns a unique port.
Protocols
Stream Configuration
Each stream host supports the following settings:TCP Streaming
TCP streams use bidirectional relay — two goroutines runningio.Copy in parallel, one for each direction. When either direction completes (client closes or upstream closes), both sides are torn down.
Connection Lifecycle
- Client connects to the stream’s listen port
- Source IP checked against whitelist/blacklist CIDRs
- If TLS enabled, TLS handshake with the configured certificate
- Middleware chain runs (proxy protocol injection, connection counting, logging)
- TCP connection opened to upstream host:port
- Bidirectional relay starts (two
io.Copygoroutines) - Connection closed when either side disconnects or idle timeout triggers
- Connection stats recorded (bytes sent/received, duration)
UDP Streaming
UDP streams use a stateful NAT table to track client-to-upstream mappings. Since UDP is connectionless, Aegis maintains per-client state to correctly route response datagrams back to the originating client.NAT Table
Stale NAT entries (no activity within the configured idle timeout) are periodically evicted.
TLS Termination
Streams support TLS termination on the listener side, using certificates from the Aegis certificate store (the same certificates used for HTTP proxy hosts).- Set
ssl_enabled: trueand provide anssl_cert_idreferencing a stored certificate - TLS is only supported on TCP (and the TCP portion of TCP+UDP)
- The upstream connection is plain TCP — TLS is terminated at Aegis
Proxy Protocol
Streams support the PROXY protocol for passing the original client IP to the upstream server.
When enabled, Aegis prepends the PROXY protocol header before relaying data to the upstream, so the upstream can see the real client IP even though the TCP connection originates from Aegis.
Access Control
Each stream has its own whitelist and blacklist CIDR lists, evaluated on every new connection:- If whitelist is non-empty, only IPs matching a whitelist entry are allowed
- If the IP matches a blacklist entry, the connection is rejected
- Rejected connections are logged (if connection logging is enabled)
Bandwidth Limiting
Per-stream upload and download rate limits are enforced in bytes per second:
Set to
0 for unlimited. Rate limiting is applied per-connection via IO wrappers.
Health Checks
When enabled, Aegis periodically verifies that the upstream is reachable:- A TCP dial to
upstream_host:upstream_portis attempted at the configured interval - If the dial succeeds, the stream is marked healthy
- If the dial fails, the stream is marked unhealthy and the error is recorded
- Health status is visible in the admin UI and via the stats API
Connection Logging
Whenlog_connections is enabled, Aegis records each connection:
Runtime Statistics
Each stream exposes real-time counters:Port Validation
Aegis validates stream ports before binding:- Port must be between 1 and 65535
- Port must not conflict with the HTTP proxy (
:80), HTTPS proxy (:443), or admin UI (9443) - Port must not conflict with another stream’s listen port
- Warnings are issued for well-known reserved ports
Admin UI
Streams have their own management page in the Aegis admin dashboard:- Create, edit, enable/disable, and delete streams
- Real-time connection stats and health status
- Connection log viewer
- Protocol, TLS, and access control configuration
- Bandwidth and timeout settings

