From 2b84b2ba13e6d3c448015c0e97860d8948e36929 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 21 May 2019 10:22:58 -0700 Subject: [PATCH 1/2] chore: fix linter nits and tests that don't compile --- core/commands/dht.go | 16 ++++++++-------- core/commands/swarm.go | 19 ++++++++++--------- core/node/libp2p/addrs.go | 2 +- namesys/resolve/pathresolver_test.go | 12 ++++++------ plugin/plugins/gen_main.sh | 2 +- 5 files changed, 26 insertions(+), 25 deletions(-) diff --git a/core/commands/dht.go b/core/commands/dht.go index a1c447f8edc..4788f7cadf1 100644 --- a/core/commands/dht.go +++ b/core/commands/dht.go @@ -494,15 +494,15 @@ Different key types can specify other 'best' rules. pfm := pfuncMap{ notif.Value: func(obj *notif.QueryEvent, out io.Writer, verbose bool) error { if verbose { - fmt.Fprintf(out, "got value: '%s'\n", obj.Extra) - } else { - res, err := base64.StdEncoding.DecodeString(obj.Extra) - if err != nil { - return err - } - out.Write(res) + _, err := fmt.Fprintf(out, "got value: '%s'\n", obj.Extra) + return err } - return nil + res, err := base64.StdEncoding.DecodeString(obj.Extra) + if err != nil { + return err + } + _, err = out.Write(res) + return err }, } diff --git a/core/commands/swarm.go b/core/commands/swarm.go index d444e1c4bb5..56857104601 100644 --- a/core/commands/swarm.go +++ b/core/commands/swarm.go @@ -22,9 +22,10 @@ import ( peer "github.com/libp2p/go-libp2p-peer" pstore "github.com/libp2p/go-libp2p-peerstore" swarm "github.com/libp2p/go-libp2p-swarm" + mafilter "github.com/libp2p/go-maddr-filter" ma "github.com/multiformats/go-multiaddr" madns "github.com/multiformats/go-multiaddr-dns" - mafilter "github.com/whyrusleeping/multiaddr-filter" + mamask "github.com/whyrusleeping/multiaddr-filter" ) const ( @@ -599,8 +600,8 @@ Filters default to those specified under the "Swarm.AddrFilters" config key. } var output []string - for _, f := range swrm.Filters.Filters() { - s, err := mafilter.ConvertIPNet(f) + for _, f := range swrm.Filters.FiltersForAction(mafilter.ActionDeny) { + s, err := mamask.ConvertIPNet(&f) if err != nil { return err } @@ -657,12 +658,12 @@ add your filters to the ipfs config file. } for _, arg := range req.Arguments { - mask, err := mafilter.NewMask(arg) + mask, err := mamask.NewMask(arg) if err != nil { return err } - swrm.Filters.AddDialFilter(mask) + swrm.Filters.AddFilter(*mask, mafilter.ActionDeny) } added, err := filtersAdd(r, cfg, req.Arguments) @@ -716,9 +717,9 @@ remove your filters from the ipfs config file. } if req.Arguments[0] == "all" || req.Arguments[0] == "*" { - fs := swrm.Filters.Filters() + fs := swrm.Filters.FiltersForAction(mafilter.ActionDeny) for _, f := range fs { - swrm.Filters.Remove(f) + swrm.Filters.RemoveLiteral(f) } removed, err := filtersRemoveAll(r, cfg) @@ -730,12 +731,12 @@ remove your filters from the ipfs config file. } for _, arg := range req.Arguments { - mask, err := mafilter.NewMask(arg) + mask, err := mamask.NewMask(arg) if err != nil { return err } - swrm.Filters.Remove(mask) + swrm.Filters.RemoveLiteral(*mask) } removed, err := filtersRemove(r, cfg, req.Arguments) diff --git a/core/node/libp2p/addrs.go b/core/node/libp2p/addrs.go index 7bdd0f7a5fc..d20417b70c5 100644 --- a/core/node/libp2p/addrs.go +++ b/core/node/libp2p/addrs.go @@ -39,7 +39,7 @@ func makeAddrsFactory(announce []string, noAnnounce []string) (p2pbhost.AddrsFac for _, addr := range noAnnounce { f, err := mamask.NewMask(addr) if err == nil { - filters.AddDialFilter(f) + filters.AddFilter(*f, mafilter.ActionDeny) continue } maddr, err := ma.NewMultiaddr(addr) diff --git a/namesys/resolve/pathresolver_test.go b/namesys/resolve/pathresolver_test.go index fe578b5d3f8..3d9c04fa2f1 100644 --- a/namesys/resolve/pathresolver_test.go +++ b/namesys/resolve/pathresolver_test.go @@ -16,17 +16,17 @@ func TestResolveNoComponents(t *testing.T) { } _, err = resolve.Resolve(n.Context(), n.Namesys, n.Resolver, path.Path("/ipns/")) - if err != path.ErrNoComponents { - t.Fatal("Should error with no components (/ipns/).", err) + if err.Error() != "invalid path \"/ipns/\": ipns path missing IPNS ID" { + t.Error("Should error with no components (/ipns/).", err) } _, err = resolve.Resolve(n.Context(), n.Namesys, n.Resolver, path.Path("/ipfs/")) - if err != path.ErrNoComponents { - t.Fatal("Should error with no components (/ipfs/).", err) + if err.Error() != "invalid path \"/ipfs/\": not enough path components" { + t.Error("Should error with no components (/ipfs/).", err) } _, err = resolve.Resolve(n.Context(), n.Namesys, n.Resolver, path.Path("/../..")) - if err != path.ErrBadPath { - t.Fatal("Should error with invalid path.", err) + if err.Error() != "invalid path \"/../..\": unknown namespace \"..\"" { + t.Error("Should error with invalid path.", err) } } diff --git a/plugin/plugins/gen_main.sh b/plugin/plugins/gen_main.sh index b149502f993..a80160b0322 100755 --- a/plugin/plugins/gen_main.sh +++ b/plugin/plugins/gen_main.sh @@ -14,7 +14,7 @@ import ( $shortpkg "$pkg" ) -var Plugins = $shortpkg.Plugins +var Plugins = $shortpkg.Plugins //nolint func main() { panic("this is a plugin, build it as a plugin, this is here as for go#20312") From c39ad0b8f91cada74fbdf7ccaa0dad4bbe6bdf9f Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 21 May 2019 10:18:20 -0700 Subject: [PATCH 2/2] ci: really enable golangci-lint --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 17e734b8039..b0ea0f0b1a1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -120,5 +120,6 @@ workflows: test: jobs: - gobuild + - golint - gotest - sharness