#tcp-udp #proxy-server #proxy #udp #tcp #server-port #networking

app swarm_proxy

A proxy for forwarding a bunch of ports really quickly

1 unstable release

0.1.0 Nov 13, 2023

#19 in #server-port

MIT license

23KB
459 lines

Swarm Proxy

A proxy that forwards a lot of ports really fast and is also pretty quick too

Motivation

I had a server behind a double NAT, and masquerading all the ports would have been a lot of effort. I'm lazy, so I wrote a proxy to work around a solvable problem :)

Usage

Command line

swarm_proxy <config.json> | <target> udp [<udp_port|udp_range>] tcp [<tcp_port|tcp_range>]

Example

Forwards ports 69-79 udp and 80 and 443 to 8443 tcp to 10.7.0.2

swarm_proxy 10.7.0.2 udp 69-79:69-79 tcp 80 443:8443

Design

TCP

Super simple, connection goes in, new connection made and packets are exchanged.

UDP

Not as simple. UDP is stateless, but server needs to know which port to forward to on the way back. When a packet is sent, a new port is bound in the proxy server only for sending back to that one client. Clients are bound for about five minutes, then the port is released. Tokio channels go brrrr.

Speed

Pretty quick, I'm not about to talk trash about my own proxy. I ran a few benchmarks with iperf, the speed in and out of the proxy was negligable. Open a PR if you have better benchmarks, or don't.

Dependencies

~6–12MB
~134K SLoC