From 83224154fa64404615ca30dfde04856bccc0469c Mon Sep 17 00:00:00 2001 From: Mohammed Date: Sun, 10 Nov 2024 09:10:55 +0000 Subject: [PATCH 1/9] add gocyclo to make format command --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 132c3e0248..ad610e9285 100644 --- a/Makefile +++ b/Makefile @@ -212,6 +212,7 @@ tidy: ## Tidies and vendors dependencies. format: tidy ## Formats the code. Must have goimports and goimports-reviser installed (use make install-linters). ${OPTS} goimports -w -local ${PROJECT_BASE} ./pkg ./cmd ./internal find . -type f -name '*.go' -not -path "./.git/*" -not -path "./vendor/*" -exec goimports-reviser -project-name ${PROJECT_BASE} {} \; + gocyclo ./pkg ./cmd ./internal format-windows: tidy ## Formats the code. Must have goimports and goimports-reviser installed (use make install-linters). powershell 'Get-ChildItem -Directory | where Name -NotMatch vendor | % { Get-ChildItem $$_ -Recurse -Include *.go } | % {goimports -w -local ${PROJECT_BASE} $$_ }' From 79462b791d39e9b084a89cad5816c0c02649bf2d Mon Sep 17 00:00:00 2001 From: Mohammed Date: Sun, 10 Nov 2024 09:25:39 +0000 Subject: [PATCH 2/9] add gocyclo to make check and lint --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index ad610e9285..50e3067927 100644 --- a/Makefile +++ b/Makefile @@ -182,6 +182,7 @@ lint: ## Run linters. Use make install-linters first ${OPTS} golangci-lint run -c .golangci.yml ./cmd/... ${OPTS} golangci-lint run -c .golangci.yml ./pkg/... ${OPTS} golangci-lint run -c .golangci.yml ./... + gocyclo ./pkg ./cmd ./internal lint-windows: ## Run linters. Use make install-linters-windows first powershell 'golangci-lint --version' From 0fb5058735de44307a3177a1e0bf73e72bf6f7bd Mon Sep 17 00:00:00 2001 From: Mohammed Date: Sun, 10 Nov 2024 09:28:00 +0000 Subject: [PATCH 3/9] add gocyclo to make check and lint windows --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 50e3067927..5e344518ac 100644 --- a/Makefile +++ b/Makefile @@ -187,6 +187,7 @@ lint: ## Run linters. Use make install-linters first lint-windows: ## Run linters. Use make install-linters-windows first powershell 'golangci-lint --version' powershell 'golangci-lint run -c .golangci.yml ./...' + powershell 'gocyclo ./pkg ./cmd ./internal' test: ## Run tests -go clean -testcache &>/dev/null From 1ec95a1aef1fbe39752c52b90fa01a3fd7dd8c6f Mon Sep 17 00:00:00 2001 From: Mohammed Date: Sun, 10 Nov 2024 09:28:16 +0000 Subject: [PATCH 4/9] add gocyclo to github action workflow --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6db0ed46e2..c55223f8d4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,6 +11,7 @@ jobs: - name: Install Requirements run: | curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.61.0 + go install github.com/fzipp/gocyclo/cmd/gocyclo@latest make dep chmod +x ./ci_scripts/create-ip-aliases.sh ./ci_scripts/create-ip-aliases.sh @@ -30,6 +31,7 @@ jobs: - name: Install Requirements run: | curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.61.0 + go install github.com/fzipp/gocyclo/cmd/gocyclo@latest make dep chmod +x ./ci_scripts/create-ip-aliases.sh ./ci_scripts/create-ip-aliases.sh @@ -49,6 +51,7 @@ jobs: - name: Install Requirements run: | choco install make + go install github.com/fzipp/gocyclo/cmd/gocyclo@latest go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0 make dep - name: Testing From 69b71203586acaacfd183c39109384da1cfe42d4 Mon Sep 17 00:00:00 2001 From: Mohammed Date: Sun, 10 Nov 2024 09:33:01 +0000 Subject: [PATCH 5/9] add -over flag to gocyclo --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 5e344518ac..133f9aead0 100644 --- a/Makefile +++ b/Makefile @@ -182,12 +182,12 @@ lint: ## Run linters. Use make install-linters first ${OPTS} golangci-lint run -c .golangci.yml ./cmd/... ${OPTS} golangci-lint run -c .golangci.yml ./pkg/... ${OPTS} golangci-lint run -c .golangci.yml ./... - gocyclo ./pkg ./cmd ./internal + gocyclo -over 14 . lint-windows: ## Run linters. Use make install-linters-windows first powershell 'golangci-lint --version' powershell 'golangci-lint run -c .golangci.yml ./...' - powershell 'gocyclo ./pkg ./cmd ./internal' + powershell 'gocyclo -over 14 .' test: ## Run tests -go clean -testcache &>/dev/null @@ -214,7 +214,7 @@ tidy: ## Tidies and vendors dependencies. format: tidy ## Formats the code. Must have goimports and goimports-reviser installed (use make install-linters). ${OPTS} goimports -w -local ${PROJECT_BASE} ./pkg ./cmd ./internal find . -type f -name '*.go' -not -path "./.git/*" -not -path "./vendor/*" -exec goimports-reviser -project-name ${PROJECT_BASE} {} \; - gocyclo ./pkg ./cmd ./internal + gocyclo -over 14 . format-windows: tidy ## Formats the code. Must have goimports and goimports-reviser installed (use make install-linters). powershell 'Get-ChildItem -Directory | where Name -NotMatch vendor | % { Get-ChildItem $$_ -Recurse -Include *.go } | % {goimports -w -local ${PROJECT_BASE} $$_ }' From 1dd414b0859765c663d68a57d16281ac51d41a56 Mon Sep 17 00:00:00 2001 From: Mohammed Date: Sun, 10 Nov 2024 09:48:37 +0000 Subject: [PATCH 6/9] ignore gocyclo issue, temporary --- cmd/skywire-cli/commands/log/st.go | 3 +++ cmd/skywire-cli/commands/rewards/ui.go | 3 +++ cmd/skywire-cli/commands/visor/top.go | 9 +++++++++ internal/vpn/client.go | 3 +++ internal/vpn/subnet_ip_incrementer.go | 3 +++ pkg/router/router.go | 3 +++ pkg/visor/cmd.go | 4 +++- pkg/visor/hypervisor.go | 4 +++- pkg/visor/init.go | 9 +++++++++ pkg/visor/visorconfig/config.go | 3 +++ 10 files changed, 42 insertions(+), 2 deletions(-) diff --git a/cmd/skywire-cli/commands/log/st.go b/cmd/skywire-cli/commands/log/st.go index b75775f683..2fb7dfd82d 100644 --- a/cmd/skywire-cli/commands/log/st.go +++ b/cmd/skywire-cli/commands/log/st.go @@ -43,6 +43,9 @@ var stCmd = &cobra.Command{ }, } +// TODO: fix gocyclo error. +// +//gocyclo:ignore func makeTree() { utFileInfo, utFileInfoErr := os.Stat("/tmp/ut.json") utData, utDataErr := script.File("/tmp/ut.json").String() diff --git a/cmd/skywire-cli/commands/rewards/ui.go b/cmd/skywire-cli/commands/rewards/ui.go index 91ebefbda8..e716322fe2 100644 --- a/cmd/skywire-cli/commands/rewards/ui.go +++ b/cmd/skywire-cli/commands/rewards/ui.go @@ -129,6 +129,9 @@ var htmlRewardPageTemplate = ` var htmlPageTemplateData htmlTemplateData var tmpl *htmpl.Template +// TODO: fix gocyclo error. +// +//gocyclo:ignore func server() { log := logging.MustGetLogger("dmsghttp") diff --git a/cmd/skywire-cli/commands/visor/top.go b/cmd/skywire-cli/commands/visor/top.go index 61ff582d78..dbb021eff1 100644 --- a/cmd/skywire-cli/commands/visor/top.go +++ b/cmd/skywire-cli/commands/visor/top.go @@ -91,6 +91,9 @@ var ( //go:embed "description.txt" var description string +// TODO: fix gocyclo error. +// +//gocyclo:ignore func parseArgs() error { cds := conf.ConfigDir.QueryFolders(configdir.All) cpaths := make([]string, len(cds)) @@ -226,6 +229,9 @@ func setDefaultTermuiColors(c gotop.Config) { ui.Theme.Block.Border = ui.NewStyle(ui.Color(c.Colorscheme.BorderLine), ui.Color(c.Colorscheme.Bg)) } +// TODO: fix gocyclo error. +// +//gocyclo:ignore func eventLoop(c gotop.Config, grid *layout.MyGrid) { drawTicker := time.NewTicker(c.UpdateInterval).C @@ -408,6 +414,9 @@ func eventLoop(c gotop.Config, grid *layout.MyGrid) { } } +// TODO: fix gocyclo error. +// +//gocyclo:ignore func run() int { ling, err := lingo.New("en_US", ".", gotop.Dicts) if err != nil { diff --git a/internal/vpn/client.go b/internal/vpn/client.go index b250f96b7c..b3acddf7e3 100644 --- a/internal/vpn/client.go +++ b/internal/vpn/client.go @@ -342,6 +342,9 @@ func (c *Client) setupTUN(tunIP, tunGateway net.IP) error { return c.SetupTUN(c.tun.Name(), tunIP.String()+TUNNetmaskCIDR, tunGateway.String(), TUNMTU) } +// TODO: fix gocyclo error. +// +//gocyclo:ignore func (c *Client) serveConn(conn net.Conn) error { tunIP, tunGateway, err := c.shakeHands(conn) if err != nil { diff --git a/internal/vpn/subnet_ip_incrementer.go b/internal/vpn/subnet_ip_incrementer.go index f686a3ee13..a940bb0f68 100644 --- a/internal/vpn/subnet_ip_incrementer.go +++ b/internal/vpn/subnet_ip_incrementer.go @@ -29,6 +29,9 @@ func newSubnetIPIncrementer(octetLowerBorders, octetBorders [4]uint8, step uint8 } } +// TODO: fix gocyclo error. +// +//gocyclo:ignore func (inc *subnetIPIncrementer) next() (net.IP, error) { inc.mx.Lock() defer inc.mx.Unlock() diff --git a/pkg/router/router.go b/pkg/router/router.go index 80af42e6ab..8c509ff08b 100644 --- a/pkg/router/router.go +++ b/pkg/router/router.go @@ -484,6 +484,9 @@ func (r *router) serveSetup() { } } +// TODO: fix gocyclo error. +// +//gocyclo:ignore func (r *router) saveRouteGroupRules(rules routing.EdgeRules, nsConf noise.Config) (*NoiseRouteGroup, error) { r.logger.Debugf("Saving route group rules with desc: %s", &rules.Desc) diff --git a/pkg/visor/cmd.go b/pkg/visor/cmd.go index 9b626b072b..52458d75c1 100644 --- a/pkg/visor/cmd.go +++ b/pkg/visor/cmd.go @@ -57,8 +57,10 @@ var ( isForceColor bool ) +// TODO: fix gocyclo error. +// +//gocyclo:ignore func init() { - root = visorconfig.IsRoot() RootCmd.Flags().SortFlags = false //the default is not set to fix the aesthetic of the help command diff --git a/pkg/visor/hypervisor.go b/pkg/visor/hypervisor.go index 152026e5e0..0df9842888 100644 --- a/pkg/visor/hypervisor.go +++ b/pkg/visor/hypervisor.go @@ -619,8 +619,10 @@ func (hv *Hypervisor) getAppStats() http.HandlerFunc { }) } -// TODO: simplify // nolint: funlen,gocognit,godox +// TODO: fix gocyclo error. +// +//gocyclo:ignore func (hv *Hypervisor) putApp() http.HandlerFunc { return hv.withCtx(hv.appCtx, func(w http.ResponseWriter, r *http.Request, ctx *httpCtx) { type req struct { diff --git a/pkg/visor/init.go b/pkg/visor/init.go index c793712ade..1713dd97a0 100644 --- a/pkg/visor/init.go +++ b/pkg/visor/init.go @@ -887,6 +887,9 @@ func handlePingConn(log *logging.Logger, remoteConn net.Conn, v *Visor) { } // getRouteSetupHooks aka autotransport +// TODO: fix gocyclo error. +// +//gocyclo:ignore func getRouteSetupHooks(ctx context.Context, v *Visor, log *logging.Logger) []router.RouteSetupHook { retrier := netutil.NewRetrier(log, time.Second, time.Second*20, 3, 1.3) return []router.RouteSetupHook{ @@ -1298,6 +1301,9 @@ func initEnsureVisorIsTransportable(ctx context.Context, v *Visor, log *logging. return nil } +// TODO: fix gocyclo error. +// +//gocyclo:ignore func initEnsureTPDConcurrency(ctx context.Context, v *Visor, log *logging.Logger) error { //nolint:all const tickDuration = 5 * time.Minute ticker := time.NewTicker(tickDuration) @@ -1408,6 +1414,9 @@ func initPublicVisor(_ context.Context, v *Visor, log *logging.Logger) error { / return nil } +// TODO: fix gocyclo error. +// +//gocyclo:ignore func initDmsgpty(ctx context.Context, v *Visor, log *logging.Logger) error { conf := v.conf.Dmsgpty diff --git a/pkg/visor/visorconfig/config.go b/pkg/visor/visorconfig/config.go index b598410362..97782459a9 100644 --- a/pkg/visor/visorconfig/config.go +++ b/pkg/visor/visorconfig/config.go @@ -126,6 +126,9 @@ func MakeBaseConfig(common *Common, testEnv bool, dmsgHTTP bool, services *Servi // The config's 'sk' field will be nil if not specified. // Generated config will be saved to 'confPath'. // This function always returns the latest config version. +// TODO: fix gocyclo error. +// +//gocyclo:ignore func MakeDefaultConfig(log *logging.MasterLogger, sk *cipher.SecKey, usrEnv bool, pkgEnv bool, testEnv bool, dmsgHTTP bool, hypervisor bool, confPath, hypervisorPKs string, services *Services) (*V1, error) { if usrEnv && pkgEnv { log.Fatal("usrEnv and pkgEnv are mutually exclusive") From 220400dcbb9445396eb1fef0d9e4d9e2a5ba4a24 Mon Sep 17 00:00:00 2001 From: Mohammed Date: Sun, 10 Nov 2024 09:51:26 +0000 Subject: [PATCH 7/9] replace test-windows with check-windows that include lint and test --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c55223f8d4..7dca37bd54 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -57,6 +57,6 @@ jobs: - name: Testing run: | set GO111MODULE=on - make test-windows + make check-windows - name: Build run: make build-windows From 9deb0efcef5d619548ad23299e65a438f3dcc6a4 Mon Sep 17 00:00:00 2001 From: Mohammed Date: Sun, 10 Nov 2024 09:59:39 +0000 Subject: [PATCH 8/9] fix windows linting issue --- pkg/util/osutil/privileges_windows.go | 2 +- pkg/visor/visorconfig/values_windows.go | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pkg/util/osutil/privileges_windows.go b/pkg/util/osutil/privileges_windows.go index 32ae6459c3..5c1eb3cd65 100644 --- a/pkg/util/osutil/privileges_windows.go +++ b/pkg/util/osutil/privileges_windows.go @@ -13,6 +13,6 @@ func GainRoot() (int, error) { } // ReleaseRoot releases root privileges, not needed on windows -func ReleaseRoot(oldUID int) error { +func ReleaseRoot(_ int) error { return nil } diff --git a/pkg/visor/visorconfig/values_windows.go b/pkg/visor/visorconfig/values_windows.go index 9b2edaac90..c6ebc72c36 100644 --- a/pkg/visor/visorconfig/values_windows.go +++ b/pkg/visor/visorconfig/values_windows.go @@ -4,7 +4,6 @@ package visorconfig import ( - "io/ioutil" "log" "net" "os" @@ -121,7 +120,7 @@ func getNodeHypervisor() string { return "docker" } // Check for cgroup indicating Docker or container environment - data, err := ioutil.ReadFile("/proc/self/cgroup") + data, err := os.ReadFile("/proc/self/cgroup") if err == nil && strings.Contains(string(data), "docker") { return "docker" } @@ -171,7 +170,7 @@ func IsRoot() bool { log.Fatalf("SID Error: %s", err) return false } - defer windows.FreeSid(sid) + defer windows.FreeSid(sid) //nolint: errcheck token := windows.Token(0) From a4338dc3ed5abbef3c05221a65e0e5e3603c58a7 Mon Sep 17 00:00:00 2001 From: Mohammed Date: Sun, 10 Nov 2024 10:16:10 +0000 Subject: [PATCH 9/9] back to test-windows because of annoying and meaningless errors for goimport on windows checking! --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7dca37bd54..c55223f8d4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -57,6 +57,6 @@ jobs: - name: Testing run: | set GO111MODULE=on - make check-windows + make test-windows - name: Build run: make build-windows