From 489ecd65fb8f825e349681e61caba32ecf4b8215 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Thu, 28 Mar 2024 23:25:25 +0300 Subject: [PATCH] feat: allow disabling monitor --- cmd/hvpn-node/hvpn-node.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/cmd/hvpn-node/hvpn-node.go b/cmd/hvpn-node/hvpn-node.go index 4f37aa3..c02eeeb 100644 --- a/cmd/hvpn-node/hvpn-node.go +++ b/cmd/hvpn-node/hvpn-node.go @@ -37,6 +37,7 @@ var wgLink *hvpnnode3.WGLink var Country countries.CountryCode var UUID uuid.UUID +var Monitor bool = false var httpPort int var TLS_ENABLED bool @@ -63,7 +64,9 @@ func run(ctx *cli.Context) { wgLink.StartedAT = time.Now().UTC() slog.Info(fmt.Sprintf("Started at %s", wgLink.StartedAT)) slog.Info(fmt.Sprintf("Country set to %s (%s)", Country.Alpha2(), Country.String())) - hvpnnode3.StartMonitor(wgLink, *slog.Default()) + if Monitor { + hvpnnode3.StartMonitor(wgLink, *slog.Default()) + } apiMux := http.NewServeMux() apiMux.HandleFunc("GET /node", hvpnnode3.HandleGetNodeInfo(wgLink)) @@ -111,7 +114,7 @@ func createCliApp() *cli.App { app.Name = os.Args[0] app.HideHelpCommand = true app.Usage = "HVPN node API server" - app.Args = true + app.Args = false author1 := cli.Author{ Name: "Hesham T. Banafa", @@ -135,6 +138,17 @@ func createCliApp() *cli.App { } app.Flags = append(app.Flags, &logLevel) + monitorFlag := cli.BoolFlag{ + Name: "monitor", + Usage: "Enables a periodic logger with count of current active peers", + Value: true, + Action: func(ctx *cli.Context, b bool) error { + Monitor = b + return nil + }, + } + app.Flags = append(app.Flags, &monitorFlag) + privateKeyFileFlag := cli.PathFlag{ Name: "private-key", Usage: "Path to file with private key", @@ -262,6 +276,7 @@ func createCliApp() *cli.App { app.Flags = append(app.Flags, &TLSCertKey) + app.Action = func(ctx *cli.Context) error { err := setup(ctx) if err != nil {