Introduce new flag, -max_queries_per_sec

I'm being gouged by bandwidth costs by AWS. Last month's bill was $148,
and all but $9 was about bandwidth.

My bandwidth has been inexplicably climbing since February:

Billing
Month   Total GB % increase

2024/2		  37.119
2024/3		  52.953	42.66%
2024/4		  58.745	10.94%
2024/5		  69.307	17.98%
2024/6		 173.371	150.15%
2024/7		 334.064	92.69%
2024/8		 539.343	61.45%
2024/9		 568.745	5.45%
2024/10	1365.305	140.06%

The new flag will allow me to throttle the AWS bandwidth to ~287 queries
/ second, which, according to my calculations, will max out the free
100 GB bandwidth without dipping into the for-pay bandwidth.
This commit is contained in:
Brian Cunnie
2024-11-03 17:35:46 -08:00
parent 078a69f75e
commit 9c8712578d
4 changed files with 108 additions and 9 deletions

View File

@@ -5,6 +5,7 @@ import (
"errors"
"flag"
"log"
"math"
"net"
"os"
"runtime"
@@ -42,12 +43,13 @@ func main() {
var bindPort = flag.Int("port", 53, "port the DNS server should bind to")
var quiet = flag.Bool("quiet", false, "suppresses logging of each DNS response. Use this to avoid Google Cloud charging you $30/month to retain the logs of your GKE-based sslip.io server")
var public = flag.Bool("public", true, "allows resolution of public IP addresses. If false, only resolves private IPs including localhost (127/8, ::1), link-local (169.254/16, fe80::/10), CG-NAT (100.64/12), private (10/8, 172.16/12, 192.168/16, fc/7). Set to false if you don't want miscreants impersonating you via public IPs. If unsure, set to false")
var maxQueriesPerSec = flag.Int("max_queries_per_sec", math.MaxInt32, "maximum queries per second. This limit, in queries/second, is measured since the server was started. When the limit is reached, the server stops replying until throughput drops below the limit. Use this if AWS is gouging you for bandwidth. 300 qps is close to 100 GB / month")
flag.Parse()
log.Printf("%s version %s starting", os.Args[0], xip.VersionSemantic)
log.Printf("blocklist URL: %s, name servers: %s, bind port: %d, quiet: %t",
*blocklistURL, *nameservers, *bindPort, *quiet)
x, logmessages := xip.NewXip(*blocklistURL, strings.Split(*nameservers, ","), strings.Split(*addresses, ","), strings.Split(*delegates, ","))
x, logmessages := xip.NewXip(*blocklistURL, strings.Split(*nameservers, ","), strings.Split(*addresses, ","), strings.Split(*delegates, ","), *maxQueriesPerSec)
x.Public = *public
for _, logmessage := range logmessages {
log.Println(logmessage)