From 19031ebdfdfb30f37b94a9d7ae323d869ecc6ea3 Mon Sep 17 00:00:00 2001 From: Owen Date: Thu, 16 Oct 2025 13:40:01 -0700 Subject: [PATCH] Move to gen the port in the right place --- README.md | 2 +- main.go | 32 ++++++++++++++++---------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 2dc9f64..11a5ec0 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Gerbil will create the peers defined in the config on the WireGuard interface. T ### Report Bandwidth -Bytes transmitted in and out of each peer are collected every 10 seconds, and incremental usage is reported via the "reportBandwidthTo" endpoint. This can be used to track data usage of each peer on the remote server. +Bytes transmitted in and out of each peer are collected every 10 seconds, and incremental usage is reported via the api endpoint. This can be used to track data usage of each peer on the remote server. ### Handle client relaying diff --git a/main.go b/main.go index bfc3db5..7a99c4d 100644 --- a/main.go +++ b/main.go @@ -165,22 +165,6 @@ func main() { if reachableAt == "" { flag.StringVar(&reachableAt, "reachableAt", "", "Endpoint of the http server to tell remote config about") - - // try to parse as http://host:port and set the listenAddr to the :port from this reachableAt. - if reachableAt != "" && listenAddr == "" { - if strings.HasPrefix(reachableAt, "http://") || strings.HasPrefix(reachableAt, "https://") { - parts := strings.Split(reachableAt, ":") - if len(parts) == 3 { - port := parts[2] - if strings.Contains(port, "/") { - port = strings.Split(port, "/")[0] - } - listenAddr = ":" + port - } - } - } else if listenAddr == "" { - listenAddr = ":3003" - } } if logLevel == "" { @@ -233,6 +217,22 @@ func main() { logger.Init() logger.GetLogger().SetLevel(parseLogLevel(logLevel)) + // try to parse as http://host:port and set the listenAddr to the :port from this reachableAt. + if reachableAt != "" && listenAddr == "" { + if strings.HasPrefix(reachableAt, "http://") || strings.HasPrefix(reachableAt, "https://") { + parts := strings.Split(reachableAt, ":") + if len(parts) == 3 { + port := parts[2] + if strings.Contains(port, "/") { + port = strings.Split(port, "/")[0] + } + listenAddr = ":" + port + } + } + } else if listenAddr == "" { + listenAddr = ":3003" + } + mtuInt, err = strconv.Atoi(mtu) if err != nil { logger.Fatal("Failed to parse MTU: %v", err)