A high-performance TCP proxy server built with Erlang/OTP that forwards traffic from clients to configurable upstream hosts.
tuningfork is a lightweight TCP proxy that accepts incoming connections and forwards all traffic to a specified upstream server. It's designed for scenarios where you need to route traffic through an intermediary server.
- Protocol Agnostic: Forwards raw TCP traffic without protocol-specific processing
- Configurable Upstream: Set upstream host via environment variable
- High Concurrency: Built on Erlang/OTP for excellent concurrent connection handling
- Connection Management: Automatic cleanup of client and server connections
- Timeout Handling: 60-second timeout for inactive connections
TUNINGFORK_UPSTREAM_HOST_ADDR: The upstream host to proxy traffic to (default:google.com)
- Listen Port: 443 (configured in
tuningfork_app.erl:16) - Upstream Port: 443 (hardcoded in
proxy_protocol.erl:41)
- Erlang/OTP 27+
- Rebar3
$ rebar3 compile$ rebar3 shell$ rebar3 as prod release$ _build/prod/rel/tuningfork/bin/tuningfork foregroundBuild and run using the provided Containerfile:
$ podman build -t tuningfork .
$ podman run -p 9000:443 -e TUNINGFORK_UPSTREAM_HOST_ADDR=example.com tuningforkUse socat to setup port forwarding:
$ sudo socat TCP-LISTEN:443,fork TCP:localhost:9000Test the proxy:
$ curl --resolve 'example.com:443:127.0.0.1' https://www.example.com# Proxy traffic to example.com
$ TUNINGFORK_UPSTREAM_HOST_ADDR=example.com rebar3 shell# Connect to the proxy (assuming it's running locally)
$ curl --resolve 'example.com:443:127.0.0.1' https://www.example.comtuningfork uses the Ranch library for connection handling and implements a gen_statem behavior for connection state management:
- Ranch TCP Listener: Accepts incoming connections on port 443
- Proxy Protocol Module: Handles bidirectional data forwarding
- State Management: Maintains client and server socket connections
- Connection Lifecycle: Automatic cleanup on connection close or timeout
Apache-2.0