From 98a258021f0f5a54371d66cca2d74bf4fd5adcb9 Mon Sep 17 00:00:00 2001 From: Nate Maninger Date: Fri, 13 Sep 2024 16:31:21 -0700 Subject: [PATCH 1/6] ci: switch to common workflow --- .github/workflows/main.yml | 12 ++++ .github/workflows/test.yml | 34 ----------- .golangci.yml | 116 ++++++++++++++++++++++++------------- 3 files changed, 87 insertions(+), 75 deletions(-) create mode 100644 .github/workflows/main.yml delete mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..897c7a3 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,12 @@ +name: Lint & Test +on: + pull_request: + push: + branches: + - master + +jobs: + test: + uses: SiaFoundation/workflows/.github/workflows/go-test.yml@master + with: + try-build: false diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index fda91d8..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Test -on: - workflow_dispatch: - pull_request: - push: - branches: - - master - -jobs: - test: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ ubuntu-latest , macos-latest, windows-latest ] - go-version: [ '1.18', '1.19' ] - steps: - - name: Configure git - run: git config --global core.autocrlf false # required on Windows - - name: Checkout - uses: actions/checkout@v3 - - name: Setup Go - uses: actions/setup-go@v3 - with: - go-version: ${{ matrix.go-version }} - - name: Lint - uses: golangci/golangci-lint-action@v3 - - name: Test Windows 1.18 # can't run race detector on windows with go 1.18 or lower due to a bug (https://github.com/golang/go/issues/46099) - if: matrix.os == 'windows-latest' && matrix.go-version == '1.18' - uses: n8maninger/action-golang-test@v1 - - name: Test - if: matrix.os != 'windows-latest' || matrix.go-version != '1.18' - uses: n8maninger/action-golang-test@v1 - with: - args: "-race" diff --git a/.golangci.yml b/.golangci.yml index 0bf93aa..72819f2 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -17,28 +17,8 @@ run: # list of build tags, all linters use it. Default is empty list. build-tags: [] - # which dirs to skip: issues from them won't be reported; - # can use regexp here: generated.*, regexp is applied on full path; - # default value is empty list, but default dirs are skipped independently - # from this option's value (see skip-dirs-use-default). - skip-dirs: - - cover - - # default is true. Enables skipping of directories: - # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ - skip-dirs-use-default: true - - # which files to skip: they will be analyzed, but issues from them - # won't be reported. Default value is empty list, but there is - # no need to include all autogenerated files, we confidently recognize - # autogenerated files. If it's not please let us know. - skip-files: [] - # output configuration options output: - # colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number" - format: colored-line-number - # print lines of code with issue, default is true print-issued-lines: true @@ -50,37 +30,90 @@ linters-settings: ## Enabled linters: govet: # report about shadowed variables - check-shadowing: false disable-all: false - golint: - min-confidence: 1.0 + tagliatelle: + case: + rules: + json: goCamel + yaml: goCamel + gocritic: # Which checks should be enabled; can't be combined with 'disabled-checks'; # See https://go-critic.github.io/overview#checks-overview # To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run` # By default list of stable checks is used. - enabled-checks: - - argOrder # Diagnostic options - - badCond - - caseOrder - - dupArg - - dupBranchBody - - dupCase - - dupSubExpr - - nilValReturn - - offBy1 - - weakCond - - boolExprSimplify # Style options here and below. - - builtinShadow - - emptyFallthrough - - hexLiteral - - underef - - equalFold + enabled-tags: + - diagnostic + - style + disabled-checks: + # diagnostic + - commentedOutCode + - uncheckedInlineErr + + # style + - emptyStringTest + - exitAfterDefer + - ifElseChain + - importShadow + - initClause + - nestingReduce + - octalLiteral + - paramTypeCombine + - ptrToRefParam + - stringsCompare + - tooManyResultsChecker + - typeDefFirst + - typeUnparen + - unlabelStmt + - unnamedResult + - whyNoLint revive: ignore-generated-header: true rules: + - name: blank-imports + disabled: false + - name: bool-literal-in-expr + disabled: false + - name: confusing-naming + disabled: false + - name: confusing-results + disabled: false + - name: constant-logical-expr + disabled: false + - name: context-as-argument + disabled: false + - name: exported + disabled: false + - name: errorf + disabled: false + - name: if-return + disabled: false + - name: indent-error-flow + disabled: true + - name: increment-decrement + disabled: false + - name: modifies-value-receiver + disabled: true + - name: optimize-operands-order + disabled: false + - name: range-val-in-closure + disabled: false + - name: struct-tag + disabled: false + - name: superfluous-else + disabled: false + - name: time-equal + disabled: false + - name: unexported-naming + disabled: false + - name: unexported-return + disabled: false + - name: unnecessary-stmt + disabled: false + - name: unreachable-code + disabled: false - name: package-comments disabled: true @@ -88,6 +121,7 @@ linters: disable-all: true fast: false enable: + - tagliatelle - gocritic - gofmt - revive @@ -113,4 +147,4 @@ issues: # it can be disabled by this option. To list all # excluded by default patterns execute `golangci-lint run --help`. # Default value for this option is true. - exclude-use-default: false \ No newline at end of file + exclude-use-default: false From 21856fd9b1ed7d0eef53c9034ffdda4e70e0f311 Mon Sep 17 00:00:00 2001 From: Nate Maninger Date: Fri, 13 Sep 2024 16:32:27 -0700 Subject: [PATCH 2/6] deps: update dependencies --- go.mod | 6 +++--- go.sum | 14 ++++---------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index b5d8904..4ae2261 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,13 @@ module go.sia.tech/mux -go 1.17 +go 1.23 require ( - golang.org/x/crypto v0.0.0-20220507011949-2cf3adece122 + golang.org/x/crypto v0.27.0 lukechampine.com/frand v1.4.2 ) require ( github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect - golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect + golang.org/x/sys v0.25.0 // indirect ) diff --git a/go.sum b/go.sum index fdc2572..2e0c230 100644 --- a/go.sum +++ b/go.sum @@ -1,15 +1,9 @@ github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da h1:KjTM2ks9d14ZYCvmHS9iAKVt9AyzRSqNU1qabPih5BY= github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da/go.mod h1:eHEWzANqSiWQsof+nXEI9bUVUyV6F53Fp89EuCh2EAA= -golang.org/x/crypto v0.0.0-20220507011949-2cf3adece122 h1:NvGWuYG8dkDHFSKksI1P9faiVJ9rayE6l0+ouWVIDs8= -golang.org/x/crypto v0.0.0-20220507011949-2cf3adece122/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A= +golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= lukechampine.com/frand v1.4.2 h1:RzFIpOvkMXuPMBb9maa4ND4wjBn71E1Jpf8BzJHMaVw= lukechampine.com/frand v1.4.2/go.mod h1:4S/TM2ZgrKejMcKMbeLjISpJMO+/eZ1zu3vYX9dtj3s= From c378ce8f597d790254fc2bc4f8424e2da7de60b1 Mon Sep 17 00:00:00 2001 From: Nate Maninger Date: Fri, 13 Sep 2024 16:31:31 -0700 Subject: [PATCH 3/6] v2: address lint --- v2/handshake.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/v2/handshake.go b/v2/handshake.go index 55c7c31..e552165 100644 --- a/v2/handshake.go +++ b/v2/handshake.go @@ -133,12 +133,12 @@ func initiateHandshake(conn net.Conn, theirKey ed25519.PublicKey, ourSettings co // write pubkey buf := make([]byte, 32+64+connSettingsSize+chachaPoly1305TagSize) - copy(buf[:], xpk[:]) + copy(buf, xpk[:]) if _, err := conn.Write(buf[:32]); err != nil { return nil, connSettings{}, fmt.Errorf("could not write handshake request: %w", err) } // read pubkey, signature, and settings - if _, err := io.ReadFull(conn, buf[:]); err != nil { + if _, err := io.ReadFull(conn, buf); err != nil { return nil, connSettings{}, fmt.Errorf("could not read handshake response: %w", err) } @@ -166,7 +166,7 @@ func initiateHandshake(conn net.Conn, theirKey ed25519.PublicKey, ourSettings co } // encrypt + write our settings - encodeConnSettings(buf[:], ourSettings) + encodeConnSettings(buf, ourSettings) cipher.encryptInPlace(buf[:connSettingsSize+chachaPoly1305TagSize]) if _, err := conn.Write(buf[:connSettingsSize+chachaPoly1305TagSize]); err != nil { return nil, connSettings{}, fmt.Errorf("could not write settings: %w", err) @@ -195,7 +195,7 @@ func acceptHandshake(conn net.Conn, ourKey ed25519.PrivateKey, ourSettings connS // write pubkey, signature, and settings sigHash := blake2b.Sum256(append(rxpk[:], xpk[:]...)) sig := ed25519.Sign(ourKey, sigHash[:]) - copy(buf[:], xpk[:]) + copy(buf, xpk[:]) copy(buf[32:], sig) encodeConnSettings(buf[32+64:], ourSettings) cipher.encryptInPlace(buf[32+64:]) From cb672ff04bfaa5025abae5611d9bec00ccc0e02c Mon Sep 17 00:00:00 2001 From: Nate Maninger Date: Fri, 13 Sep 2024 16:39:34 -0700 Subject: [PATCH 4/6] github: enable dependabot --- .github/dependabot.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..cd88554 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file + +version: 2 +updates: + - package-ecosystem: "gomod" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "weekly" From 471f45cc573160a1e2229f1cce0851502eaf223f Mon Sep 17 00:00:00 2001 From: Nate Maninger Date: Fri, 13 Sep 2024 16:41:32 -0700 Subject: [PATCH 5/6] github: group dependabot --- .github/dependabot.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index cd88554..27b41fa 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -9,3 +9,7 @@ updates: directory: "/" # Location of package manifests schedule: interval: "weekly" + groups: + all-dependencies: + patterns: + - "*" From 5169509d23cc7833c1acda5735ce79989a603f4a Mon Sep 17 00:00:00 2001 From: Nate Maninger Date: Fri, 13 Sep 2024 16:43:32 -0700 Subject: [PATCH 6/6] fix lint --- v1/errors_windows.go | 3 +-- v2/errors_windows.go | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/v1/errors_windows.go b/v1/errors_windows.go index cb581c9..a726d91 100644 --- a/v1/errors_windows.go +++ b/v1/errors_windows.go @@ -9,9 +9,8 @@ import ( // isConnCloseError returns true if the error is from the peer closing the // connection early. func isConnCloseError(err error) bool { - const WSAEPROTOTYPE = syscall.Errno(10041) return errors.Is(err, io.EOF) || - errors.Is(err, WSAEPROTOTYPE) || + errors.Is(err, syscall.Errno(10041)) || // WSAEPROTOTYPE errors.Is(err, syscall.WSAECONNABORTED) || errors.Is(err, syscall.WSAECONNRESET) } diff --git a/v2/errors_windows.go b/v2/errors_windows.go index cb581c9..a726d91 100644 --- a/v2/errors_windows.go +++ b/v2/errors_windows.go @@ -9,9 +9,8 @@ import ( // isConnCloseError returns true if the error is from the peer closing the // connection early. func isConnCloseError(err error) bool { - const WSAEPROTOTYPE = syscall.Errno(10041) return errors.Is(err, io.EOF) || - errors.Is(err, WSAEPROTOTYPE) || + errors.Is(err, syscall.Errno(10041)) || // WSAEPROTOTYPE errors.Is(err, syscall.WSAECONNABORTED) || errors.Is(err, syscall.WSAECONNRESET) }