From 8b4258454395069619e916399fc9a542c746c418 Mon Sep 17 00:00:00 2001 From: Piotr Galar Date: Thu, 12 Jun 2025 18:32:50 +0200 Subject: [PATCH 1/3] ci: set up golangci lint in boxo --- .golangci.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .golangci.yml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 000000000..65e3cc2e5 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,27 @@ +version: "2" + +run: + timeout: 10m + +issues: + max-issues-per-linter: 0 + max-same-issues: 0 + +linters: + enable: + - ineffassign + - misspell + - unconvert + - unused + - usestdlibvars + + disable: + - errcheck + +formatters: + enable: + - gci + - gofumpt + +severity: + default: warning From 6345496491aacc99a9a8efbf97dce16a9556b811 Mon Sep 17 00:00:00 2001 From: galargh Date: Thu, 12 Jun 2025 18:47:27 +0200 Subject: [PATCH 2/3] chore: fix issues raised by golangci-lint --- bitswap/network/bsnet/ipfs_impl.go | 1 - bitswap/network/http_multiaddr_test.go | 1 - bitswap/network/httpnet/cooldown.go | 1 - bitswap/network/httpnet/error_tracker_test.go | 2 +- bitswap/network/httpnet/httpnet.go | 17 +++++------ bitswap/network/httpnet/httpnet_test.go | 15 ++++------ bitswap/network/httpnet/msg_sender.go | 12 ++++---- bitswap/network/httpnet/pinger.go | 4 +-- bitswap/network/interface.go | 2 -- bitswap/network/router.go | 1 + examples/bitswap-transfer/main.go | 30 ++++++++----------- examples/bitswap-transfer/main_test.go | 1 - fetcher/testutil/testutil.go | 1 - gateway/assets/test/main.go | 1 - gateway/backend_blocks.go | 1 - gateway/gateway_test.go | 3 -- gateway/handler_codec.go | 1 - ipld/merkledag/merkledag.go | 1 - ipld/unixfs/io/directory.go | 3 +- mfs/dir.go | 3 +- provider/dagprovider_test.go | 1 - provider/internal/queue/queue.go | 2 +- provider/reprovider.go | 1 - tar/extractor_test.go | 2 +- 24 files changed, 40 insertions(+), 67 deletions(-) diff --git a/bitswap/network/bsnet/ipfs_impl.go b/bitswap/network/bsnet/ipfs_impl.go index 3c3a6a1f5..68ab31e31 100644 --- a/bitswap/network/bsnet/ipfs_impl.go +++ b/bitswap/network/bsnet/ipfs_impl.go @@ -11,7 +11,6 @@ import ( bsmsg "github.com/ipfs/boxo/bitswap/message" iface "github.com/ipfs/boxo/bitswap/network" "github.com/ipfs/boxo/bitswap/network/bsnet/internal" - logging "github.com/ipfs/go-log/v2" "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/network" diff --git a/bitswap/network/http_multiaddr_test.go b/bitswap/network/http_multiaddr_test.go index 5807e6389..dd3cefc88 100644 --- a/bitswap/network/http_multiaddr_test.go +++ b/bitswap/network/http_multiaddr_test.go @@ -53,7 +53,6 @@ func TestExtractHTTPAddress(t *testing.T) { expectErr: false, }, { - name: "Valid HTTPS multiaddress with DNS", maStr: "/dns4/example.com/tcp/443/https", want: &url.URL{ diff --git a/bitswap/network/httpnet/cooldown.go b/bitswap/network/httpnet/cooldown.go index 37d66990f..1e9751146 100644 --- a/bitswap/network/httpnet/cooldown.go +++ b/bitswap/network/httpnet/cooldown.go @@ -80,7 +80,6 @@ func (ct *cooldownTracker) fillSenderURLs(urls []network.ParsedURL) []*senderURL surls := make([]*senderURL, len(urls)) ct.urlsLock.RLock() { - for i, u := range urls { var cooldown time.Time dl, ok := ct.urls[u.URL.Host] diff --git a/bitswap/network/httpnet/error_tracker_test.go b/bitswap/network/httpnet/error_tracker_test.go index fd7bec11a..ab1ae56d0 100644 --- a/bitswap/network/httpnet/error_tracker_test.go +++ b/bitswap/network/httpnet/error_tracker_test.go @@ -77,7 +77,7 @@ func TestErrorTracker_ConcurrentAccess(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - for j := 0; j < int(threshold)/numRoutines; j++ { + for j := 0; j < threshold/numRoutines; j++ { et.logErrors(p, 1, threshold) } }() diff --git a/bitswap/network/httpnet/httpnet.go b/bitswap/network/httpnet/httpnet.go index 939e4e4a5..8ef6dd81b 100644 --- a/bitswap/network/httpnet/httpnet.go +++ b/bitswap/network/httpnet/httpnet.go @@ -30,16 +30,16 @@ import ( var log = logging.Logger("httpnet") -var ErrNoHTTPAddresses = errors.New("AddrInfo does not contain any valid HTTP addresses") -var ErrNoSuccess = errors.New("none of the peer HTTP endpoints responded successfully to request") -var ErrNotConnected = errors.New("no HTTP connection has been setup to this peer") +var ( + ErrNoHTTPAddresses = errors.New("AddrInfo does not contain any valid HTTP addresses") + ErrNoSuccess = errors.New("none of the peer HTTP endpoints responded successfully to request") + ErrNotConnected = errors.New("no HTTP connection has been setup to this peer") +) var _ network.BitSwapNetwork = (*Network)(nil) -var ( - // DefaultUserAgent is sent as a header in all requests. - DefaultUserAgent = defaultUserAgent() // Usually will result in a "boxo@commitID" -) +// DefaultUserAgent is sent as a header in all requests. +var DefaultUserAgent = defaultUserAgent() // Usually will result in a "boxo@commitID" // Defaults for the configurable options. const ( @@ -348,7 +348,6 @@ func (ht *Network) Stop() { // Ping triggers a ping to the given peer and returns the latency. func (ht *Network) Ping(ctx context.Context, p peer.ID) ping.Result { return ht.pinger.ping(ctx, p) - } // Latency returns the EWMA latency for the given peer. @@ -514,7 +513,7 @@ func (ht *Network) connectToURL(ctx context.Context, p peer.ID, u network.Parsed // probe success. // FIXME: Storacha returns 410 for our probe. - if resp.StatusCode == 200 || resp.StatusCode == 204 || resp.StatusCode == 410 { + if resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusNoContent || resp.StatusCode == http.StatusGone { return nil } diff --git a/bitswap/network/httpnet/httpnet_test.go b/bitswap/network/httpnet/httpnet_test.go index 8ed067814..847beba82 100644 --- a/bitswap/network/httpnet/httpnet_test.go +++ b/bitswap/network/httpnet/httpnet_test.go @@ -27,9 +27,11 @@ import ( manet "github.com/multiformats/go-multiaddr/net" ) -var errorCid = cid.MustParse("bafkreiachshsblgr5kv3mzbgfgmvuhllwe2f6fasm6mykzwsi4l7odq464") // "errorcid" -var slowCid = cid.MustParse("bafkreidhph5i4jevaun4eqjxolqgn3rfpoknj35ocyos3on57iriwpaujm") // "slowcid" -var backoffCid = cid.MustParse("bafkreid6g5qrufgqj46djic7ntjnppaj5bg4urppjoyywrxwegvltrmqbu") // "backoff" +var ( + errorCid = cid.MustParse("bafkreiachshsblgr5kv3mzbgfgmvuhllwe2f6fasm6mykzwsi4l7odq464") // "errorcid" + slowCid = cid.MustParse("bafkreidhph5i4jevaun4eqjxolqgn3rfpoknj35ocyos3on57iriwpaujm") // "slowcid" + backoffCid = cid.MustParse("bafkreid6g5qrufgqj46djic7ntjnppaj5bg4urppjoyywrxwegvltrmqbu") // "backoff" +) var _ network.Receiver = (*mockRecv)(nil) @@ -92,7 +94,6 @@ func (recv *mockRecv) waitDisconnected(seconds int) error { } func (recv *mockRecv) ReceiveError(err error) { - } func (recv *mockRecv) PeerConnected(p peer.ID) { @@ -113,7 +114,6 @@ func mockReceiver(t *testing.T) *mockRecv { waitConnectedCh: make(chan struct{}, 1), waitDisconnectedCh: make(chan struct{}, 1), } - } func mockNet(t *testing.T) mocknet.Mocknet { @@ -167,7 +167,6 @@ func makeMessage(wantlist []cid.Cid, wantType pb.Message_Wantlist_WantType, send wantType, sendDontHave, ) - } return msg } @@ -246,7 +245,7 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, r *http.Request) { } rw.WriteHeader(http.StatusOK) - if r.Method == "HEAD" { + if r.Method == http.MethodHead { return } @@ -390,7 +389,6 @@ func TestBestURL(t *testing.T) { if err == nil { t.Fatal("expected error since only urls failed too many times") } - } func TestSendMessage(t *testing.T) { @@ -485,7 +483,6 @@ func TestSendMessageWithPartialResponse(t *testing.T) { t.Error("block should not have been received") } } - } func TestSendMessageSendHavesAndDontHaves(t *testing.T) { diff --git a/bitswap/network/httpnet/msg_sender.go b/bitswap/network/httpnet/msg_sender.go index 0b44b93f6..70d14a976 100644 --- a/bitswap/network/httpnet/msg_sender.go +++ b/bitswap/network/httpnet/msg_sender.go @@ -32,7 +32,7 @@ const ( // request can take. DefaultSendTimeout = 5 * time.Second // SendErrorBackoff specifies how long to wait between retries to the - // same endpoint after failure. It is overriden by Retry-After + // same endpoint after failure. It is overridden by Retry-After // headers and must be at least 50ms. DefaultSendErrorBackoff = time.Second ) @@ -176,7 +176,7 @@ func (err senderError) Error() string { return err.Err.Error() } -// tryURL attemps to make a request to the given URL using the given entry. +// tryURL attempts to make a request to the given URL using the given entry. // Blocks, Haves etc. are recorded in the given response. cancellations are // processed. tryURL returns an error so that it can be decided what to do next: // i.e. retry, or move to next item in wantlist, or abort completely. @@ -329,7 +329,7 @@ func (sender *httpMsgSender) tryURL(ctx context.Context, u *senderURL, entry bsm } log.Debugf("%s %q -> %d (%d bytes)", req.Method, req.URL, statusCode, len(body)) - if req.Method == "HEAD" { + if req.Method == http.MethodHead { return nil, nil } // GET @@ -354,7 +354,7 @@ func (sender *httpMsgSender) tryURL(ctx context.Context, u *senderURL, entry bsm // Retry-After. They are used to signal that a block cannot // be fetched too, not only fatal server issues, which poses a // difficult overlap. Current approach treats these errors as - // non fatal if they don't happen repeteadly: + // non fatal if they don't happen repeatedly: // - By default we disconnect on server errors: MaxRetries = 1. // - First try errors. We add default backoff if non specified. // - Retry same CID. If it fails again, count that as server @@ -364,7 +364,7 @@ func (sender *httpMsgSender) tryURL(ctx context.Context, u *senderURL, entry bsm // In practice, our wantlists should be 1/3 elements. It // doesn't make sense to tolerate 5 server errors for 3 - // requests as we will repeteadly hit broken servers that way. + // requests as we will repeatedly hit broken servers that way. // It is always better if endpoints keep these errors for // server issues, and simply return 404 when they cannot find // the content but everything else is fine. @@ -402,7 +402,7 @@ func (sender *httpMsgSender) tryURL(ctx context.Context, u *senderURL, entry bsm } // SendMsg performs an http request for the wanted cids per the msg's -// Wantlist. It reads the response and records it in a reponse BitswapMessage +// Wantlist. It reads the response and records it in a response BitswapMessage // which is forwarded to the receivers (in a separate goroutine). func (sender *httpMsgSender) SendMsg(ctx context.Context, msg bsmsg.BitSwapMessage) error { // SendMsg gets called from MessageQueue and returning an error diff --git a/bitswap/network/httpnet/pinger.go b/bitswap/network/httpnet/pinger.go index 3932fcbee..ec6b1bf39 100644 --- a/bitswap/network/httpnet/pinger.go +++ b/bitswap/network/httpnet/pinger.go @@ -85,7 +85,7 @@ func (pngr *pinger) ping(ctx context.Context, p peer.ID) ping.Result { } result.RTT = result.RTT / time.Duration(len(urls)-lenErrors) - //log.Debugf("ping latency %s %s", p, result.RTT) + // log.Debugf("ping latency %s %s", p, result.RTT) pngr.recordLatency(p, result.RTT) return result } @@ -144,7 +144,6 @@ func (pngr *pinger) startPinging(p peer.ID) { } } }(ctx, p) - } func (pngr *pinger) stopPinging(p peer.ID) { @@ -160,7 +159,6 @@ func (pngr *pinger) stopPinging(p peer.ID) { pngr.latenciesLock.Lock() delete(pngr.latencies, p) pngr.latenciesLock.Unlock() - } func (pngr *pinger) isPinging(p peer.ID) bool { diff --git a/bitswap/network/interface.go b/bitswap/network/interface.go index 89ec990f5..d46e89de4 100644 --- a/bitswap/network/interface.go +++ b/bitswap/network/interface.go @@ -5,9 +5,7 @@ import ( "time" bsmsg "github.com/ipfs/boxo/bitswap/message" - cid "github.com/ipfs/go-cid" - "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/routing" "github.com/libp2p/go-libp2p/p2p/protocol/ping" diff --git a/bitswap/network/router.go b/bitswap/network/router.go index 529e86749..7d59783e8 100644 --- a/bitswap/network/router.go +++ b/bitswap/network/router.go @@ -202,6 +202,7 @@ func (rt *router) Protect(p peer.ID, tag string) { } rt.Bitswap.Protect(p, tag) } + func (rt *router) Unprotect(p peer.ID, tag string) bool { pi := rt.Peerstore.PeerInfo(p) htaddrs, _ := SplitHTTPAddrs(pi) diff --git a/examples/bitswap-transfer/main.go b/examples/bitswap-transfer/main.go index b155e971f..f3e80d5e0 100644 --- a/examples/bitswap-transfer/main.go +++ b/examples/bitswap-transfer/main.go @@ -12,31 +12,27 @@ import ( "strconv" "strings" - "github.com/ipfs/go-datastore" - dsync "github.com/ipfs/go-datastore/sync" - - "github.com/libp2p/go-libp2p" - "github.com/libp2p/go-libp2p/core/crypto" - "github.com/libp2p/go-libp2p/core/host" - "github.com/libp2p/go-libp2p/core/peer" - - "github.com/ipfs/go-cid" - "github.com/multiformats/go-multiaddr" - "github.com/multiformats/go-multicodec" - + bsclient "github.com/ipfs/boxo/bitswap/client" + bsnet "github.com/ipfs/boxo/bitswap/network/bsnet" + bsserver "github.com/ipfs/boxo/bitswap/server" "github.com/ipfs/boxo/blockservice" blockstore "github.com/ipfs/boxo/blockstore" chunker "github.com/ipfs/boxo/chunker" offline "github.com/ipfs/boxo/exchange/offline" + "github.com/ipfs/boxo/files" "github.com/ipfs/boxo/ipld/merkledag" unixfile "github.com/ipfs/boxo/ipld/unixfs/file" "github.com/ipfs/boxo/ipld/unixfs/importer/balanced" uih "github.com/ipfs/boxo/ipld/unixfs/importer/helpers" - - bsclient "github.com/ipfs/boxo/bitswap/client" - bsnet "github.com/ipfs/boxo/bitswap/network/bsnet" - bsserver "github.com/ipfs/boxo/bitswap/server" - "github.com/ipfs/boxo/files" + "github.com/ipfs/go-cid" + "github.com/ipfs/go-datastore" + dsync "github.com/ipfs/go-datastore/sync" + "github.com/libp2p/go-libp2p" + "github.com/libp2p/go-libp2p/core/crypto" + "github.com/libp2p/go-libp2p/core/host" + "github.com/libp2p/go-libp2p/core/peer" + "github.com/multiformats/go-multiaddr" + "github.com/multiformats/go-multicodec" ) const exampleBinaryName = "bitswap-transfer" diff --git a/examples/bitswap-transfer/main_test.go b/examples/bitswap-transfer/main_test.go index 39586fed2..dd09c6dc7 100644 --- a/examples/bitswap-transfer/main_test.go +++ b/examples/bitswap-transfer/main_test.go @@ -6,7 +6,6 @@ import ( "testing" "github.com/ipfs/go-cid" - "github.com/libp2p/go-libp2p/core/peer" ) diff --git a/fetcher/testutil/testutil.go b/fetcher/testutil/testutil.go index ecb7ac102..078022b50 100644 --- a/fetcher/testutil/testutil.go +++ b/fetcher/testutil/testutil.go @@ -8,7 +8,6 @@ import ( blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-cid" "github.com/ipld/go-ipld-prime" - // used to make sure we have dagcbor encoding _ "github.com/ipld/go-ipld-prime/codec/dagcbor" cidlink "github.com/ipld/go-ipld-prime/linking/cid" diff --git a/gateway/assets/test/main.go b/gateway/assets/test/main.go index d27cfa50a..ad3fdd8b1 100644 --- a/gateway/assets/test/main.go +++ b/gateway/assets/test/main.go @@ -10,7 +10,6 @@ import ( "github.com/ipfs/boxo/gateway/assets" "github.com/ipfs/go-cid" - // Ensure basic codecs are registered. _ "github.com/ipld/go-ipld-prime/codec/cbor" _ "github.com/ipld/go-ipld-prime/codec/dagcbor" diff --git a/gateway/backend_blocks.go b/gateway/backend_blocks.go index 468d67e94..656d158e5 100644 --- a/gateway/backend_blocks.go +++ b/gateway/backend_blocks.go @@ -29,7 +29,6 @@ import ( "github.com/ipld/go-car/v2/storage" dagpb "github.com/ipld/go-codec-dagpb" "github.com/ipld/go-ipld-prime" - // Ensure basic codecs are registered. _ "github.com/ipld/go-ipld-prime/codec/cbor" _ "github.com/ipld/go-ipld-prime/codec/dagcbor" diff --git a/gateway/gateway_test.go b/gateway/gateway_test.go index fa94d6a33..41833ceca 100644 --- a/gateway/gateway_test.go +++ b/gateway/gateway_test.go @@ -854,7 +854,6 @@ func TestRedirects(t *testing.T) { // Check Redirect target contains all query parameters redirectURL := res.Header.Get("Location") require.Equal(t, expectedTargetURL, redirectURL) - } do(http.MethodGet) @@ -899,7 +898,6 @@ func TestRedirects(t *testing.T) { // Check Redirect target contains all query parameters redirectURL := res.Header.Get("Location") require.Equal(t, expectedTargetURL, redirectURL) - } do(http.MethodGet) @@ -944,7 +942,6 @@ func TestRedirects(t *testing.T) { // Check Redirect target contains all query parameters redirectURL := res.Header.Get("Location") require.Equal(t, expectedTargetURL, redirectURL) - } do(http.MethodGet) diff --git a/gateway/handler_codec.go b/gateway/handler_codec.go index 28b6db397..4332471c8 100644 --- a/gateway/handler_codec.go +++ b/gateway/handler_codec.go @@ -14,7 +14,6 @@ import ( "github.com/ipfs/boxo/gateway/assets" "github.com/ipfs/boxo/path" "github.com/ipfs/go-cid" - // Ensure basic codecs are registered. _ "github.com/ipld/go-ipld-prime/codec/cbor" _ "github.com/ipld/go-ipld-prime/codec/dagcbor" diff --git a/ipld/merkledag/merkledag.go b/ipld/merkledag/merkledag.go index 1c638d139..d500dc7c7 100644 --- a/ipld/merkledag/merkledag.go +++ b/ipld/merkledag/merkledag.go @@ -13,7 +13,6 @@ import ( format "github.com/ipfs/go-ipld-format" legacy "github.com/ipfs/go-ipld-legacy" dagpb "github.com/ipld/go-codec-dagpb" - // blank import is used to register the IPLD raw codec _ "github.com/ipld/go-ipld-prime/codec/raw" basicnode "github.com/ipld/go-ipld-prime/node/basic" diff --git a/ipld/unixfs/io/directory.go b/ipld/unixfs/io/directory.go index d8b589256..e17cf3ade 100644 --- a/ipld/unixfs/io/directory.go +++ b/ipld/unixfs/io/directory.go @@ -690,7 +690,7 @@ func (d *HAMTDirectory) GetCidBuilder() cid.Builder { // switchToBasic returns a BasicDirectory implementation of this directory. func (d *HAMTDirectory) switchToBasic(ctx context.Context, opts ...DirectoryOption) (*BasicDirectory, error) { - // needsoSwichToBasicDir checks d.maxLinks is appropiate. No check is + // needsoSwichToBasicDir checks d.maxLinks is appropriate. No check is // performed here. basicDir, err := NewBasicDirectory(d.dserv, opts...) if err != nil { @@ -779,7 +779,6 @@ func (d *HAMTDirectory) needsToSwitchToBasicDir(ctx context.Context, name string } return canSwitchSize && canSwitchMaxLinks, nil - } // Evaluate directory size and a future sizeChange and check if it will be below diff --git a/mfs/dir.go b/mfs/dir.go index 55d7474a2..11f2c5f70 100644 --- a/mfs/dir.go +++ b/mfs/dir.go @@ -74,7 +74,6 @@ func NewEmptyDirectory(ctx context.Context, name string, parent parent, dserv ip uio.WithStat(opts.Mode, opts.ModTime), uio.WithCidBuilder(opts.CidBuilder), ) - if err != nil { return nil, err } @@ -335,7 +334,7 @@ func (d *Directory) MkdirWithOpts(name string, opts MkdirOpts) (*Directory, erro } } - // hector: no idea why this option is overriden, but it must be to + // hector: no idea why this option is overridden, but it must be to // keep backwards compatibility. CidBuilder from the options is // manually set in `Mkdir` (ops.go) though. opts.CidBuilder = d.GetCidBuilder() diff --git a/provider/dagprovider_test.go b/provider/dagprovider_test.go index cd8b680c9..1e4a48990 100644 --- a/provider/dagprovider_test.go +++ b/provider/dagprovider_test.go @@ -102,7 +102,6 @@ func TestNewDAGProviderCtxCancel(t *testing.T) { time.Sleep(time.Second) } } - }() time.Sleep(500 * time.Millisecond) diff --git a/provider/internal/queue/queue.go b/provider/internal/queue/queue.go index fbda5d7c4..8dcccb178 100644 --- a/provider/internal/queue/queue.go +++ b/provider/internal/queue/queue.go @@ -20,7 +20,7 @@ import ( var log = logging.Logger("provider.queue") const ( - // batchSize is the limit on number of CIDs kept in memory at which ther + // batchSize is the limit on number of CIDs kept in memory at which there // are all written to the datastore. batchSize = 16 * 1024 // dedupCacheSize is the size of the LRU cache used to deduplicate CIDs in diff --git a/provider/reprovider.go b/provider/reprovider.go index 3fca9292c..65e21ccd6 100644 --- a/provider/reprovider.go +++ b/provider/reprovider.go @@ -11,7 +11,6 @@ import ( "github.com/ipfs/boxo/provider/internal/queue" "github.com/ipfs/boxo/verifcid" - "github.com/ipfs/go-cid" "github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore/namespace" diff --git a/tar/extractor_test.go b/tar/extractor_test.go index c3d9970e5..6535ade7a 100644 --- a/tar/extractor_test.go +++ b/tar/extractor_test.go @@ -560,7 +560,7 @@ func chmodRecursive(t *testing.T, path string) { if err != nil { return err } - return os.Chmod(path, fs.FileMode(0700)) + return os.Chmod(path, fs.FileMode(0o700)) }) if err != nil { t.Log("ERROR:", err) From ca8f5e791c6e3e8926b4fb65728b7f83be8f370f Mon Sep 17 00:00:00 2001 From: gammazero <11790789+gammazero@users.noreply.github.com> Date: Mon, 16 Jun 2025 09:49:09 -1000 Subject: [PATCH 3/3] fix formating --- bitswap/network/httpnet/httpnet_test.go | 1 - bitswap/network/httpnet/msg_sender.go | 12 ++++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/bitswap/network/httpnet/httpnet_test.go b/bitswap/network/httpnet/httpnet_test.go index 719eec13a..135b3edd5 100644 --- a/bitswap/network/httpnet/httpnet_test.go +++ b/bitswap/network/httpnet/httpnet_test.go @@ -437,7 +437,6 @@ func TestConnectErrors(t *testing.T) { if !strings.Contains(err.Error(), "denylist") { t.Error("wrong error") } - } func TestSendMessage(t *testing.T) { diff --git a/bitswap/network/httpnet/msg_sender.go b/bitswap/network/httpnet/msg_sender.go index 70d14a976..a85fdbed0 100644 --- a/bitswap/network/httpnet/msg_sender.go +++ b/bitswap/network/httpnet/msg_sender.go @@ -190,11 +190,11 @@ func (sender *httpMsgSender) tryURL(ctx context.Context, u *senderURL, entry bsm var method string - switch { - case entry.WantType == pb.Message_Wantlist_Block: - method = "GET" - case entry.WantType == pb.Message_Wantlist_Have: - method = "HEAD" + switch entry.WantType { + case pb.Message_Wantlist_Block: + method = http.MethodGet + case pb.Message_Wantlist_Have: + method = http.MethodHead default: panic("unknown bitswap entry type") } @@ -204,7 +204,7 @@ func (sender *httpMsgSender) tryURL(ctx context.Context, u *senderURL, entry bsm // is worse than downloading some extra bytes. We do abort if the // context WAS already cancelled before making the request. if err := ctx.Err(); err != nil { - log.Debugf("aborted before sending: %s %q", method, u.ParsedURL.URL) + log.Debugf("aborted before sending: %s %q", method, u.URL) return nil, &senderError{ Type: typeContext, Err: err,