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)