Traffic-shaping SOCKS5 proxy
tsproxy provides basic latency, download and upload traffic shaping while only requiring user-level access (no root permissions required). It should work for basic browser testing but for protocol-level work it does not provide a suitable replacement for something like dummynet or netem.
tsproxy is monolithic and all of the functionality is in tsproxy.py. It is written expecting Python 2.7.
$ python tsproxy.py --rtt=<latency> --inkbps=<download bandwidth> --outkbps=<upload bandwidth>
ctrl-C (or send a
SIGINT) to exit
$ python tsproxy.py --rtt=200 --inkbps=1600 --outkbps=768
||Latency in milliseconds (full round trip, half of the latency gets applied to each direction).|
||Download Bandwidth (in 1000 bits/s - Kbps).|
||Upload Bandwidth (in 1000 bits/s - Kbps).|
||Emulated TCP initial congestion window (defaults to 10).|
||SOCKS 5 proxy port (defaults to port 1080). Specifying a port of 0 will use a randomly assigned port.|
||Interface address to listen on (defaults to localhost).|
||Redirect all outbound connections to the specified host (name or IP).|
||Remap outbound ports. Comma-separated list of original:new with * as a wildcard.
||Include connections already destined for localhost/127.0.0.1 in the host and port remapping.|
||Increase verbosity (specify multiple times for more).
The traffic shaping configuration can be changed dynamically at runtime by passing commands in through the console (or stdin). Each command is on a line, terminated with an end-of-line (
flush: Flush queued data out of the pipes. Useful for clearing out any accumulated background data between tests.
set rtt <latency>: Change the connection latency. i.e.
set rtt 200\nwill change to a 200ms RTT.
set inkbps <bandwidth>: Change the download bandwidth. i.e.
set inkbps 5000\nwill change to a 5Mbps download connection.
set outkbps <bandwidth>: Change the upload bandwidth. i.e.
set outkbps 1000\nwill change to a 1Mbps upload connection.
set mapports <port mapping string>: Change the destination port mapping.
reset all: Disable all port mapping and traffic shaping
reset rtt: Set latency to 0
reset inkbps: Disable download traffic shaping
reset outkbps: Disable upload traffic shaping
reset mapports: Disable destination port mapping
All bandwidth and latency changes also carry an implied flush and clear out any pending data.
A Dockerfile is provided to allow Docker development workflow.
Also, an official image on Docker Hub is available from source via an Automated Build to enable use of tsproxy in Docker environments. You can run tsproxy without installing anything (other than Docker) by issuing:
docker run --rm -it -p 1080:1080 webpagetest/tsproxy [options...]
Configuring Chrome to use tsproxy
Add a --proxy-server command-line option.
- DNS lookups on OSX (and FreeBSD) will block each other when it comes to actually resolving. DNS in Python on most platforms is allowed to run concurrently in threads (which tsproxy does) but on OSX and FreeBSD it is not thread-safe and there is a lock around the actual lookups. For most cases this isn't an issue because the latency isn't added on the actual DNS lookup (it is from the browser perspective but it is added outside of the actual lookup). This is also not an issue when desthost is used to override the destination address since dns lookups will be disabled.
- QUIC support. Chrome doesn't currently support QUIC proxies, and further work would be neccessary to correctly handle UDP traffic in tsproxy.