Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ configuration file can be a JSON file with the following format:
"127.0.0.1:12000"
],
"upstream": "127.0.0.1:12001",
"inverse": false,
"rate": "10M",
"burst": "64KiB",
"per_client": false,
Expand Down Expand Up @@ -49,6 +50,7 @@ name: my-beloved-app
addrs:
- 127.0.0.1:12000
upstream: 127.0.0.1:12001
inverse: false
rate: 10M
burst: 64KiB
per_client: false
Expand Down
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type configuration struct {
Name string `yaml:"name" flag:"name,,instance name"`
Addrs StringSlice `yaml:"addrs" flag:"addrs,127.0.0.1:12000,bind addresses"`
Upstream string `yaml:"upstream" flag:"upstream,,upstream address"`
Inverse bool `yaml:"inverse" flag:"inverse,,instead of limiting incoming traffic from the upstream's perspective, limit outgoing traffic"`
Rate HumanBytes `yaml:"rate" flag:"rate,,incoming traffic rate limit"`
Burst HumanBytes `yaml:"burst" flag:"burst,,allowed traffic burst"`
PerClient bool `yaml:"per_client" flag:"per-client,,apply rate limit per client"`
Expand Down
9 changes: 7 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,13 @@ func handleClient(c *configuration, conn net.Conn, limiter *rate.Limiter) {
}
}
wg.Add(2)
go forward(conn, uconn, true)
go forward(uconn, conn, false)
if !c.Inverse {
go forward(conn, uconn, true)
go forward(uconn, conn, false)
} else {
go forward(conn, uconn, false)
go forward(uconn, conn, true)
}
wg.Wait()
}

Expand Down