From d0e3f5863afa27d7572f52e96f98c5cc1d047b14 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Wed, 7 May 2025 16:16:35 +0100 Subject: [PATCH] rename initProxy to launchProxy remove double log on error add some explanatory comments. --- cmd/q3rcon-proxy/main.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cmd/q3rcon-proxy/main.go b/cmd/q3rcon-proxy/main.go index cd958c8..6c4fd41 100644 --- a/cmd/q3rcon-proxy/main.go +++ b/cmd/q3rcon-proxy/main.go @@ -13,6 +13,7 @@ import ( "github.com/urfave/cli/v3" ) +// proxyConfig holds the configuration for a single UDP proxy server. type proxyConfig struct { proxyHost string targetHost string @@ -96,13 +97,13 @@ func main() { sessionTimeout: cmd.Int("session-timeout"), } - go initProxy(cfg, errChan) + go launchProxy(cfg, errChan) } - // We don't expect to receive any errors from the channels, but if we do, we log and return early. + // Under normal circumstances, the main goroutine will block here + // until the server is stopped or an error occurs. for err := range errChan { if err != nil { - log.Errorf("Error: %v", err) return err } } @@ -115,7 +116,10 @@ func main() { } } -func initProxy(cfg proxyConfig, errChan chan error) { +// launchProxy initializes the UDP proxy server with the given configuration. +// It listens on the specified proxy host and port, and forwards traffic to the target host and port. +// server.ListenAndServe blocks until the server is stopped or an error occurs. +func launchProxy(cfg proxyConfig, errChan chan error) { proxyPort, targetPort := cfg.portsMapping[0], cfg.portsMapping[1] hostAddr := fmt.Sprintf("%s:%s", cfg.proxyHost, proxyPort)