TCP Proxy Prototype
Learning the layer below by writing the smallest version of it.
- Language
- C++20
- Library
- Boost.Asio
- Buffer
- 8192 B / direction
- Commits
- 2
- Updated
- Mar 2026
- License
- MIT
System
How it fits together.
A simplified view of the moving parts, not a full architecture diagram.
- 01ClientTCP connection
- 02Listener :8000accept loop
- 032 coroutinesclient → backend, backend → client
- 04Backend :8080fixed upstream
Context
Why it exists.
I wanted to understand what actually sits between a client and a backend, so I wrote the smallest proxy I could reason about: accept a connection, open an upstream connection, and move bytes in both directions.
Approach
- 01Accept on port 8000 and forward to 127.0.0.1:8080.
- 02Use Boost.Asio C++20 coroutines: one awaitable per direction, combined with co_await (a && b) so the tunnel ends when either side closes.
- 03Keep an 8192-byte buffer per direction and use async_read_some / async_write.
- 04Build with clang++, C++20, optimization enabled, and link Boost.System.
Inside the repository
What is actually in there.
Coroutine tunnel
Each connection spawns two detached proxy_stream coroutines; the connection closes when either direction finishes.
Explicit buffers
A fixed 8 KiB stack buffer per direction keeps the first implementation easy to inspect.
Small surface
Two source files, three headers, and a Makefile. MIT licensed.
Known gaps
No configuration, CLI arguments, TLS, logging, or tests. Two of the headers are empty placeholders.
Constraints & notes
An early prototype, not a gateway. Routing is hardcoded in main; the root main.cpp is an older duplicate that the Makefile does not build. The next honest steps are configuration, CLI parsing, TLS, and tests.