diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 625ceb04..f6b622f5 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -16,13 +16,12 @@ jobs: #with: # go-version: ${{ steps.version.outputs.go_version }} with: - go-version: 1.18.0-rc1 - stable: false + go-version: 1.18.x - name: golangci-lint #uses: golangci/golangci-lint-action@v3 #with: # version: latest run: | - go install github.com/golangci/golangci-lint/cmd/golangci-lint@93a0015 + go install github.com/golangci/golangci-lint/cmd/golangci-lint@ec95236 golangci-lint run ./... diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 38ee84dc..795a8a03 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,8 +14,7 @@ jobs: #with: # go-version: ${{ steps.version.outputs.go_version }} with: - go-version: 1.18.0-rc1 - stable: false + go-version: 1.18.x - name: Check out code into the Go module directory uses: actions/checkout@v3 diff --git a/.golangci.yaml b/.golangci.yaml index 0ab00f01..05cf626a 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -5,6 +5,8 @@ linters: - staticcheck - govet # - gci + - gofmt + - goimports linters-settings: gci: diff --git a/constant/tun.go b/constant/tun.go index 944608c4..10e24861 100644 --- a/constant/tun.go +++ b/constant/tun.go @@ -19,7 +19,7 @@ const ( type TUNStack int // UnmarshalYAML unserialize TUNStack with yaml -func (e *TUNStack) UnmarshalYAML(unmarshal func(interface{}) error) error { +func (e *TUNStack) UnmarshalYAML(unmarshal func(any) error) error { var tp string if err := unmarshal(&tp); err != nil { return err @@ -33,7 +33,7 @@ func (e *TUNStack) UnmarshalYAML(unmarshal func(interface{}) error) error { } // MarshalYAML serialize TUNStack with yaml -func (e TUNStack) MarshalYAML() (interface{}, error) { +func (e TUNStack) MarshalYAML() (any, error) { return e.String(), nil } diff --git a/go.mod b/go.mod index fc271a28..77c9c28f 100644 --- a/go.mod +++ b/go.mod @@ -27,7 +27,7 @@ require ( golang.zx2c4.com/wireguard/windows v0.5.3 google.golang.org/protobuf v1.27.1 gopkg.in/yaml.v2 v2.4.0 - gvisor.dev/gvisor v0.0.0-20220314190221-89a04115dfa4 + gvisor.dev/gvisor v0.0.0-20220315202956-f1399ecf1672 ) require ( diff --git a/go.sum b/go.sum index ff1c8384..cedd9b96 100644 --- a/go.sum +++ b/go.sum @@ -163,5 +163,5 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gvisor.dev/gvisor v0.0.0-20220314190221-89a04115dfa4 h1:7xad6H5GS+ihL8OQGSZjndLmGTPqyXFLxV7viYKLZ30= -gvisor.dev/gvisor v0.0.0-20220314190221-89a04115dfa4/go.mod h1:V4WNP2Uwtx69eOhvLDSQ734EaTJTaBI3P8KgRAlROsg= +gvisor.dev/gvisor v0.0.0-20220315202956-f1399ecf1672 h1:aXIFpjZYl3zv2rQyr4rSit5Uq0k7BVXC8lJaDa4Cg7M= +gvisor.dev/gvisor v0.0.0-20220315202956-f1399ecf1672/go.mod h1:V4WNP2Uwtx69eOhvLDSQ734EaTJTaBI3P8KgRAlROsg= diff --git a/listener/tun/ipstack/commons/boot.go b/listener/tun/ipstack/commons/boot.go deleted file mode 100644 index 3c19f496..00000000 --- a/listener/tun/ipstack/commons/boot.go +++ /dev/null @@ -1,41 +0,0 @@ -//go:build windows -// +build windows - -/* SPDX-License-Identifier: MIT - * - * Copyright (C) 2019-2021 WireGuard LLC. All Rights Reserved. - */ - -package commons - -import ( - "errors" - "log" - "sync" - "time" - - "golang.org/x/sys/windows" - "golang.org/x/sys/windows/svc" -) - -var ( - startedAtBoot bool - startedAtBootOnce sync.Once -) - -func StartedAtBoot() bool { - startedAtBootOnce.Do(func() { - if isService, err := svc.IsWindowsService(); err == nil && !isService { - return - } - if reason, err := svc.DynamicStartReason(); err == nil { - startedAtBoot = (reason&svc.StartReasonAuto) != 0 || (reason&svc.StartReasonDelayedAuto) != 0 - } else if errors.Is(err, windows.ERROR_PROC_NOT_FOUND) { - // TODO: Below this line is Windows 7 compatibility code, which hopefully we can delete at some point. - startedAtBoot = windows.DurationSinceBoot() < time.Minute*10 - } else { - log.Printf("Unable to determine service start reason: %v", err) - } - }) - return startedAtBoot -} diff --git a/listener/tun/ipstack/commons/router_windows.go b/listener/tun/ipstack/commons/router_windows.go index 834ed1ec..51dbcd7c 100644 --- a/listener/tun/ipstack/commons/router_windows.go +++ b/listener/tun/ipstack/commons/router_windows.go @@ -11,6 +11,7 @@ import ( "github.com/Dreamacro/clash/log" "golang.org/x/sys/windows" + "golang.zx2c4.com/wireguard/windows/services" "golang.zx2c4.com/wireguard/windows/tunnel/winipcfg" ) @@ -24,7 +25,7 @@ func GetAutoDetectInterface() (string, error) { } func ConfigInterfaceAddress(dev device.Device, addr netip.Prefix, forceMTU int, autoRoute bool) error { - retryOnFailure := StartedAtBoot() + retryOnFailure := services.StartedAtBoot() tryTimes := 0 var err error startOver: diff --git a/listener/tun/ipstack/system/mars/tcpip/tcpip_amd64.go b/listener/tun/ipstack/system/mars/tcpip/tcpip_amd64.go index d6f48dc0..c7d5dcaa 100644 --- a/listener/tun/ipstack/system/mars/tcpip/tcpip_amd64.go +++ b/listener/tun/ipstack/system/mars/tcpip/tcpip_amd64.go @@ -1,5 +1,4 @@ //go:build !noasm -// +build !noasm package tcpip diff --git a/log/log.go b/log/log.go index 4e5c375b..3a7ea729 100644 --- a/log/log.go +++ b/log/log.go @@ -97,9 +97,3 @@ func newLog(logLevel LogLevel, format string, v ...any) *Event { Payload: fmt.Sprintf(format, v...), } } - -func PrintLog(logLevel LogLevel, format string, v ...interface{}) { - event := newLog(logLevel, format, v...) - logCh <- event - print(event) -} diff --git a/test/go.mod b/test/go.mod index a9407847..7030e49b 100644 --- a/test/go.mod +++ b/test/go.mod @@ -56,5 +56,5 @@ require ( gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect gotest.tools/v3 v3.1.0 // indirect - gvisor.dev/gvisor v0.0.0-20220314190221-89a04115dfa4 // indirect + gvisor.dev/gvisor v0.0.0-20220315202956-f1399ecf1672 // indirect ) diff --git a/test/go.sum b/test/go.sum index 0de9cd0c..ac2a7f95 100644 --- a/test/go.sum +++ b/test/go.sum @@ -1413,8 +1413,8 @@ gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk= gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8= gotest.tools/v3 v3.1.0 h1:rVV8Tcg/8jHUkPUorwjaMTtemIMVXfIPKiOqnhEhakk= gotest.tools/v3 v3.1.0/go.mod h1:fHy7eyTmJFO5bQbUsEGQ1v4m2J3Jz9eWL54TP2/ZuYQ= -gvisor.dev/gvisor v0.0.0-20220314190221-89a04115dfa4 h1:7xad6H5GS+ihL8OQGSZjndLmGTPqyXFLxV7viYKLZ30= -gvisor.dev/gvisor v0.0.0-20220314190221-89a04115dfa4/go.mod h1:V4WNP2Uwtx69eOhvLDSQ734EaTJTaBI3P8KgRAlROsg= +gvisor.dev/gvisor v0.0.0-20220315202956-f1399ecf1672 h1:aXIFpjZYl3zv2rQyr4rSit5Uq0k7BVXC8lJaDa4Cg7M= +gvisor.dev/gvisor v0.0.0-20220315202956-f1399ecf1672/go.mod h1:V4WNP2Uwtx69eOhvLDSQ734EaTJTaBI3P8KgRAlROsg= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=