From 0881f7f297b893f05fec6b49a413ab0cc810cfc3 Mon Sep 17 00:00:00 2001 From: web3-bot Date: Thu, 25 Aug 2022 12:03:40 +0000 Subject: [PATCH 1/4] bump go.mod to Go 1.18 and run go fix --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 8cd2d22..552b418 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/multiformats/go-multiaddr -go 1.17 +go 1.18 require ( github.com/ipfs/go-cid v0.0.7 From 21be45fb008acf649b146d173aaf1738c63c9b8a Mon Sep 17 00:00:00 2001 From: web3-bot Date: Thu, 25 Aug 2022 12:03:43 +0000 Subject: [PATCH 2/4] stop using the deprecated io/ioutil package --- doc.go | 41 ++++++++++++++++++++--------------------- filter.go | 5 +++-- interface.go | 7 +++---- net/net.go | 16 ++++++++-------- net/net_test.go | 3 +-- 5 files changed, 35 insertions(+), 37 deletions(-) diff --git a/doc.go b/doc.go index d8c37b2..b80f3ab 100644 --- a/doc.go +++ b/doc.go @@ -7,30 +7,29 @@ Learn more at https://github.com/multiformats/multiaddr Basic Use: - import ( - "bytes" - "strings" - ma "github.com/multiformats/go-multiaddr" - ) + import ( + "bytes" + "strings" + ma "github.com/multiformats/go-multiaddr" + ) - // construct from a string (err signals parse failure) - m1, err := ma.NewMultiaddr("/ip4/127.0.0.1/udp/1234") + // construct from a string (err signals parse failure) + m1, err := ma.NewMultiaddr("/ip4/127.0.0.1/udp/1234") - // construct from bytes (err signals parse failure) - m2, err := ma.NewMultiaddrBytes(m1.Bytes()) + // construct from bytes (err signals parse failure) + m2, err := ma.NewMultiaddrBytes(m1.Bytes()) - // true - strings.Equal(m1.String(), "/ip4/127.0.0.1/udp/1234") - strings.Equal(m1.String(), m2.String()) - bytes.Equal(m1.Bytes(), m2.Bytes()) - m1.Equal(m2) - m2.Equal(m1) - - // tunneling (en/decap) - printer, _ := ma.NewMultiaddr("/ip4/192.168.0.13/tcp/80") - proxy, _ := ma.NewMultiaddr("/ip4/10.20.30.40/tcp/443") - printerOverProxy := proxy.Encapsulate(printer) - proxyAgain := printerOverProxy.Decapsulate(printer) + // true + strings.Equal(m1.String(), "/ip4/127.0.0.1/udp/1234") + strings.Equal(m1.String(), m2.String()) + bytes.Equal(m1.Bytes(), m2.Bytes()) + m1.Equal(m2) + m2.Equal(m1) + // tunneling (en/decap) + printer, _ := ma.NewMultiaddr("/ip4/192.168.0.13/tcp/80") + proxy, _ := ma.NewMultiaddr("/ip4/10.20.30.40/tcp/443") + printerOverProxy := proxy.Encapsulate(printer) + proxyAgain := printerOverProxy.Decapsulate(printer) */ package multiaddr diff --git a/filter.go b/filter.go index cc13aee..ba915da 100644 --- a/filter.go +++ b/filter.go @@ -85,8 +85,9 @@ func (fs *Filters) RemoveLiteral(ipnet net.IPNet) (removed bool) { // default is returned. // // TODO: currently, the last filter to match wins always, but it shouldn't be that way. -// Instead, the highest-specific last filter should win; that way more specific filters -// override more general ones. +// +// Instead, the highest-specific last filter should win; that way more specific filters +// override more general ones. func (fs *Filters) AddrBlocked(a Multiaddr) (deny bool) { var ( netip net.IP diff --git a/interface.go b/interface.go index 82cc764..0c2198b 100644 --- a/interface.go +++ b/interface.go @@ -12,11 +12,10 @@ Learn more here: https://github.com/multiformats/multiaddr Multiaddrs have both a binary and string representation. - import ma "github.com/multiformats/go-multiaddr" - - addr, err := ma.NewMultiaddr("/ip4/1.2.3.4/tcp/80") - // err non-nil when parsing failed. + import ma "github.com/multiformats/go-multiaddr" + addr, err := ma.NewMultiaddr("/ip4/1.2.3.4/tcp/80") + // err non-nil when parsing failed. */ type Multiaddr interface { json.Marshaler diff --git a/net/net.go b/net/net.go index 16f1bbc..10fcff7 100644 --- a/net/net.go +++ b/net/net.go @@ -81,11 +81,11 @@ func wrap(nconn net.Conn, laddr, raddr ma.Multiaddr) Conn { // This function does it's best to avoid "hiding" methods exposed by the wrapped // type. Guarantees: // -// * If the wrapped connection exposes the "half-open" closer methods -// (CloseWrite, CloseRead), these will be available on the wrapped connection -// via type assertions. -// * If the wrapped connection is a UnixConn, IPConn, TCPConn, or UDPConn, all -// methods on these wrapped connections will be available via type assertions. +// - If the wrapped connection exposes the "half-open" closer methods +// (CloseWrite, CloseRead), these will be available on the wrapped connection +// via type assertions. +// - If the wrapped connection is a UnixConn, IPConn, TCPConn, or UDPConn, all +// methods on these wrapped connections will be available via type assertions. func WrapNetConn(nconn net.Conn) (Conn, error) { if nconn == nil { return nil, fmt.Errorf("failed to convert nconn.LocalAddr: nil") @@ -224,9 +224,9 @@ func (nla *netListenerAdapter) Accept() (net.Conn, error) { // NetListener turns this Listener into a net.Listener. // -// * Connections returned from Accept implement multiaddr/net Conn. -// * Calling WrapNetListener on the net.Listener returned by this function will -// return the original (underlying) multiaddr/net Listener. +// - Connections returned from Accept implement multiaddr/net Conn. +// - Calling WrapNetListener on the net.Listener returned by this function will +// return the original (underlying) multiaddr/net Listener. func NetListener(l Listener) net.Listener { return &netListenerAdapter{l} } diff --git a/net/net_test.go b/net/net_test.go index a2c13e2..3e84010 100644 --- a/net/net_test.go +++ b/net/net_test.go @@ -3,7 +3,6 @@ package manet import ( "bytes" "fmt" - "io/ioutil" "net" "os" "path/filepath" @@ -80,7 +79,7 @@ func TestDial(t *testing.T) { } func TestUnixSockets(t *testing.T) { - dir, err := ioutil.TempDir(os.TempDir(), "manettest") + dir, err := os.MkdirTemp(os.TempDir(), "manettest") if err != nil { t.Fatal(err) } From c450ae92fac7245dd94c4a5eb2a6af8d63cdde01 Mon Sep 17 00:00:00 2001 From: web3-bot Date: Thu, 25 Aug 2022 12:03:43 +0000 Subject: [PATCH 3/4] update .github/workflows/go-test.yml --- .github/workflows/go-test.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml index b86241a..8a1697b 100644 --- a/.github/workflows/go-test.yml +++ b/.github/workflows/go-test.yml @@ -10,16 +10,16 @@ jobs: fail-fast: false matrix: os: [ "ubuntu", "windows", "macos" ] - go: [ "1.17.x", "1.18.x" ] + go: [ "1.18.x", "1.19.x" ] env: COVERAGES: "" runs-on: ${{ format('{0}-latest', matrix.os) }} name: ${{ matrix.os }} (go ${{ matrix.go }}) steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: recursive - - uses: actions/setup-go@v2 + - uses: actions/setup-go@v3 with: go-version: ${{ matrix.go }} - name: Go information @@ -43,7 +43,7 @@ jobs: # Use -coverpkg=./..., so that we include cross-package coverage. # If package ./A imports ./B, and ./A's tests also cover ./B, # this means ./B's coverage will be significantly higher than 0%. - run: go test -v -coverprofile=module-coverage.txt -coverpkg=./... ./... + run: go test -v -shuffle=on -coverprofile=module-coverage.txt -coverpkg=./... ./... - name: Run tests (32 bit) if: ${{ matrix.os != 'macos' }} # can't run 32 bit tests on OSX. uses: protocol/multiple-go-modules@v1.2 @@ -52,7 +52,7 @@ jobs: with: run: | export "PATH=${{ env.PATH_386 }}:$PATH" - go test -v ./... + go test -v -shuffle=on ./... - name: Run tests with race detector if: ${{ matrix.os == 'ubuntu' }} # speed things up. Windows and OSX VMs are slow uses: protocol/multiple-go-modules@v1.2 @@ -62,7 +62,7 @@ jobs: shell: bash run: echo "COVERAGES=$(find . -type f -name 'module-coverage.txt' | tr -s '\n' ',' | sed 's/,$//')" >> $GITHUB_ENV - name: Upload coverage to Codecov - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 + uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 with: files: '${{ env.COVERAGES }}' env_vars: OS=${{ matrix.os }}, GO=${{ matrix.go }} From ea9f32ccb74c4d103be58c5d67dd5931f4973aa6 Mon Sep 17 00:00:00 2001 From: web3-bot Date: Thu, 25 Aug 2022 12:03:43 +0000 Subject: [PATCH 4/4] update .github/workflows/go-check.yml --- .github/workflows/go-check.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/go-check.yml b/.github/workflows/go-check.yml index 25e1afd..251f7fa 100644 --- a/.github/workflows/go-check.yml +++ b/.github/workflows/go-check.yml @@ -11,12 +11,12 @@ jobs: env: RUNGOGENERATE: false steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: recursive - - uses: actions/setup-go@v2 + - uses: actions/setup-go@v3 with: - go-version: "1.18.x" + go-version: "1.19.x" - name: Run repo-specific setup uses: ./.github/actions/go-check-setup if: hashFiles('./.github/actions/go-check-setup') != '' @@ -27,7 +27,7 @@ jobs: echo "RUNGOGENERATE=true" >> $GITHUB_ENV fi - name: Install staticcheck - run: go install honnef.co/go/tools/cmd/staticcheck@d7e217c1ff411395475b2971c0824e1e7cc1af98 # 2022.1 (v0.3.0) + run: go install honnef.co/go/tools/cmd/staticcheck@376210a89477dedbe6fdc4484b233998650d7b3c # 2022.1.3 (v0.3.3) - name: Check that go.mod is tidy uses: protocol/multiple-go-modules@v1.2 with: