diff --git a/bitswap/bitswap.go b/bitswap/bitswap.go index c4685a2ae..d4c38225b 100644 --- a/bitswap/bitswap.go +++ b/bitswap/bitswap.go @@ -9,16 +9,14 @@ import ( "github.com/ipfs/boxo/bitswap/network" "github.com/ipfs/boxo/bitswap/server" "github.com/ipfs/boxo/bitswap/tracer" - "github.com/ipfs/go-metrics-interface" - blockstore "github.com/ipfs/boxo/blockstore" exchange "github.com/ipfs/boxo/exchange" blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log/v2" + "github.com/ipfs/go-metrics-interface" "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/routing" - "go.uber.org/multierr" ) diff --git a/bitswap/client/internal/getter/getter.go b/bitswap/client/internal/getter/getter.go index c03b2aecc..5a5613002 100644 --- a/bitswap/client/internal/getter/getter.go +++ b/bitswap/client/internal/getter/getter.go @@ -6,11 +6,10 @@ import ( "github.com/ipfs/boxo/bitswap/client/internal" notifications "github.com/ipfs/boxo/bitswap/client/internal/notifications" - logging "github.com/ipfs/go-log/v2" - blocks "github.com/ipfs/go-block-format" cid "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" + logging "github.com/ipfs/go-log/v2" ) var log = logging.Logger("bitswap/client/getter") diff --git a/bitswap/client/internal/peermanager/peermanager.go b/bitswap/client/internal/peermanager/peermanager.go index 4634ff164..f070462d2 100644 --- a/bitswap/client/internal/peermanager/peermanager.go +++ b/bitswap/client/internal/peermanager/peermanager.go @@ -4,10 +4,9 @@ import ( "context" "sync" + cid "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log/v2" "github.com/ipfs/go-metrics-interface" - - cid "github.com/ipfs/go-cid" peer "github.com/libp2p/go-libp2p/core/peer" ) diff --git a/bitswap/client/internal/peermanager/peerwantmanager.go b/bitswap/client/internal/peermanager/peerwantmanager.go index ac727d837..6c8960c82 100644 --- a/bitswap/client/internal/peermanager/peerwantmanager.go +++ b/bitswap/client/internal/peermanager/peerwantmanager.go @@ -158,7 +158,6 @@ func (pwm *peerWantManager) broadcastWantHaves(wantHaves []cid.Cid) { // sendWants only sends the peer the want-blocks and want-haves that have not // already been sent to it. func (pwm *peerWantManager) sendWants(p peer.ID, wantBlocks []cid.Cid, wantHaves []cid.Cid) { - // Get the existing want-blocks and want-haves for the peer pws, ok := pwm.peerWants[p] if !ok { diff --git a/bitswap/client/internal/session/session_test.go b/bitswap/client/internal/session/session_test.go index c0d26a91d..165ba521c 100644 --- a/bitswap/client/internal/session/session_test.go +++ b/bitswap/client/internal/session/session_test.go @@ -145,6 +145,7 @@ func (pm *fakePeerManager) UnregisterSession(uint64) {} func (pm *fakePeerManager) SendWants(context.Context, peer.ID, []cid.Cid, []cid.Cid) bool { return true } + func (pm *fakePeerManager) BroadcastWantHaves(ctx context.Context, cids []cid.Cid) { select { case pm.wantReqs <- wantReq{cids}: @@ -287,7 +288,7 @@ func TestSessionFindMorePeers(t *testing.T) { // Make sure the first block is not included because it has already // been received for _, c := range receivedWantReq.cids { - require.False(t, c.Equals(cids[0]), "should not braodcast block that was already received") + require.False(t, c.Equals(cids[0]), "should not broadcast block that was already received") } case <-ctx.Done(): t.Fatal("Never rebroadcast want list") diff --git a/bitswap/client/internal/session/sessionwantsender.go b/bitswap/client/internal/session/sessionwantsender.go index ba7e8b0c5..bc3e6c8db 100644 --- a/bitswap/client/internal/session/sessionwantsender.go +++ b/bitswap/client/internal/session/sessionwantsender.go @@ -4,7 +4,6 @@ import ( "context" bsbpm "github.com/ipfs/boxo/bitswap/client/internal/blockpresencemanager" - cid "github.com/ipfs/go-cid" peer "github.com/libp2p/go-libp2p/core/peer" ) diff --git a/bitswap/client/internal/sessioninterestmanager/sessioninterestmanager.go b/bitswap/client/internal/sessioninterestmanager/sessioninterestmanager.go index 3756005d8..698e26c8e 100644 --- a/bitswap/client/internal/sessioninterestmanager/sessioninterestmanager.go +++ b/bitswap/client/internal/sessioninterestmanager/sessioninterestmanager.go @@ -4,7 +4,6 @@ import ( "sync" blocks "github.com/ipfs/go-block-format" - cid "github.com/ipfs/go-cid" ) diff --git a/bitswap/client/internal/sessionmanager/sessionmanager.go b/bitswap/client/internal/sessionmanager/sessionmanager.go index 0d2b24330..16a8e7b40 100644 --- a/bitswap/client/internal/sessionmanager/sessionmanager.go +++ b/bitswap/client/internal/sessionmanager/sessionmanager.go @@ -6,18 +6,17 @@ import ( "sync" "time" - cid "github.com/ipfs/go-cid" - delay "github.com/ipfs/go-ipfs-delay" - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/trace" - "github.com/ipfs/boxo/bitswap/client/internal" bsbpm "github.com/ipfs/boxo/bitswap/client/internal/blockpresencemanager" notifications "github.com/ipfs/boxo/bitswap/client/internal/notifications" bssession "github.com/ipfs/boxo/bitswap/client/internal/session" bssim "github.com/ipfs/boxo/bitswap/client/internal/sessioninterestmanager" exchange "github.com/ipfs/boxo/exchange" + cid "github.com/ipfs/go-cid" + delay "github.com/ipfs/go-ipfs-delay" peer "github.com/libp2p/go-libp2p/core/peer" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) // Session is a session that is managed by the session manager diff --git a/bitswap/client/internal/sessionpeermanager/sessionpeermanager.go b/bitswap/client/internal/sessionpeermanager/sessionpeermanager.go index 1832e9c7f..ce9726ea1 100644 --- a/bitswap/client/internal/sessionpeermanager/sessionpeermanager.go +++ b/bitswap/client/internal/sessionpeermanager/sessionpeermanager.go @@ -5,7 +5,6 @@ import ( "sync" logging "github.com/ipfs/go-log/v2" - peer "github.com/libp2p/go-libp2p/core/peer" ) diff --git a/bitswap/client/wantlist/wantlist.go b/bitswap/client/wantlist/wantlist.go index 20432a2b1..bf8b33b49 100644 --- a/bitswap/client/wantlist/wantlist.go +++ b/bitswap/client/wantlist/wantlist.go @@ -7,7 +7,6 @@ import ( "slices" pb "github.com/ipfs/boxo/bitswap/message/pb" - cid "github.com/ipfs/go-cid" ) diff --git a/bitswap/message/message.go b/bitswap/message/message.go index a0a45970b..86ba866ad 100644 --- a/bitswap/message/message.go +++ b/bitswap/message/message.go @@ -7,14 +7,12 @@ import ( "github.com/ipfs/boxo/bitswap/client/wantlist" pb "github.com/ipfs/boxo/bitswap/message/pb" - + u "github.com/ipfs/boxo/util" blocks "github.com/ipfs/go-block-format" cid "github.com/ipfs/go-cid" pool "github.com/libp2p/go-buffer-pool" - msgio "github.com/libp2p/go-msgio" - - u "github.com/ipfs/boxo/util" "github.com/libp2p/go-libp2p/core/network" + msgio "github.com/libp2p/go-msgio" ) // BitSwapMessage is the basic interface for interacting building, encoding, @@ -116,7 +114,7 @@ func (e *Entry) Size() int { func (e *Entry) ToPB() pb.Message_Wantlist_Entry { return pb.Message_Wantlist_Entry{ Block: pb.Cid{Cid: e.Cid}, - Priority: int32(e.Priority), + Priority: e.Priority, Cancel: e.Cancel, WantType: e.WantType, SendDontHave: e.SendDontHave, diff --git a/bitswap/message/pb/cid_test.go b/bitswap/message/pb/cid_test.go index 6d346488a..7e53d9060 100644 --- a/bitswap/message/pb/cid_test.go +++ b/bitswap/message/pb/cid_test.go @@ -4,10 +4,9 @@ import ( "bytes" "testing" + pb "github.com/ipfs/boxo/bitswap/message/pb" u "github.com/ipfs/boxo/util" "github.com/ipfs/go-cid" - - pb "github.com/ipfs/boxo/bitswap/message/pb" ) func TestCID(t *testing.T) { diff --git a/bitswap/network/interface.go b/bitswap/network/interface.go index bc4cf0a8f..eef4a52b2 100644 --- a/bitswap/network/interface.go +++ b/bitswap/network/interface.go @@ -6,9 +6,7 @@ import ( bsmsg "github.com/ipfs/boxo/bitswap/message" "github.com/ipfs/boxo/bitswap/network/internal" - cid "github.com/ipfs/go-cid" - "github.com/libp2p/go-libp2p/core/connmgr" "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/routing" diff --git a/bitswap/network/ipfs_impl.go b/bitswap/network/ipfs_impl.go index 4a60aaf6b..952ee54aa 100644 --- a/bitswap/network/ipfs_impl.go +++ b/bitswap/network/ipfs_impl.go @@ -10,7 +10,6 @@ import ( bsmsg "github.com/ipfs/boxo/bitswap/message" "github.com/ipfs/boxo/bitswap/network/internal" - logging "github.com/ipfs/go-log/v2" "github.com/libp2p/go-libp2p/core/connmgr" "github.com/libp2p/go-libp2p/core/host" diff --git a/bitswap/server/internal/decision/engine.go b/bitswap/server/internal/decision/engine.go index 308673696..ac04ebe77 100644 --- a/bitswap/server/internal/decision/engine.go +++ b/bitswap/server/internal/decision/engine.go @@ -248,7 +248,7 @@ type TaskInfo struct { type TaskComparator func(ta, tb *TaskInfo) bool // PeerBlockRequestFilter is used to accept / deny requests for a CID coming from a PeerID -// It should return true if the request should be fullfilled. +// It should return true if the request should be fulfilled. type PeerBlockRequestFilter func(p peer.ID, c cid.Cid) bool type Option func(*Engine) @@ -683,7 +683,7 @@ func (e *Engine) MessageReceived(ctx context.Context, p peer.ID, m bsmsg.BitSwap wants, cancels, denials, err := e.splitWantsCancelsDenials(p, m) if err != nil { - // This is a truely broken client, let's kill the connection. + // This is a truly broken client, let's kill the connection. log.Warnw(err.Error(), "local", e.self, "remote", p) return true } diff --git a/bitswap/server/internal/decision/engine_test.go b/bitswap/server/internal/decision/engine_test.go index 2e52ae8ed..5148d4fc1 100644 --- a/bitswap/server/internal/decision/engine_test.go +++ b/bitswap/server/internal/decision/engine_test.go @@ -912,8 +912,7 @@ func TestSendReceivedBlocksToPeersThatWantThem(t *testing.T) { _, env = getNextEnvelope(e, next, 5*time.Millisecond) if env == nil { t.Fatal("expected envelope") - } - if env.Peer != partner { + } else if env.Peer != partner { t.Fatal("expected message to peer") } sentBlk := env.Message.Blocks() @@ -947,8 +946,7 @@ func TestSendDontHave(t *testing.T) { next, env := getNextEnvelope(e, next, 10*time.Millisecond) if env == nil { t.Fatal("expected envelope") - } - if env.Peer != partner { + } else if env.Peer != partner { t.Fatal("expected message to peer") } if len(env.Message.Blocks()) > 0 { @@ -978,8 +976,7 @@ func TestSendDontHave(t *testing.T) { _, env = getNextEnvelope(e, next, 10*time.Millisecond) if env == nil { t.Fatal("expected envelope") - } - if env.Peer != partner { + } else if env.Peer != partner { t.Fatal("expected message to peer") } if len(env.Message.Blocks()) != 2 { diff --git a/bitswap/server/internal/decision/peer_ledger.go b/bitswap/server/internal/decision/peer_ledger.go index 227e50de1..588b9a19b 100644 --- a/bitswap/server/internal/decision/peer_ledger.go +++ b/bitswap/server/internal/decision/peer_ledger.go @@ -3,7 +3,6 @@ package decision import ( wl "github.com/ipfs/boxo/bitswap/client/wantlist" pb "github.com/ipfs/boxo/bitswap/message/pb" - "github.com/ipfs/go-cid" "github.com/libp2p/go-libp2p/core/peer" ) diff --git a/bitswap/server/server.go b/bitswap/server/server.go index 6a2ceb3f9..1c4ee29be 100644 --- a/bitswap/server/server.go +++ b/bitswap/server/server.go @@ -408,7 +408,7 @@ func (bs *Server) NotifyNewBlocks(ctx context.Context, blks ...blocks.Block) err func (bs *Server) ReceiveMessage(ctx context.Context, p peer.ID, incoming message.BitSwapMessage) { // This call records changes to wantlists, blocks received, - // and number of bytes transfered. + // and number of bytes transferred. mustKillConnection := bs.engine.MessageReceived(ctx, p, incoming) if mustKillConnection { bs.network.DisconnectFrom(ctx, p) @@ -422,7 +422,7 @@ func (bs *Server) ReceiveMessage(ctx context.Context, p peer.ID, incoming messag } // ReceivedBlocks notify the decision engine that a peer is well behaving -// and gave us usefull data, potentially increasing it's score and making us +// and gave us useful data, potentially increasing it's score and making us // send them more data in exchange. func (bs *Server) ReceivedBlocks(from peer.ID, blks []blocks.Block) { bs.engine.ReceivedBlocks(from, blks) diff --git a/bitswap/testnet/interface.go b/bitswap/testnet/interface.go index ec2818518..4320c8d90 100644 --- a/bitswap/testnet/interface.go +++ b/bitswap/testnet/interface.go @@ -2,7 +2,6 @@ package bitswap import ( bsnet "github.com/ipfs/boxo/bitswap/network" - tnet "github.com/libp2p/go-libp2p-testing/net" "github.com/libp2p/go-libp2p/core/peer" ) diff --git a/bitswap/testnet/network_test.go b/bitswap/testnet/network_test.go index 2d45e09b1..f91c3082e 100644 --- a/bitswap/testnet/network_test.go +++ b/bitswap/testnet/network_test.go @@ -7,10 +7,8 @@ import ( bsmsg "github.com/ipfs/boxo/bitswap/message" bsnet "github.com/ipfs/boxo/bitswap/network" - blocks "github.com/ipfs/go-block-format" delay "github.com/ipfs/go-ipfs-delay" - tnet "github.com/libp2p/go-libp2p-testing/net" "github.com/libp2p/go-libp2p/core/peer" ) diff --git a/bitswap/testnet/peernet.go b/bitswap/testnet/peernet.go index 84fa70c6e..01608f755 100644 --- a/bitswap/testnet/peernet.go +++ b/bitswap/testnet/peernet.go @@ -4,7 +4,6 @@ import ( "context" bsnet "github.com/ipfs/boxo/bitswap/network" - tnet "github.com/libp2p/go-libp2p-testing/net" "github.com/libp2p/go-libp2p/core/peer" mockpeernet "github.com/libp2p/go-libp2p/p2p/net/mock" diff --git a/blockservice/blockservice.go b/blockservice/blockservice.go index 810f26d3f..421831b60 100644 --- a/blockservice/blockservice.go +++ b/blockservice/blockservice.go @@ -8,9 +8,7 @@ import ( "io" "sync" - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/trace" - + "github.com/ipfs/boxo/blockservice/internal" "github.com/ipfs/boxo/blockstore" "github.com/ipfs/boxo/exchange" "github.com/ipfs/boxo/verifcid" @@ -18,8 +16,8 @@ import ( "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" logging "github.com/ipfs/go-log/v2" - - "github.com/ipfs/boxo/blockservice/internal" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) var logger = logging.Logger("blockservice") @@ -488,7 +486,7 @@ func ContextWithSession(ctx context.Context, bs BlockService) context.Context { // EmbedSessionInContext is like [ContextWithSession] but it allows to embed an existing session. func EmbedSessionInContext(ctx context.Context, ses *Session) context.Context { - // use ses.bs as a key, so if multiple blockservices use embeded sessions it gets dispatched to the matching blockservice. + // use ses.bs as a key, so if multiple blockservices use embedded sessions it gets dispatched to the matching blockservice. return context.WithValue(ctx, ses.bs, ses) } diff --git a/blockservice/test/blocks_test.go b/blockservice/test/blocks_test.go index 6cb56faab..3945fafe7 100644 --- a/blockservice/test/blocks_test.go +++ b/blockservice/test/blocks_test.go @@ -8,7 +8,6 @@ import ( "time" . "github.com/ipfs/boxo/blockservice" - blockstore "github.com/ipfs/boxo/blockstore" offline "github.com/ipfs/boxo/exchange/offline" u "github.com/ipfs/boxo/util" diff --git a/blockstore/blockstore.go b/blockstore/blockstore.go index 368670d3d..8f722af00 100644 --- a/blockstore/blockstore.go +++ b/blockstore/blockstore.go @@ -83,13 +83,13 @@ type Viewer interface { // garbage-collection operations. type GCLocker interface { // GCLock locks the blockstore for garbage collection. No operations - // that expect to finish with a pin should ocurr simultaneously. + // that expect to finish with a pin should occur simultaneously. // Reading during GC is safe, and requires no lock. GCLock(context.Context) Unlocker // PinLock locks the blockstore for sequences of puts expected to finish // with a pin (before GC). Multiple put->pin sequences can write through - // at the same time, but no GC should happen simulatenously. + // at the same time, but no GC should happen simultaneously. // Reading during Pinning is safe, and requires no lock. PinLock(context.Context) Unlocker diff --git a/blockstore/caching.go b/blockstore/caching.go index 67fe8cade..c80f5780f 100644 --- a/blockstore/caching.go +++ b/blockstore/caching.go @@ -8,7 +8,7 @@ import ( ) // CacheOpts wraps options for CachedBlockStore(). -// Next to each option is it aproximate memory usage per unit +// Next to each option is it approximate memory usage per unit type CacheOpts struct { HasBloomFilterSize int // 1 byte HasBloomFilterHashes int // No size, 7 is usually best, consult bloom papers diff --git a/bootstrap/bootstrap_test.go b/bootstrap/bootstrap_test.go index d933379d4..360fbc648 100644 --- a/bootstrap/bootstrap_test.go +++ b/bootstrap/bootstrap_test.go @@ -125,7 +125,6 @@ func TestNoTempPeersLoadAndSave(t *testing.T) { time.Sleep(4 * period) bootstrapper.Close() - } func assertPanics(t *testing.T, name string, f func()) { diff --git a/fetcher/impl/blockservice/fetcher_test.go b/fetcher/impl/blockservice/fetcher_test.go index 55c1d5c21..dba1f4321 100644 --- a/fetcher/impl/blockservice/fetcher_test.go +++ b/fetcher/impl/blockservice/fetcher_test.go @@ -6,9 +6,6 @@ import ( "testing" "time" - "github.com/ipld/go-ipld-prime/traversal/selector" - "github.com/ipld/go-ipld-prime/traversal/selector/builder" - testinstance "github.com/ipfs/boxo/bitswap/testinstance" tn "github.com/ipfs/boxo/bitswap/testnet" "github.com/ipfs/boxo/blockservice" @@ -23,6 +20,8 @@ import ( "github.com/ipld/go-ipld-prime/fluent" cidlink "github.com/ipld/go-ipld-prime/linking/cid" basicnode "github.com/ipld/go-ipld-prime/node/basic" + "github.com/ipld/go-ipld-prime/traversal/selector" + "github.com/ipld/go-ipld-prime/traversal/selector/builder" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) 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/files/file_test.go b/files/file_test.go index 07d9f04db..a695d809d 100644 --- a/files/file_test.go +++ b/files/file_test.go @@ -53,7 +53,7 @@ func TestReaderFiles(t *testing.T) { func TestReaderFileStat(t *testing.T) { reader := strings.NewReader("beep boop") - mode := os.FileMode(0754) + mode := os.FileMode(0o754) mtime := time.Date(2020, 11, 2, 12, 27, 35, 55555, time.UTC) stat := &mockFileInfo{name: "test", mode: mode, mtime: mtime} @@ -217,13 +217,13 @@ implicit file2 kind: TFile, name: "£ẞǑǓÆ æ ♫♬", value: "beep", - mode: 0754, + mode: 0o754, mtime: time.Unix(1604320500, 55555), }, { kind: TDirStart, name: "dir1", - mode: 0755, + mode: 0o755, mtime: time.Unix(1604320500, 0), }, { @@ -235,19 +235,19 @@ implicit file2 kind: TFile, name: "nested2", value: "some content", - mode: 0600, + mode: 0o600, }, { kind: TSymlink, name: "simlynk", value: "anotherfile", - mode: 0777, + mode: 0o777, }, { kind: TSymlink, name: "simlynk2", value: "anotherfile", - mode: 0777, + mode: 0o777, mtime: time.Unix(1604320500, 0), }, { @@ -265,7 +265,7 @@ implicit file2 kind: TFile, name: "deep_implicit", value: "implicit file1", - mode: 0644, + mode: 0o644, }, { kind: TDirEnd, @@ -274,7 +274,7 @@ implicit file2 kind: TFile, name: "shallow_implicit", value: "implicit file2", - mode: 0755, + mode: 0o755, mtime: time.Unix(1604320500, 0), }, { diff --git a/files/meta_posix.go b/files/meta_posix.go index d3d961593..106576fa6 100644 --- a/files/meta_posix.go +++ b/files/meta_posix.go @@ -22,7 +22,7 @@ func updateMtime(path string, mtime time.Time) error { if mtime.IsZero() { return nil } - var AtFdCwd = -100 + AtFdCwd := -100 pathname, err := syscall.BytePtrFromString(path) if err != nil { return err diff --git a/files/meta_windows.go b/files/meta_windows.go index e060ec02f..58a8f2024 100644 --- a/files/meta_windows.go +++ b/files/meta_windows.go @@ -15,11 +15,11 @@ func updateMode(path string, mode os.FileMode) error { return nil } // read+write if owner, group or world writeable - if mode&0222 != 0 { - return os.Chmod(path, 0600) + if mode&0o222 != 0 { + return os.Chmod(path, 0o600) } // otherwise read-only - return os.Chmod(path, 0400) + return os.Chmod(path, 0o400) } func updateMtime(path string, mtime time.Time) error { diff --git a/files/multifilereader_test.go b/files/multifilereader_test.go index 623c5404a..7660b3ef1 100644 --- a/files/multifilereader_test.go +++ b/files/multifilereader_test.go @@ -20,7 +20,7 @@ func newBytesFileWithPath(abspath string, b []byte) File { return &ReaderFile{ abspath: abspath, reader: bytesReaderCloser{bytes.NewReader(b)}, - stat: &mockFileInfo{name: path.Base(abspath), mode: 0754, mtime: time.Unix(1604320500, 55555)}, + stat: &mockFileInfo{name: path.Base(abspath), mode: 0o754, mtime: time.Unix(1604320500, 55555)}, fsize: int64(len(b)), } } @@ -64,7 +64,7 @@ func runMultiFileReaderToMultiFileTest(t *testing.T, binaryFileName, rawAbsPath, require.True(t, it.Next()) require.Equal(t, "beep.txt", it.Name()) n := it.Node() - require.Equal(t, fs.FileMode(0754), n.Mode(), "unexpected file mode") + require.Equal(t, fs.FileMode(0o754), n.Mode(), "unexpected file mode") require.Equal(t, time.Unix(1604320500, 55555), n.ModTime(), "unexpected last modification time") require.True(t, it.Next()) require.Equal(t, "boop", it.Name()) @@ -122,14 +122,14 @@ func getTestMultiFileReader(t *testing.T) *MultiFileReader { "boop": NewMapDirectory(map[string]Node{ "a.txt": NewReaderStatFile( strings.NewReader("bleep"), - &mockFileInfo{name: "a.txt", mode: 0744, mtime: time.Time{}}), + &mockFileInfo{name: "a.txt", mode: 0o744, mtime: time.Time{}}), "b.txt": NewReaderStatFile( strings.NewReader("bloop"), - &mockFileInfo{name: "b.txt", mode: 0666, mtime: time.Unix(1604320500, 0)}), + &mockFileInfo{name: "b.txt", mode: 0o666, mtime: time.Unix(1604320500, 0)}), }), "beep.txt": NewReaderStatFile( strings.NewReader("beep"), - &mockFileInfo{name: "beep.txt", mode: 0754, mtime: time.Unix(1604320500, 55555)}), + &mockFileInfo{name: "beep.txt", mode: 0o754, mtime: time.Unix(1604320500, 55555)}), }) // testing output by reading it with the go stdlib "mime/multipart" Reader diff --git a/files/tarwriter_test.go b/files/tarwriter_test.go index 559d77f3d..67bff5014 100644 --- a/files/tarwriter_test.go +++ b/files/tarwriter_test.go @@ -14,9 +14,9 @@ func TestTarWriter(t *testing.T) { "boop": NewMapStatDirectory(map[string]Node{ "a.txt": NewBytesFile([]byte("bleep")), "b.txt": NewBytesFile([]byte("bloop")), - }, &mockFileInfo{name: "", mode: 0750, mtime: time.Unix(6600000000, 0)}), + }, &mockFileInfo{name: "", mode: 0o750, mtime: time.Unix(6600000000, 0)}), "beep.txt": NewBytesStatFile([]byte("beep"), - &mockFileInfo{name: "beep.txt", size: 4, mode: 0766, mtime: time.Unix(1604320500, 54321)}), + &mockFileInfo{name: "beep.txt", size: 4, mode: 0o766, mtime: time.Unix(1604320500, 54321)}), "boop-sl": NewSymlinkFile("boop", time.Unix(6600050000, 0)), }) @@ -64,36 +64,36 @@ func TestTarWriter(t *testing.T) { if cur, err = tr.Next(); err != nil { t.Fatal(err) } - checkHeader("", tar.TypeDir, 0, 0755, time.Time{}) + checkHeader("", tar.TypeDir, 0, 0o755, time.Time{}) if cur, err = tr.Next(); err != nil { t.Fatal(err) } - checkHeader("beep.txt", tar.TypeReg, 4, 0766, time.Unix(1604320500, 54321)) + checkHeader("beep.txt", tar.TypeReg, 4, 0o766, time.Unix(1604320500, 54321)) if cur, err = tr.Next(); err != nil { t.Fatal(err) } - checkHeader("boop", tar.TypeDir, 0, 0750, time.Unix(6600000000, 0)) + checkHeader("boop", tar.TypeDir, 0, 0o750, time.Unix(6600000000, 0)) if cur, err = tr.Next(); err != nil { t.Fatal(err) } - checkHeader("boop/a.txt", tar.TypeReg, 5, 0644, time.Time{}) + checkHeader("boop/a.txt", tar.TypeReg, 5, 0o644, time.Time{}) if cur, err = tr.Next(); err != nil { t.Fatal(err) } - checkHeader("boop/b.txt", tar.TypeReg, 5, 0644, time.Time{}) + checkHeader("boop/b.txt", tar.TypeReg, 5, 0o644, time.Time{}) if cur, err = tr.Next(); err != nil { t.Fatal(err) } - checkHeader("boop-sl", tar.TypeSymlink, 0, 0777, time.Unix(6600050000, 0)) + checkHeader("boop-sl", tar.TypeSymlink, 0, 0o777, time.Unix(6600050000, 0)) if cur, err = tr.Next(); err != nil { t.Fatal(err) } - checkHeader("file.txt", tar.TypeReg, 13, 0644, time.Time{}) + checkHeader("file.txt", tar.TypeReg, 13, 0o644, time.Time{}) if cur, err = tr.Next(); err != io.EOF { t.Fatal(err) diff --git a/files/util.go b/files/util.go index 1ac673b0e..b131e5a4b 100644 --- a/files/util.go +++ b/files/util.go @@ -36,11 +36,11 @@ func UnixPermsOrDefault(n Node) uint32 { switch n.(type) { case *Symlink: - return 0777 + return 0o777 case Directory: - return 0755 + return 0o755 default: - return 0644 + return 0o644 } } diff --git a/files/util_test.go b/files/util_test.go index 396abec99..d4cd7c8ce 100644 --- a/files/util_test.go +++ b/files/util_test.go @@ -8,17 +8,17 @@ import ( ) func TestModePermsToUnixPerms(t *testing.T) { - assert.Equal(t, uint32(0777), ModePermsToUnixPerms(os.FileMode(0777))) - assert.Equal(t, uint32(04755), ModePermsToUnixPerms(0755|os.ModeSetuid)) - assert.Equal(t, uint32(02777), ModePermsToUnixPerms(0777|os.ModeSetgid)) - assert.Equal(t, uint32(01377), ModePermsToUnixPerms(0377|os.ModeSticky)) - assert.Equal(t, uint32(05300), ModePermsToUnixPerms(0300|os.ModeSetuid|os.ModeSticky)) + assert.Equal(t, uint32(0o777), ModePermsToUnixPerms(os.FileMode(0o777))) + assert.Equal(t, uint32(0o4755), ModePermsToUnixPerms(0o755|os.ModeSetuid)) + assert.Equal(t, uint32(0o2777), ModePermsToUnixPerms(0o777|os.ModeSetgid)) + assert.Equal(t, uint32(0o1377), ModePermsToUnixPerms(0o377|os.ModeSticky)) + assert.Equal(t, uint32(0o5300), ModePermsToUnixPerms(0o300|os.ModeSetuid|os.ModeSticky)) } func TestUnixPermsToModePerms(t *testing.T) { - assert.Equal(t, os.FileMode(0777), UnixPermsToModePerms(0777)) - assert.Equal(t, 0755|os.ModeSetuid, UnixPermsToModePerms(04755)) - assert.Equal(t, 0777|os.ModeSetgid, UnixPermsToModePerms(02777)) - assert.Equal(t, 0377|os.ModeSticky, UnixPermsToModePerms(01377)) - assert.Equal(t, 0300|os.ModeSetuid|os.ModeSticky, UnixPermsToModePerms(05300)) + assert.Equal(t, os.FileMode(0o777), UnixPermsToModePerms(0o777)) + assert.Equal(t, 0o755|os.ModeSetuid, UnixPermsToModePerms(0o4755)) + assert.Equal(t, 0o777|os.ModeSetgid, UnixPermsToModePerms(0o2777)) + assert.Equal(t, 0o377|os.ModeSticky, UnixPermsToModePerms(0o1377)) + assert.Equal(t, 0o300|os.ModeSetuid|os.ModeSticky, UnixPermsToModePerms(0o5300)) } diff --git a/files/webfile_test.go b/files/webfile_test.go index b2a7238ab..867c60fe8 100644 --- a/files/webfile_test.go +++ b/files/webfile_test.go @@ -13,7 +13,7 @@ import ( func TestWebFile(t *testing.T) { const content = "Hello world!" - const mode = 0644 + const mode = 0o644 mtime := time.Unix(16043205005, 0) s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { diff --git a/filestore/filestore_test.go b/filestore/filestore_test.go index 4d17adbe7..ddaf33444 100644 --- a/filestore/filestore_test.go +++ b/filestore/filestore_test.go @@ -7,10 +7,9 @@ import ( "os" "testing" - dag "github.com/ipfs/boxo/ipld/merkledag" - blockstore "github.com/ipfs/boxo/blockstore" posinfo "github.com/ipfs/boxo/filestore/posinfo" + dag "github.com/ipfs/boxo/ipld/merkledag" cid "github.com/ipfs/go-cid" ds "github.com/ipfs/go-datastore" ipld "github.com/ipfs/go-ipld-format" diff --git a/filestore/fsrefstore.go b/filestore/fsrefstore.go index eb7f190d0..3d7156785 100644 --- a/filestore/fsrefstore.go +++ b/filestore/fsrefstore.go @@ -8,10 +8,9 @@ import ( "os" "path/filepath" - pb "github.com/ipfs/boxo/filestore/pb" - proto "github.com/gogo/protobuf/proto" dshelp "github.com/ipfs/boxo/datastore/dshelp" + pb "github.com/ipfs/boxo/filestore/pb" posinfo "github.com/ipfs/boxo/filestore/posinfo" blocks "github.com/ipfs/go-block-format" cid "github.com/ipfs/go-cid" @@ -239,7 +238,7 @@ func (f *FileManager) readURLDataObj(ctx context.Context, m mh.Multihash, d *pb. return nil, ErrUrlstoreNotEnabled } - req, err := http.NewRequestWithContext(ctx, "GET", d.GetFilePath(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, d.GetFilePath(), nil) if err != nil { return nil, err } @@ -315,6 +314,8 @@ func (f *FileManager) putTo(ctx context.Context, b *posinfo.FilestoreNode, to pu if !f.AllowFiles { return ErrFilestoreNotEnabled } + + //nolint:staticcheck //lint:ignore SA1019 // ignore staticcheck if !filepath.HasPrefix(b.PosInfo.FullPath, f.root) { return fmt.Errorf("cannot add filestore references outside ipfs root (%s)", f.root) diff --git a/filestore/util.go b/filestore/util.go index 21900f055..26685795b 100644 --- a/filestore/util.go +++ b/filestore/util.go @@ -7,9 +7,8 @@ import ( "slices" "strings" - pb "github.com/ipfs/boxo/filestore/pb" - dshelp "github.com/ipfs/boxo/datastore/dshelp" + pb "github.com/ipfs/boxo/filestore/pb" cid "github.com/ipfs/go-cid" ds "github.com/ipfs/go-datastore" dsq "github.com/ipfs/go-datastore/query" diff --git a/gateway/assets/test/main.go b/gateway/assets/test/main.go index c03074dab..ad3fdd8b1 100644 --- a/gateway/assets/test/main.go +++ b/gateway/assets/test/main.go @@ -10,16 +10,15 @@ import ( "github.com/ipfs/boxo/gateway/assets" "github.com/ipfs/go-cid" - "github.com/ipld/go-ipld-prime/multicodec" - "github.com/ipld/go-ipld-prime/node/basicnode" - mc "github.com/multiformats/go-multicodec" - // Ensure basic codecs are registered. _ "github.com/ipld/go-ipld-prime/codec/cbor" _ "github.com/ipld/go-ipld-prime/codec/dagcbor" _ "github.com/ipld/go-ipld-prime/codec/dagjson" _ "github.com/ipld/go-ipld-prime/codec/json" _ "github.com/ipld/go-ipld-prime/codec/raw" + "github.com/ipld/go-ipld-prime/multicodec" + "github.com/ipld/go-ipld-prime/node/basicnode" + mc "github.com/multiformats/go-multicodec" ) //go:embed dag/*.block diff --git a/gateway/backend_blocks.go b/gateway/backend_blocks.go index d62d3d876..79cf99607 100644 --- a/gateway/backend_blocks.go +++ b/gateway/backend_blocks.go @@ -29,6 +29,11 @@ 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" + _ "github.com/ipld/go-ipld-prime/codec/dagjson" + _ "github.com/ipld/go-ipld-prime/codec/json" "github.com/ipld/go-ipld-prime/datamodel" cidlink "github.com/ipld/go-ipld-prime/linking/cid" "github.com/ipld/go-ipld-prime/node/basicnode" @@ -37,12 +42,6 @@ import ( "github.com/ipld/go-ipld-prime/traversal/selector" selectorparse "github.com/ipld/go-ipld-prime/traversal/selector/parse" mc "github.com/multiformats/go-multicodec" - - // Ensure basic codecs are registered. - _ "github.com/ipld/go-ipld-prime/codec/cbor" - _ "github.com/ipld/go-ipld-prime/codec/dagcbor" - _ "github.com/ipld/go-ipld-prime/codec/dagjson" - _ "github.com/ipld/go-ipld-prime/codec/json" ) // BlocksBackend is an [IPFSBackend] implementation based on a [blockservice.BlockService]. @@ -514,7 +513,6 @@ func walkGatewaySimpleSelector(ctx context.Context, lastCid cid.Cid, terminalBlk if err != nil { return err } - foundFileLength = true } to = fileLength + *entityRange.To } diff --git a/gateway/backend_car.go b/gateway/backend_car.go index a0a9eca2d..bc2b3eaba 100644 --- a/gateway/backend_car.go +++ b/gateway/backend_car.go @@ -571,8 +571,10 @@ func (api *CarBackend) GetAll(ctx context.Context, path path.ImmutablePath) (Con return fetchWithPartialRetries(ctx, path, CarParams{Scope: DagScopeAll}, loadTerminalUnixFSElementWithRecursiveDirectories, api.metrics, api.fetchCAR, api.getBlockTimeout) } -type loadTerminalElement[T any] func(ctx context.Context, c cid.Cid, blk blocks.Block, lsys *ipld.LinkSystem, params CarParams, getLsys lsysGetter) (T, error) -type fetchCarFn = func(ctx context.Context, path path.ImmutablePath, params CarParams, cb DataCallback) error +type ( + loadTerminalElement[T any] func(ctx context.Context, c cid.Cid, blk blocks.Block, lsys *ipld.LinkSystem, params CarParams, getLsys lsysGetter) (T, error) + fetchCarFn = func(ctx context.Context, path path.ImmutablePath, params CarParams, cb DataCallback) error +) type terminalPathType[T any] struct { resp T @@ -764,7 +766,6 @@ func (api *CarBackend) GetBlock(ctx context.Context, p path.ImmutablePath) (Cont f = files.NewBytesFile(blockData) return nil }) - if err != nil { return ContentPathMetadata{}, nil, err } @@ -903,7 +904,6 @@ func (api *CarBackend) Head(ctx context.Context, p path.ImmutablePath) (ContentP } return nil }) - if err != nil { return ContentPathMetadata{}, nil, err } @@ -930,7 +930,6 @@ func (api *CarBackend) ResolvePath(ctx context.Context, p path.ImmutablePath) (C return err }) - if err != nil { return ContentPathMetadata{}, err } diff --git a/gateway/backend_car_fetcher_test.go b/gateway/backend_car_fetcher_test.go index 383f20c2d..a01fbbb36 100644 --- a/gateway/backend_car_fetcher_test.go +++ b/gateway/backend_car_fetcher_test.go @@ -3,9 +3,8 @@ package gateway import ( "testing" - "github.com/stretchr/testify/require" - "github.com/ipfs/boxo/path" + "github.com/stretchr/testify/require" ) func TestContentPathToCarUrl(t *testing.T) { diff --git a/gateway/backend_car_files.go b/gateway/backend_car_files.go index 50c298a38..8bae0ebcf 100644 --- a/gateway/backend_car_files.go +++ b/gateway/backend_car_files.go @@ -119,8 +119,10 @@ func (b *backpressuredFile) Seek(offset int64, whence int) (int64, error) { return b.f.Seek(offset, whence) } -var _ files.File = (*backpressuredFile)(nil) -var _ awaitCloser = (*backpressuredFile)(nil) +var ( + _ files.File = (*backpressuredFile)(nil) + _ awaitCloser = (*backpressuredFile)(nil) +) type singleUseDirectory struct { dirIter files.DirIterator @@ -145,7 +147,7 @@ func (b *singleUseDirectory) ModTime() time.Time { } func (b *singleUseDirectory) Size() (int64, error) { - //TODO implement me + // TODO implement me panic("implement me") } @@ -153,8 +155,10 @@ func (b *singleUseDirectory) Entries() files.DirIterator { return b.dirIter } -var _ files.Directory = (*singleUseDirectory)(nil) -var _ awaitCloser = (*singleUseDirectory)(nil) +var ( + _ files.Directory = (*singleUseDirectory)(nil) + _ awaitCloser = (*singleUseDirectory)(nil) +) type backpressuredFlatDirIter struct { linksItr *dagpb.PBLinks__Itr diff --git a/gateway/backend_car_test.go b/gateway/backend_car_test.go index eebd8e19b..f76085db4 100644 --- a/gateway/backend_car_test.go +++ b/gateway/backend_car_test.go @@ -3,6 +3,7 @@ package gateway import ( "bytes" "context" + _ "embed" "errors" "fmt" "io" @@ -12,8 +13,6 @@ import ( "testing" "time" - _ "embed" - "github.com/ipfs/boxo/blockservice" "github.com/ipfs/boxo/exchange/offline" "github.com/ipfs/boxo/files" @@ -603,7 +602,7 @@ func TestCarBackendGetFileRangeRequest(t *testing.T) { trustedGatewayServer := httptest.NewServer(NewHandler(Config{DeserializedResponses: true}, backend)) defer trustedGatewayServer.Close() - req, err := http.NewRequestWithContext(ctx, "GET", trustedGatewayServer.URL+"/ipfs/bafybeigcisqd7m5nf3qmuvjdbakl5bdnh4ocrmacaqkpuh77qjvggmt2sa", nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, trustedGatewayServer.URL+"/ipfs/bafybeigcisqd7m5nf3qmuvjdbakl5bdnh4ocrmacaqkpuh77qjvggmt2sa", nil) require.NoError(t, err) startIndex := 256 endIndex := 750 diff --git a/gateway/blockstore.go b/gateway/blockstore.go index 07c758d05..b2b88d6c9 100644 --- a/gateway/blockstore.go +++ b/gateway/blockstore.go @@ -10,14 +10,12 @@ import ( "sync/atomic" "time" - "github.com/ipfs/go-cid" - format "github.com/ipfs/go-ipld-format" - + lru "github.com/hashicorp/golang-lru/v2" blockstore "github.com/ipfs/boxo/blockstore" "github.com/ipfs/boxo/util" blocks "github.com/ipfs/go-block-format" - - lru "github.com/hashicorp/golang-lru/v2" + "github.com/ipfs/go-cid" + format "github.com/ipfs/go-ipld-format" "github.com/prometheus/client_golang/prometheus" "go.uber.org/zap/zapcore" ) diff --git a/gateway/handler_car.go b/gateway/handler_car.go index 9c63d2d16..8adee0a25 100644 --- a/gateway/handler_car.go +++ b/gateway/handler_car.go @@ -14,7 +14,6 @@ import ( "github.com/cespare/xxhash/v2" "github.com/ipfs/boxo/path" "github.com/ipfs/go-cid" - "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" "go.uber.org/multierr" diff --git a/gateway/handler_car_test.go b/gateway/handler_car_test.go index a9c3667d2..2e79fa013 100644 --- a/gateway/handler_car_test.go +++ b/gateway/handler_car_test.go @@ -145,7 +145,7 @@ func TestContentTypeFromCarParams(t *testing.T) { // below ensures buildContentTypeFromCarParams produces correct Content-Type // at this point we do not do any inferring, it happens in buildCarParams instead - // and tests of *Unspecified here are just present for completenes and to guard + // and tests of *Unspecified here are just present for completes and to guard // against regressions between refactors tests := []struct { params CarParams diff --git a/gateway/handler_codec.go b/gateway/handler_codec.go index b3b1fcce2..80d676409 100644 --- a/gateway/handler_codec.go +++ b/gateway/handler_codec.go @@ -13,17 +13,16 @@ import ( "github.com/ipfs/boxo/gateway/assets" "github.com/ipfs/boxo/path" "github.com/ipfs/go-cid" - "github.com/ipld/go-ipld-prime/multicodec" - "github.com/ipld/go-ipld-prime/node/basicnode" - mc "github.com/multiformats/go-multicodec" - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/trace" - // Ensure basic codecs are registered. _ "github.com/ipld/go-ipld-prime/codec/cbor" _ "github.com/ipld/go-ipld-prime/codec/dagcbor" _ "github.com/ipld/go-ipld-prime/codec/dagjson" _ "github.com/ipld/go-ipld-prime/codec/json" + "github.com/ipld/go-ipld-prime/multicodec" + "github.com/ipld/go-ipld-prime/node/basicnode" + mc "github.com/multiformats/go-multicodec" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) // codecToContentType maps the supported IPLD codecs to the HTTP Content diff --git a/gateway/handler_defaults.go b/gateway/handler_defaults.go index ee4b130ee..c53daf68f 100644 --- a/gateway/handler_defaults.go +++ b/gateway/handler_defaults.go @@ -11,7 +11,6 @@ import ( "strings" mc "github.com/multiformats/go-multicodec" - "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" ) diff --git a/gateway/hostname.go b/gateway/hostname.go index ebdbe9273..29c0b7f81 100644 --- a/gateway/hostname.go +++ b/gateway/hostname.go @@ -12,7 +12,6 @@ import ( cid "github.com/ipfs/go-cid" "github.com/libp2p/go-libp2p/core/peer" dns "github.com/miekg/dns" - mbase "github.com/multiformats/go-multibase" ) @@ -182,7 +181,6 @@ func NewHostnameHandler(c Config, backend IPFSBackend, next http.Handler) http.H // Un-inlined DNS name has a valid DNSLink record. // Update path prefix to use un-inlined FQDN in gateway processing. pathPrefix = "/ipns/" + dnslinkFQDN // → /ipns/my.v-long.example.com - } else if !hasDNSLinkRecord(r.Context(), backend, rootID) { // Inspected _dnslink.my-v--long-example-com as a // fallback, but it had no DNSLink record either. @@ -193,7 +191,6 @@ func NewHostnameHandler(c Config, backend IPFSBackend, next http.Handler) http.H // about missing DNSLink will use the un-inlined FQDN, // and not the inlined one. pathPrefix = "/ipns/" + dnslinkFQDN - } } } diff --git a/gateway/hostname_test.go b/gateway/hostname_test.go index 1a150facb..1bfb07c42 100644 --- a/gateway/hostname_test.go +++ b/gateway/hostname_test.go @@ -23,9 +23,9 @@ func TestToSubdomainURL(t *testing.T) { backend.namesys["/ipns/dnslink.long-name.example.com"] = newMockNamesysItem(path.FromCid(testCID), 0) backend.namesys["/ipns/dnslink.too-long.f1siqrebi3vir8sab33hu5vcy008djegvay6atmz91ojesyjs8lx350b7y7i1nvyw2haytfukfyu2f2x4tocdrfa0zgij6p4zpl4u5o.example.com"] = newMockNamesysItem(path.FromCid(testCID), 0) - httpRequest := httptest.NewRequest("GET", "http://127.0.0.1:8080", nil) - httpsRequest := httptest.NewRequest("GET", "https://https-request-stub.example.com", nil) - httpsProxiedRequest := httptest.NewRequest("GET", "http://proxied-https-request-stub.example.com", nil) + httpRequest := httptest.NewRequest(http.MethodGet, "http://127.0.0.1:8080", nil) + httpsRequest := httptest.NewRequest(http.MethodGet, "https://https-request-stub.example.com", nil) + httpsProxiedRequest := httptest.NewRequest(http.MethodGet, "http://proxied-https-request-stub.example.com", nil) httpsProxiedRequest.Header.Set("X-Forwarded-Proto", "https") for _, test := range []struct { @@ -118,13 +118,13 @@ func TestToDNSLinkFQDN(t *testing.T) { func TestIsHTTPSRequest(t *testing.T) { t.Parallel() - httpRequest := httptest.NewRequest("GET", "http://127.0.0.1:8080", nil) - httpsRequest := httptest.NewRequest("GET", "https://https-request-stub.example.com", nil) - httpsProxiedRequest := httptest.NewRequest("GET", "http://proxied-https-request-stub.example.com", nil) + httpRequest := httptest.NewRequest(http.MethodGet, "http://127.0.0.1:8080", nil) + httpsRequest := httptest.NewRequest(http.MethodGet, "https://https-request-stub.example.com", nil) + httpsProxiedRequest := httptest.NewRequest(http.MethodGet, "http://proxied-https-request-stub.example.com", nil) httpsProxiedRequest.Header.Set("X-Forwarded-Proto", "https") - httpProxiedRequest := httptest.NewRequest("GET", "http://proxied-http-request-stub.example.com", nil) + httpProxiedRequest := httptest.NewRequest(http.MethodGet, "http://proxied-http-request-stub.example.com", nil) httpProxiedRequest.Header.Set("X-Forwarded-Proto", "http") - oddballRequest := httptest.NewRequest("GET", "foo://127.0.0.1:8080", nil) + oddballRequest := httptest.NewRequest(http.MethodGet, "foo://127.0.0.1:8080", nil) for _, test := range []struct { in *http.Request out bool @@ -313,12 +313,14 @@ func TestKnownSubdomainDetails(t *testing.T) { } } -const testInlinedDNSLinkA = "example-com" -const testInlinedDNSLinkB = "docs-ipfs-tech" -const testInlinedDNSLinkC = "en-wikipedia--on--ipfs-org" -const testDNSLinkA = "example.com" -const testDNSLinkB = "docs.ipfs.tech" -const testDNSLinkC = "en.wikipedia-on-ipfs.org" +const ( + testInlinedDNSLinkA = "example-com" + testInlinedDNSLinkB = "docs-ipfs-tech" + testInlinedDNSLinkC = "en-wikipedia--on--ipfs-org" + testDNSLinkA = "example.com" + testDNSLinkB = "docs.ipfs.tech" + testDNSLinkC = "en.wikipedia-on-ipfs.org" +) func inlineDNSLinkSimple(fqdn string) (dnsLabel string, err error) { dnsLabel = strings.ReplaceAll(fqdn, "-", "--") @@ -328,6 +330,7 @@ func inlineDNSLinkSimple(fqdn string) (dnsLabel string, err error) { } return dnsLabel, nil } + func uninlineDNSLinkSimple(dnsLabel string) (fqdn string) { fqdn = strings.ReplaceAll(dnsLabel, "--", "@") // @ placeholder is unused in DNS labels fqdn = strings.ReplaceAll(fqdn, "-", ".") @@ -342,6 +345,7 @@ func BenchmarkUninlineDNSLinkSimple(b *testing.B) { _ = uninlineDNSLinkSimple(testInlinedDNSLinkC) } } + func BenchmarkUninlineDNSLink(b *testing.B) { for i := 0; i < b.N; i++ { _ = UninlineDNSLink(testInlinedDNSLinkA) @@ -357,6 +361,7 @@ func BenchmarkInlineDNSLinkSimple(b *testing.B) { _, _ = inlineDNSLinkSimple(testDNSLinkC) } } + func BenchmarkInlineDNSLink(b *testing.B) { for i := 0; i < b.N; i++ { _, _ = InlineDNSLink(testDNSLinkA) diff --git a/gateway/metrics.go b/gateway/metrics.go index 29df1272d..3bc5ea65a 100644 --- a/gateway/metrics.go +++ b/gateway/metrics.go @@ -178,8 +178,10 @@ func (b *ipfsBackendWithMetrics) GetDNSLinkRecord(ctx context.Context, fqdn stri return p, err } -var _ IPFSBackend = (*ipfsBackendWithMetrics)(nil) -var _ WithContextHint = (*ipfsBackendWithMetrics)(nil) +var ( + _ IPFSBackend = (*ipfsBackendWithMetrics)(nil) + _ WithContextHint = (*ipfsBackendWithMetrics)(nil) +) func (b *ipfsBackendWithMetrics) WrapContextForRequest(ctx context.Context) context.Context { if withCtxWrap, ok := b.backend.(WithContextHint); ok { diff --git a/gateway/serve_http_content.go b/gateway/serve_http_content.go index 9a8ee435f..38b6a5313 100644 --- a/gateway/serve_http_content.go +++ b/gateway/serve_http_content.go @@ -114,7 +114,7 @@ func httpServeContent(w http.ResponseWriter, r *http.Request, modtime time.Time, w.WriteHeader(code) - if r.Method != "HEAD" { + if r.Method != http.MethodHead { io.CopyN(w, content, sendSize) } } @@ -249,7 +249,7 @@ func checkIfNoneMatch(w http.ResponseWriter, r *http.Request) condResult { } func checkIfModifiedSince(r *http.Request, modtime time.Time) condResult { - if r.Method != "GET" && r.Method != "HEAD" { + if r.Method != http.MethodGet && r.Method != http.MethodHead { return condNone } ims := r.Header.Get("If-Modified-Since") @@ -270,7 +270,7 @@ func checkIfModifiedSince(r *http.Request, modtime time.Time) condResult { } func checkIfRange(w http.ResponseWriter, r *http.Request, modtime time.Time) condResult { - if r.Method != "GET" && r.Method != "HEAD" { + if r.Method != http.MethodGet && r.Method != http.MethodHead { return condNone } ir := headerGetExact(r.Header, "If-Range") @@ -341,7 +341,7 @@ func checkPreconditions(w http.ResponseWriter, r *http.Request, modtime time.Tim } switch checkIfNoneMatch(w, r) { case condFalse: - if r.Method == "GET" || r.Method == "HEAD" { + if r.Method == http.MethodGet || r.Method == http.MethodHead { writeNotModified(w) return true, "" } else { diff --git a/ipld/merkledag/dagutils/diff.go b/ipld/merkledag/dagutils/diff.go index 49a3ae627..28da1114f 100644 --- a/ipld/merkledag/dagutils/diff.go +++ b/ipld/merkledag/dagutils/diff.go @@ -5,10 +5,9 @@ import ( "fmt" "path" + dag "github.com/ipfs/boxo/ipld/merkledag" "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" - - dag "github.com/ipfs/boxo/ipld/merkledag" ) // ChangeType denotes type of change in Change diff --git a/ipld/merkledag/dagutils/diffenum.go b/ipld/merkledag/dagutils/diffenum.go index d2d57a8ec..6d7462456 100644 --- a/ipld/merkledag/dagutils/diffenum.go +++ b/ipld/merkledag/dagutils/diffenum.go @@ -4,10 +4,9 @@ import ( "context" "fmt" + mdag "github.com/ipfs/boxo/ipld/merkledag" cid "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" - - mdag "github.com/ipfs/boxo/ipld/merkledag" ) // DiffEnumerate fetches every object in the graph pointed to by 'to' that is diff --git a/ipld/merkledag/dagutils/diffenum_test.go b/ipld/merkledag/dagutils/diffenum_test.go index d22ea7288..a0a937bb6 100644 --- a/ipld/merkledag/dagutils/diffenum_test.go +++ b/ipld/merkledag/dagutils/diffenum_test.go @@ -6,11 +6,10 @@ import ( "fmt" "testing" - "github.com/ipfs/go-cid" - ipld "github.com/ipfs/go-ipld-format" - dag "github.com/ipfs/boxo/ipld/merkledag" mdtest "github.com/ipfs/boxo/ipld/merkledag/test" + "github.com/ipfs/go-cid" + ipld "github.com/ipfs/go-ipld-format" ) func buildNode(name string, desc map[string]ndesc, out map[string]ipld.Node) ipld.Node { diff --git a/ipld/merkledag/dagutils/utils.go b/ipld/merkledag/dagutils/utils.go index 4f6500b25..083e77def 100644 --- a/ipld/merkledag/dagutils/utils.go +++ b/ipld/merkledag/dagutils/utils.go @@ -8,11 +8,10 @@ import ( bserv "github.com/ipfs/boxo/blockservice" bstore "github.com/ipfs/boxo/blockstore" offline "github.com/ipfs/boxo/exchange/offline" + dag "github.com/ipfs/boxo/ipld/merkledag" ds "github.com/ipfs/go-datastore" syncds "github.com/ipfs/go-datastore/sync" ipld "github.com/ipfs/go-ipld-format" - - dag "github.com/ipfs/boxo/ipld/merkledag" ) // Editor represents a ProtoNode tree editor and provides methods to diff --git a/ipld/merkledag/dagutils/utils_test.go b/ipld/merkledag/dagutils/utils_test.go index 3fd3e823f..de0a62f33 100644 --- a/ipld/merkledag/dagutils/utils_test.go +++ b/ipld/merkledag/dagutils/utils_test.go @@ -5,11 +5,10 @@ import ( "strings" "testing" - "github.com/ipfs/go-cid" - ipld "github.com/ipfs/go-ipld-format" - dag "github.com/ipfs/boxo/ipld/merkledag" mdtest "github.com/ipfs/boxo/ipld/merkledag/test" + "github.com/ipfs/go-cid" + ipld "github.com/ipfs/go-ipld-format" ) func TestAddLink(t *testing.T) { 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/merkledag/merkledag_test.go b/ipld/merkledag/merkledag_test.go index 004d462aa..6fc10b70f 100644 --- a/ipld/merkledag/merkledag_test.go +++ b/ipld/merkledag/merkledag_test.go @@ -16,13 +16,12 @@ import ( "testing" "time" - . "github.com/ipfs/boxo/ipld/merkledag" - mdpb "github.com/ipfs/boxo/ipld/merkledag/pb" - dstest "github.com/ipfs/boxo/ipld/merkledag/test" - bserv "github.com/ipfs/boxo/blockservice" bstest "github.com/ipfs/boxo/blockservice/test" offline "github.com/ipfs/boxo/exchange/offline" + . "github.com/ipfs/boxo/ipld/merkledag" + mdpb "github.com/ipfs/boxo/ipld/merkledag/pb" + dstest "github.com/ipfs/boxo/ipld/merkledag/test" blocks "github.com/ipfs/go-block-format" cid "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" diff --git a/ipld/merkledag/node_test.go b/ipld/merkledag/node_test.go index 87fb484e8..64d2c0618 100644 --- a/ipld/merkledag/node_test.go +++ b/ipld/merkledag/node_test.go @@ -7,7 +7,6 @@ import ( . "github.com/ipfs/boxo/ipld/merkledag" mdtest "github.com/ipfs/boxo/ipld/merkledag/test" - cid "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" ) diff --git a/ipld/merkledag/pb/merkledag.pb.go b/ipld/merkledag/pb/merkledag.pb.go index 428459527..1efa26907 100644 --- a/ipld/merkledag/pb/merkledag.pb.go +++ b/ipld/merkledag/pb/merkledag.pb.go @@ -448,7 +448,7 @@ func (m *PBLink) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.XXX_unrecognized) } if m.Tsize != nil { - i = encodeVarintMerkledag(dAtA, i, uint64(*m.Tsize)) + i = encodeVarintMerkledag(dAtA, i, *m.Tsize) i-- dAtA[i] = 0x18 } @@ -539,11 +539,11 @@ func NewPopulatedPBLink(r randyMerkledag, easy bool) *PBLink { } } if r.Intn(5) != 0 { - v2 := string(randStringMerkledag(r)) + v2 := randStringMerkledag(r) this.Name = &v2 } if r.Intn(5) != 0 { - v3 := uint64(uint64(r.Uint32())) + v3 := uint64(r.Uint32()) this.Tsize = &v3 } if !easy && r.Intn(10) != 0 { @@ -644,7 +644,7 @@ func randFieldMerkledag(dAtA []byte, r randyMerkledag, fieldNumber int, wire int func encodeVarintPopulateMerkledag(dAtA []byte, v uint64) []byte { for v >= 1<<7 { - dAtA = append(dAtA, uint8(uint64(v)&0x7f|0x80)) + dAtA = append(dAtA, uint8(v&0x7f|0x80)) v >>= 7 } dAtA = append(dAtA, uint8(v)) @@ -666,7 +666,7 @@ func (m *PBLink) Size() (n int) { n += 1 + l + sovMerkledag(uint64(l)) } if m.Tsize != nil { - n += 1 + sovMerkledag(uint64(*m.Tsize)) + n += 1 + sovMerkledag(*m.Tsize) } if m.XXX_unrecognized != nil { n += len(m.XXX_unrecognized) diff --git a/ipld/merkledag/raw.go b/ipld/merkledag/raw.go index 69de2cc46..621ceeac9 100644 --- a/ipld/merkledag/raw.go +++ b/ipld/merkledag/raw.go @@ -6,12 +6,11 @@ import ( u "github.com/ipfs/boxo/util" blocks "github.com/ipfs/go-block-format" + cid "github.com/ipfs/go-cid" + format "github.com/ipfs/go-ipld-format" legacy "github.com/ipfs/go-ipld-legacy" ipld "github.com/ipld/go-ipld-prime" basicnode "github.com/ipld/go-ipld-prime/node/basic" - - cid "github.com/ipfs/go-cid" - format "github.com/ipfs/go-ipld-format" ) // RawNode represents a node which only contains data. diff --git a/ipld/merkledag/readonly_test.go b/ipld/merkledag/readonly_test.go index 0d00eebfb..16abb7a16 100644 --- a/ipld/merkledag/readonly_test.go +++ b/ipld/merkledag/readonly_test.go @@ -6,7 +6,6 @@ import ( . "github.com/ipfs/boxo/ipld/merkledag" dstest "github.com/ipfs/boxo/ipld/merkledag/test" - cid "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" ) diff --git a/ipld/merkledag/test/dag_generator.go b/ipld/merkledag/test/dag_generator.go index 41f6c267d..cc0e06c5f 100644 --- a/ipld/merkledag/test/dag_generator.go +++ b/ipld/merkledag/test/dag_generator.go @@ -5,11 +5,10 @@ import ( "fmt" "strconv" + "github.com/ipfs/boxo/ipld/merkledag" blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-cid" format "github.com/ipfs/go-ipld-format" - - "github.com/ipfs/boxo/ipld/merkledag" ) // NewDAGGenerator returns an object capable of diff --git a/ipld/merkledag/test/utils.go b/ipld/merkledag/test/utils.go index 302d194d6..9cc2fb4cd 100644 --- a/ipld/merkledag/test/utils.go +++ b/ipld/merkledag/test/utils.go @@ -1,11 +1,10 @@ package mdutils import ( - dag "github.com/ipfs/boxo/ipld/merkledag" - bsrv "github.com/ipfs/boxo/blockservice" blockstore "github.com/ipfs/boxo/blockstore" offline "github.com/ipfs/boxo/exchange/offline" + dag "github.com/ipfs/boxo/ipld/merkledag" ds "github.com/ipfs/go-datastore" dssync "github.com/ipfs/go-datastore/sync" ipld "github.com/ipfs/go-ipld-format" diff --git a/ipld/merkledag/traverse/traverse_test.go b/ipld/merkledag/traverse/traverse_test.go index c19f1b054..41f4c7ad2 100644 --- a/ipld/merkledag/traverse/traverse_test.go +++ b/ipld/merkledag/traverse/traverse_test.go @@ -8,7 +8,6 @@ import ( mdag "github.com/ipfs/boxo/ipld/merkledag" mdagtest "github.com/ipfs/boxo/ipld/merkledag/test" - ipld "github.com/ipfs/go-ipld-format" ) diff --git a/ipld/unixfs/file/unixfile.go b/ipld/unixfs/file/unixfile.go index 0cf7616c1..0ffe346e3 100644 --- a/ipld/unixfs/file/unixfile.go +++ b/ipld/unixfs/file/unixfile.go @@ -6,11 +6,10 @@ import ( "os" "time" - ft "github.com/ipfs/boxo/ipld/unixfs" - uio "github.com/ipfs/boxo/ipld/unixfs/io" - "github.com/ipfs/boxo/files" dag "github.com/ipfs/boxo/ipld/merkledag" + ft "github.com/ipfs/boxo/ipld/unixfs" + uio "github.com/ipfs/boxo/ipld/unixfs/io" ipld "github.com/ipfs/go-ipld-format" ) diff --git a/ipld/unixfs/hamt/hamt_stress_test.go b/ipld/unixfs/hamt/hamt_stress_test.go index de8575d22..a9a5fed3e 100644 --- a/ipld/unixfs/hamt/hamt_stress_test.go +++ b/ipld/unixfs/hamt/hamt_stress_test.go @@ -10,7 +10,6 @@ import ( mdtest "github.com/ipfs/boxo/ipld/merkledag/test" ft "github.com/ipfs/boxo/ipld/unixfs" - ipld "github.com/ipfs/go-ipld-format" ) @@ -139,9 +138,9 @@ func executeOpSet(t *testing.T, ds ipld.DAGService, width int, ops []testOp) (*S } func genOpSet(seed int64, keep, temp []string) []testOp { - tempset := make(map[string]struct{}, len(temp)) + tempSet := make(map[string]struct{}, len(temp)) for _, s := range temp { - tempset[s] = struct{}{} + tempSet[s] = struct{}{} } allnames := append(keep, temp...) @@ -167,7 +166,7 @@ func genOpSet(seed int64, keep, temp []string) []testOp { Val: next, }) - if _, ok := tempset[next]; ok { + if _, ok := tempSet[next]; ok { todel = append(todel, next) } } else { diff --git a/ipld/unixfs/hamt/util.go b/ipld/unixfs/hamt/util.go index 66369b912..d8f0be544 100644 --- a/ipld/unixfs/hamt/util.go +++ b/ipld/unixfs/hamt/util.go @@ -5,7 +5,6 @@ import ( "math/bits" "github.com/ipfs/boxo/ipld/unixfs/internal" - "github.com/spaolacci/murmur3" ) diff --git a/ipld/unixfs/importer/balanced/balanced_test.go b/ipld/unixfs/importer/balanced/balanced_test.go index 4ea4cb8a9..c45e138d2 100644 --- a/ipld/unixfs/importer/balanced/balanced_test.go +++ b/ipld/unixfs/importer/balanced/balanced_test.go @@ -9,12 +9,11 @@ import ( "testing" "time" - h "github.com/ipfs/boxo/ipld/unixfs/importer/helpers" - uio "github.com/ipfs/boxo/ipld/unixfs/io" - chunker "github.com/ipfs/boxo/chunker" dag "github.com/ipfs/boxo/ipld/merkledag" mdtest "github.com/ipfs/boxo/ipld/merkledag/test" + h "github.com/ipfs/boxo/ipld/unixfs/importer/helpers" + uio "github.com/ipfs/boxo/ipld/unixfs/io" ipld "github.com/ipfs/go-ipld-format" "github.com/ipfs/go-test/random" ) @@ -361,7 +360,7 @@ func testMetadata(t *testing.T, buf *bytes.Buffer) { dbp := h.DagBuilderParams{ Dagserv: dagserv, Maxlinks: h.DefaultLinksPerBlock, - FileMode: 0522, + FileMode: 0o522, FileModTime: time.Unix(1638111600, 76552), } diff --git a/ipld/unixfs/importer/balanced/builder.go b/ipld/unixfs/importer/balanced/builder.go index 915d0a439..5d7ca6a3f 100644 --- a/ipld/unixfs/importer/balanced/builder.go +++ b/ipld/unixfs/importer/balanced/builder.go @@ -55,7 +55,6 @@ import ( ft "github.com/ipfs/boxo/ipld/unixfs" h "github.com/ipfs/boxo/ipld/unixfs/importer/helpers" - ipld "github.com/ipfs/go-ipld-format" ) diff --git a/ipld/unixfs/importer/helpers/dagbuilder.go b/ipld/unixfs/importer/helpers/dagbuilder.go index aefffad15..b295274b9 100644 --- a/ipld/unixfs/importer/helpers/dagbuilder.go +++ b/ipld/unixfs/importer/helpers/dagbuilder.go @@ -7,14 +7,12 @@ import ( "os" "time" - dag "github.com/ipfs/boxo/ipld/merkledag" - - ft "github.com/ipfs/boxo/ipld/unixfs" - pb "github.com/ipfs/boxo/ipld/unixfs/pb" - chunker "github.com/ipfs/boxo/chunker" "github.com/ipfs/boxo/files" pi "github.com/ipfs/boxo/filestore/posinfo" + dag "github.com/ipfs/boxo/ipld/merkledag" + ft "github.com/ipfs/boxo/ipld/unixfs" + pb "github.com/ipfs/boxo/ipld/unixfs/pb" cid "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" ) diff --git a/ipld/unixfs/importer/importer.go b/ipld/unixfs/importer/importer.go index 0903952c6..c5f1e0c81 100644 --- a/ipld/unixfs/importer/importer.go +++ b/ipld/unixfs/importer/importer.go @@ -3,11 +3,10 @@ package importer import ( + chunker "github.com/ipfs/boxo/chunker" bal "github.com/ipfs/boxo/ipld/unixfs/importer/balanced" h "github.com/ipfs/boxo/ipld/unixfs/importer/helpers" trickle "github.com/ipfs/boxo/ipld/unixfs/importer/trickle" - - chunker "github.com/ipfs/boxo/chunker" ipld "github.com/ipfs/go-ipld-format" ) diff --git a/ipld/unixfs/importer/importer_test.go b/ipld/unixfs/importer/importer_test.go index 1d20525ea..b14d67862 100644 --- a/ipld/unixfs/importer/importer_test.go +++ b/ipld/unixfs/importer/importer_test.go @@ -6,10 +6,9 @@ import ( "io" "testing" - uio "github.com/ipfs/boxo/ipld/unixfs/io" - chunker "github.com/ipfs/boxo/chunker" mdtest "github.com/ipfs/boxo/ipld/merkledag/test" + uio "github.com/ipfs/boxo/ipld/unixfs/io" cid "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" "github.com/ipfs/go-test/random" diff --git a/ipld/unixfs/importer/trickle/trickle_test.go b/ipld/unixfs/importer/trickle/trickle_test.go index d495fd208..18594c0c2 100644 --- a/ipld/unixfs/importer/trickle/trickle_test.go +++ b/ipld/unixfs/importer/trickle/trickle_test.go @@ -10,13 +10,12 @@ import ( "testing" "time" - ft "github.com/ipfs/boxo/ipld/unixfs" - h "github.com/ipfs/boxo/ipld/unixfs/importer/helpers" - uio "github.com/ipfs/boxo/ipld/unixfs/io" - chunker "github.com/ipfs/boxo/chunker" merkledag "github.com/ipfs/boxo/ipld/merkledag" mdtest "github.com/ipfs/boxo/ipld/merkledag/test" + ft "github.com/ipfs/boxo/ipld/unixfs" + h "github.com/ipfs/boxo/ipld/unixfs/importer/helpers" + uio "github.com/ipfs/boxo/ipld/unixfs/io" ipld "github.com/ipfs/go-ipld-format" "github.com/ipfs/go-test/random" ) @@ -709,7 +708,6 @@ func TestAppendWithModTime(t *testing.T) { if !fsn.ModTime().After(timestamp) { t.Errorf("expected modification time to be updated") } - } func TestAppendToEmptyWithModTime(t *testing.T) { @@ -760,7 +758,7 @@ func testMetadata(t *testing.T, rawLeaves UseRawLeaves) { Dagserv: dagserv, Maxlinks: h.DefaultLinksPerBlock, RawLeaves: bool(rawLeaves), - FileMode: 0522, + FileMode: 0o522, FileModTime: time.Unix(1638111600, 76552), } diff --git a/ipld/unixfs/importer/trickle/trickledag.go b/ipld/unixfs/importer/trickle/trickledag.go index 2b9d31dfa..67cf4b850 100644 --- a/ipld/unixfs/importer/trickle/trickledag.go +++ b/ipld/unixfs/importer/trickle/trickledag.go @@ -21,10 +21,9 @@ import ( "fmt" "time" + dag "github.com/ipfs/boxo/ipld/merkledag" ft "github.com/ipfs/boxo/ipld/unixfs" h "github.com/ipfs/boxo/ipld/unixfs/importer/helpers" - - dag "github.com/ipfs/boxo/ipld/merkledag" cid "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" ) diff --git a/ipld/unixfs/io/completehamt_test.go b/ipld/unixfs/io/completehamt_test.go index bc02c18db..77ad3fb7c 100644 --- a/ipld/unixfs/io/completehamt_test.go +++ b/ipld/unixfs/io/completehamt_test.go @@ -8,15 +8,12 @@ import ( "math" "testing" - "github.com/ipfs/boxo/ipld/unixfs/internal" - mdtest "github.com/ipfs/boxo/ipld/merkledag/test" - "github.com/stretchr/testify/assert" - "github.com/ipfs/boxo/ipld/unixfs" "github.com/ipfs/boxo/ipld/unixfs/hamt" - + "github.com/ipfs/boxo/ipld/unixfs/internal" ipld "github.com/ipfs/go-ipld-format" + "github.com/stretchr/testify/assert" ) // CreateCompleteHAMT creates a HAMT the following properties: diff --git a/ipld/unixfs/io/dagreader.go b/ipld/unixfs/io/dagreader.go index bb1c83800..72093edc8 100644 --- a/ipld/unixfs/io/dagreader.go +++ b/ipld/unixfs/io/dagreader.go @@ -286,7 +286,7 @@ func (dr *dagReader) writeNodeDataBuffer(w io.Writer) (int64, error) { // single node's data, not the entire DAG. } - dr.offset += int64(n) + dr.offset += n return n, nil } diff --git a/ipld/unixfs/io/dagreader_test.go b/ipld/unixfs/io/dagreader_test.go index 1f9f93558..374c54da3 100644 --- a/ipld/unixfs/io/dagreader_test.go +++ b/ipld/unixfs/io/dagreader_test.go @@ -2,15 +2,13 @@ package io import ( "bytes" + context "context" "io" "strings" "testing" mdag "github.com/ipfs/boxo/ipld/merkledag" "github.com/ipfs/boxo/ipld/unixfs" - - context "context" - testu "github.com/ipfs/boxo/ipld/unixfs/test" ) diff --git a/ipld/unixfs/io/directory.go b/ipld/unixfs/io/directory.go index ce6a6af9f..edac04b22 100644 --- a/ipld/unixfs/io/directory.go +++ b/ipld/unixfs/io/directory.go @@ -5,12 +5,11 @@ import ( "errors" "os" - "github.com/ipfs/boxo/ipld/unixfs/hamt" - "github.com/ipfs/boxo/ipld/unixfs/private/linksize" - "github.com/alecthomas/units" mdag "github.com/ipfs/boxo/ipld/merkledag" format "github.com/ipfs/boxo/ipld/unixfs" + "github.com/ipfs/boxo/ipld/unixfs/hamt" + "github.com/ipfs/boxo/ipld/unixfs/private/linksize" "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" logging "github.com/ipfs/go-log/v2" @@ -48,7 +47,7 @@ type Directory interface { ForEachLink(context.Context, func(*ipld.Link) error) error // EnumLinksAsync returns a channel which will receive Links in the directory - // as they are enumerated, where order is not gauranteed + // as they are enumerated, where order is not guaranteed EnumLinksAsync(context.Context) <-chan format.LinkResult // Links returns the all the links in the directory node. @@ -242,7 +241,7 @@ func (d *BasicDirectory) addLinkChild(ctx context.Context, name string, link *ip } // EnumLinksAsync returns a channel which will receive Links in the directory -// as they are enumerated, where order is not gauranteed +// as they are enumerated, where order is not guaranteed func (d *BasicDirectory) EnumLinksAsync(ctx context.Context) <-chan format.LinkResult { linkResults := make(chan format.LinkResult) go func() { @@ -368,7 +367,7 @@ func (d *HAMTDirectory) ForEachLink(ctx context.Context, f func(*ipld.Link) erro } // EnumLinksAsync returns a channel which will receive Links in the directory -// as they are enumerated, where order is not gauranteed +// as they are enumerated, where order is not guaranteed func (d *HAMTDirectory) EnumLinksAsync(ctx context.Context) <-chan format.LinkResult { return d.shard.EnumLinksAsync(ctx) } diff --git a/ipld/unixfs/io/directory_test.go b/ipld/unixfs/io/directory_test.go index 480aaa592..f69ad0b27 100644 --- a/ipld/unixfs/io/directory_test.go +++ b/ipld/unixfs/io/directory_test.go @@ -16,17 +16,15 @@ import ( offline "github.com/ipfs/boxo/exchange/offline" mdag "github.com/ipfs/boxo/ipld/merkledag" mdtest "github.com/ipfs/boxo/ipld/merkledag/test" + ft "github.com/ipfs/boxo/ipld/unixfs" + "github.com/ipfs/boxo/ipld/unixfs/hamt" + "github.com/ipfs/boxo/ipld/unixfs/internal" + "github.com/ipfs/boxo/ipld/unixfs/private/linksize" blocks "github.com/ipfs/go-block-format" cid "github.com/ipfs/go-cid" ds "github.com/ipfs/go-datastore" dssync "github.com/ipfs/go-datastore/sync" ipld "github.com/ipfs/go-ipld-format" - - ft "github.com/ipfs/boxo/ipld/unixfs" - "github.com/ipfs/boxo/ipld/unixfs/hamt" - "github.com/ipfs/boxo/ipld/unixfs/internal" - "github.com/ipfs/boxo/ipld/unixfs/private/linksize" - "github.com/stretchr/testify/assert" ) diff --git a/ipld/unixfs/io/resolve.go b/ipld/unixfs/io/resolve.go index 4b07d49e0..ef5134457 100644 --- a/ipld/unixfs/io/resolve.go +++ b/ipld/unixfs/io/resolve.go @@ -6,7 +6,6 @@ import ( dag "github.com/ipfs/boxo/ipld/merkledag" ft "github.com/ipfs/boxo/ipld/unixfs" hamt "github.com/ipfs/boxo/ipld/unixfs/hamt" - ipld "github.com/ipfs/go-ipld-format" ) diff --git a/ipld/unixfs/mod/dagmodifier.go b/ipld/unixfs/mod/dagmodifier.go index c075523f8..e3a5b7c60 100644 --- a/ipld/unixfs/mod/dagmodifier.go +++ b/ipld/unixfs/mod/dagmodifier.go @@ -9,13 +9,12 @@ import ( "io" "time" + chunker "github.com/ipfs/boxo/chunker" + mdag "github.com/ipfs/boxo/ipld/merkledag" ft "github.com/ipfs/boxo/ipld/unixfs" help "github.com/ipfs/boxo/ipld/unixfs/importer/helpers" trickle "github.com/ipfs/boxo/ipld/unixfs/importer/trickle" uio "github.com/ipfs/boxo/ipld/unixfs/io" - - chunker "github.com/ipfs/boxo/chunker" - mdag "github.com/ipfs/boxo/ipld/merkledag" cid "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" ) @@ -498,13 +497,13 @@ func (dm *DagModifier) Truncate(size int64) error { if err != nil { return err } - if size == int64(realSize) { + if size == realSize { return nil } // Truncate can also be used to expand the file - if size > int64(realSize) { - return dm.expandSparse(int64(size) - realSize) + if size > realSize { + return dm.expandSparse(size - realSize) } nnode, err := dm.dagTruncate(dm.ctx, dm.curNode, uint64(size)) diff --git a/ipld/unixfs/test/utils.go b/ipld/unixfs/test/utils.go index 465808ca2..34c53ac3d 100644 --- a/ipld/unixfs/test/utils.go +++ b/ipld/unixfs/test/utils.go @@ -7,13 +7,12 @@ import ( "io" "testing" - ft "github.com/ipfs/boxo/ipld/unixfs" - h "github.com/ipfs/boxo/ipld/unixfs/importer/helpers" - trickle "github.com/ipfs/boxo/ipld/unixfs/importer/trickle" - chunker "github.com/ipfs/boxo/chunker" mdag "github.com/ipfs/boxo/ipld/merkledag" mdagmock "github.com/ipfs/boxo/ipld/merkledag/test" + ft "github.com/ipfs/boxo/ipld/unixfs" + h "github.com/ipfs/boxo/ipld/unixfs/importer/helpers" + trickle "github.com/ipfs/boxo/ipld/unixfs/importer/trickle" cid "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" "github.com/ipfs/go-test/random" diff --git a/ipld/unixfs/unixfs.go b/ipld/unixfs/unixfs.go index fb2c9bbf2..92c7671ce 100644 --- a/ipld/unixfs/unixfs.go +++ b/ipld/unixfs/unixfs.go @@ -111,7 +111,7 @@ func FolderPBDataWithStat(mode os.FileMode, mtime time.Time) []byte { data, err := proto.Marshal(pbfile) if err != nil { - //this really shouldnt happen, i promise + // this really shouldnt happen, i promise panic(err) } return data diff --git a/ipld/unixfs/unixfs_test.go b/ipld/unixfs/unixfs_test.go index 4cbc22ca8..2b5af0bfe 100644 --- a/ipld/unixfs/unixfs_test.go +++ b/ipld/unixfs/unixfs_test.go @@ -7,7 +7,6 @@ import ( "time" proto "github.com/gogo/protobuf/proto" - pb "github.com/ipfs/boxo/ipld/unixfs/pb" ) @@ -220,7 +219,7 @@ func TestMode(t *testing.T) { t.Fatal("expected mode not to be set") } - fileMode := os.FileMode(0640) + fileMode := os.FileMode(0o640) fsn.SetMode(fileMode) if !fsn.Mode().IsRegular() { t.Fatal("expected a regular file mode") @@ -283,7 +282,7 @@ func TestMode(t *testing.T) { fsn.SetMode(fileMode | os.ModeSetuid | os.ModeSticky) pbn := fsn.getPbData(t) // unix perms setuid and sticky bits should also be set - expected := uint32(05000 | (fileMode & os.ModePerm)) + expected := uint32(0o5000 | (fileMode & os.ModePerm)) if *pbn.Mode != expected { t.Fatalf("expected stored permissions to be %O but got %O", expected, *pbn.Mode) } @@ -305,7 +304,7 @@ func TestMode(t *testing.T) { func TestExtendedMode(t *testing.T) { fsn := NewFSNode(TFile) fsn.SetMode(os.ModePerm | os.ModeSetuid | os.ModeSticky) - const expectedUnixMode = uint32(05777) + const expectedUnixMode = uint32(0o5777) expectedExtMode := uint32(0xAAAAA) fsn.SetExtendedMode(expectedExtMode) diff --git a/ipns/record_test.go b/ipns/record_test.go index 6ab1d5994..edf1db062 100644 --- a/ipns/record_test.go +++ b/ipns/record_test.go @@ -18,9 +18,7 @@ import ( "google.golang.org/protobuf/proto" ) -var ( - testPath path.Path -) +var testPath path.Path func init() { var err error diff --git a/mfs/dir.go b/mfs/dir.go index 5eed9426b..506d9f7ee 100644 --- a/mfs/dir.go +++ b/mfs/dir.go @@ -12,7 +12,6 @@ import ( dag "github.com/ipfs/boxo/ipld/merkledag" ft "github.com/ipfs/boxo/ipld/unixfs" uio "github.com/ipfs/boxo/ipld/unixfs/io" - cid "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" ) diff --git a/mfs/fd.go b/mfs/fd.go index 705e0e5ec..d7b68c90b 100644 --- a/mfs/fd.go +++ b/mfs/fd.go @@ -1,14 +1,12 @@ package mfs import ( + context "context" "errors" "fmt" "io" mod "github.com/ipfs/boxo/ipld/unixfs/mod" - - context "context" - ipld "github.com/ipfs/go-ipld-format" ) @@ -109,7 +107,7 @@ func (fi *fileDescriptor) CtxReadFull(ctx context.Context, b []byte) (int, error return fi.mod.CtxReadFull(ctx, b) } -// Close flushes, then propogates the modified dag node up the directory structure +// Close flushes, then propagates the modified dag node up the directory structure // and signals a republish to occur func (fi *fileDescriptor) Close() error { if fi.state == stateClosed { diff --git a/mfs/file.go b/mfs/file.go index 700244321..648f7681c 100644 --- a/mfs/file.go +++ b/mfs/file.go @@ -7,11 +7,10 @@ import ( "sync" "time" + chunker "github.com/ipfs/boxo/chunker" dag "github.com/ipfs/boxo/ipld/merkledag" ft "github.com/ipfs/boxo/ipld/unixfs" mod "github.com/ipfs/boxo/ipld/unixfs/mod" - - chunker "github.com/ipfs/boxo/chunker" ipld "github.com/ipfs/go-ipld-format" ) diff --git a/mfs/mfs_test.go b/mfs/mfs_test.go index cf56f9d73..8a3a7f1b4 100644 --- a/mfs/mfs_test.go +++ b/mfs/mfs_test.go @@ -26,12 +26,11 @@ import ( ft "github.com/ipfs/boxo/ipld/unixfs" importer "github.com/ipfs/boxo/ipld/unixfs/importer" uio "github.com/ipfs/boxo/ipld/unixfs/io" - "github.com/ipfs/go-test/random" - cid "github.com/ipfs/go-cid" ds "github.com/ipfs/go-datastore" dssync "github.com/ipfs/go-datastore/sync" ipld "github.com/ipfs/go-ipld-format" + "github.com/ipfs/go-test/random" ) func emptyDirNode() *dag.ProtoNode { @@ -669,8 +668,8 @@ func TestMfsModeAndModTime(t *testing.T) { ts, _ := time.Now(), time.Time{} // can set mode - if err = fi.SetMode(0644); err == nil { - if mode, err = fi.Mode(); mode != 0644 { + if err = fi.SetMode(0o644); err == nil { + if mode, err = fi.Mode(); mode != 0o644 { t.Fatal("failed to get correct mode of file") } } @@ -832,7 +831,7 @@ func TestMfsRawNodeSetModeAndMtime(t *testing.T) { } // Set and check mode. - err = fi.SetMode(0644) + err = fi.SetMode(0o644) if err != nil { t.Fatalf("failed to set file mode: %s", err) } @@ -840,7 +839,7 @@ func TestMfsRawNodeSetModeAndMtime(t *testing.T) { if err != nil { t.Fatalf("failed to check file mode: %s", err) } - if mode != 0644 { + if mode != 0o644 { t.Fatal("failed to get correct mode of file, got", mode.String()) } @@ -1807,7 +1806,7 @@ func FuzzMkdirAndWriteConcurrently(f *testing.F) { _, err = wfd.Write(filecontent) if err != nil { - t.Logf("error writting to file from filepath %s: %s", filepath, err) + t.Logf("error writing to file from filepath %s: %s", filepath, err) } }) } diff --git a/mfs/repub.go b/mfs/repub.go index 0ad0d33a2..61ef356e3 100644 --- a/mfs/repub.go +++ b/mfs/repub.go @@ -76,7 +76,7 @@ func (rp *Republisher) Close() error { // Shutdown the publisher. rp.cancel() }) - // Wait for pblisher to stop and then return. + // Wait for publisher to stop and then return. <-rp.stopped return err } diff --git a/mfs/root.go b/mfs/root.go index e332f2da3..c8d307b2d 100644 --- a/mfs/root.go +++ b/mfs/root.go @@ -12,7 +12,6 @@ import ( dag "github.com/ipfs/boxo/ipld/merkledag" ft "github.com/ipfs/boxo/ipld/unixfs" - ipld "github.com/ipfs/go-ipld-format" logging "github.com/ipfs/go-log/v2" ) diff --git a/namesys/ipns_publisher_test.go b/namesys/ipns_publisher_test.go index a783ddd61..ecdd4aaeb 100644 --- a/namesys/ipns_publisher_test.go +++ b/namesys/ipns_publisher_test.go @@ -6,17 +6,16 @@ import ( "testing" "time" - "github.com/ipfs/boxo/path" - "github.com/stretchr/testify/require" - dshelp "github.com/ipfs/boxo/datastore/dshelp" "github.com/ipfs/boxo/ipns" + "github.com/ipfs/boxo/path" mockrouting "github.com/ipfs/boxo/routing/mock" ds "github.com/ipfs/go-datastore" dssync "github.com/ipfs/go-datastore/sync" testutil "github.com/libp2p/go-libp2p-testing/net" ci "github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/peer" + "github.com/stretchr/testify/require" ) func TestIPNSPublisher(t *testing.T) { diff --git a/namesys/ipns_resolver.go b/namesys/ipns_resolver.go index 5efcf8785..c566aac93 100644 --- a/namesys/ipns_resolver.go +++ b/namesys/ipns_resolver.go @@ -7,7 +7,6 @@ import ( "github.com/ipfs/boxo/ipns" "github.com/ipfs/boxo/path" - dht "github.com/libp2p/go-libp2p-kad-dht" "github.com/libp2p/go-libp2p/core/routing" "go.opentelemetry.io/otel/attribute" diff --git a/namesys/republisher/repub.go b/namesys/republisher/repub.go index 71aeb4af9..9808c9401 100644 --- a/namesys/republisher/repub.go +++ b/namesys/republisher/repub.go @@ -7,17 +7,16 @@ import ( "errors" "time" + "github.com/ipfs/boxo/ipns" "github.com/ipfs/boxo/keystore" "github.com/ipfs/boxo/namesys" - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/trace" - - "github.com/ipfs/boxo/ipns" ds "github.com/ipfs/go-datastore" logging "github.com/ipfs/go-log/v2" ic "github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/peer" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) var ( diff --git a/namesys/republisher/repub_test.go b/namesys/republisher/repub_test.go index db42b02a9..ee7fa6110 100644 --- a/namesys/republisher/repub_test.go +++ b/namesys/republisher/repub_test.go @@ -6,6 +6,13 @@ import ( "testing" "time" + "github.com/ipfs/boxo/ipns" + "github.com/ipfs/boxo/keystore" + "github.com/ipfs/boxo/namesys" + . "github.com/ipfs/boxo/namesys/republisher" + "github.com/ipfs/boxo/path" + ds "github.com/ipfs/go-datastore" + dssync "github.com/ipfs/go-datastore/sync" "github.com/libp2p/go-libp2p" dht "github.com/libp2p/go-libp2p-kad-dht" ic "github.com/libp2p/go-libp2p/core/crypto" @@ -13,15 +20,6 @@ import ( "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/routing" "github.com/stretchr/testify/require" - - "github.com/ipfs/boxo/ipns" - "github.com/ipfs/boxo/path" - ds "github.com/ipfs/go-datastore" - dssync "github.com/ipfs/go-datastore/sync" - - "github.com/ipfs/boxo/keystore" - "github.com/ipfs/boxo/namesys" - . "github.com/ipfs/boxo/namesys/republisher" ) type mockNode struct { diff --git a/path/resolver/resolver.go b/path/resolver/resolver.go index 1746cbe63..655c08638 100644 --- a/path/resolver/resolver.go +++ b/path/resolver/resolver.go @@ -6,10 +6,6 @@ import ( "fmt" "time" - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/trace" - "github.com/ipfs/boxo/fetcher" fetcherhelpers "github.com/ipfs/boxo/fetcher/helpers" "github.com/ipfs/boxo/path" @@ -20,6 +16,9 @@ import ( basicnode "github.com/ipld/go-ipld-prime/node/basic" "github.com/ipld/go-ipld-prime/schema" "github.com/ipld/go-ipld-prime/traversal/selector/builder" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) var log = logging.Logger("path/resolver") diff --git a/path/resolver/resolver_test.go b/path/resolver/resolver_test.go index 91f05e7d6..782709ddc 100644 --- a/path/resolver/resolver_test.go +++ b/path/resolver/resolver_test.go @@ -9,22 +9,21 @@ import ( "time" bsfetcher "github.com/ipfs/boxo/fetcher/impl/blockservice" + merkledag "github.com/ipfs/boxo/ipld/merkledag" + dagmock "github.com/ipfs/boxo/ipld/merkledag/test" + "github.com/ipfs/boxo/path" + "github.com/ipfs/boxo/path/resolver" blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-cid" + "github.com/ipfs/go-unixfsnode" dagpb "github.com/ipld/go-codec-dagpb" "github.com/ipld/go-ipld-prime" + dagcbor "github.com/ipld/go-ipld-prime/codec/dagcbor" + dagjson "github.com/ipld/go-ipld-prime/codec/dagjson" cidlink "github.com/ipld/go-ipld-prime/linking/cid" basicnode "github.com/ipld/go-ipld-prime/node/basic" "github.com/ipld/go-ipld-prime/schema" "github.com/multiformats/go-multihash" - - merkledag "github.com/ipfs/boxo/ipld/merkledag" - dagmock "github.com/ipfs/boxo/ipld/merkledag/test" - "github.com/ipfs/boxo/path" - "github.com/ipfs/boxo/path/resolver" - "github.com/ipfs/go-unixfsnode" - dagcbor "github.com/ipld/go-ipld-prime/codec/dagcbor" - dagjson "github.com/ipld/go-ipld-prime/codec/dagjson" "github.com/stretchr/testify/require" ) diff --git a/peering/peering_test.go b/peering/peering_test.go index 3d146e3e3..df40e1be7 100644 --- a/peering/peering_test.go +++ b/peering/peering_test.go @@ -10,7 +10,6 @@ import ( "github.com/libp2p/go-libp2p/core/network" "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/p2p/net/connmgr" - "github.com/stretchr/testify/require" ) diff --git a/pinning/pinner/dspinner/pin.go b/pinning/pinner/dspinner/pin.go index ddc93c2c5..4cc5e38e7 100644 --- a/pinning/pinner/dspinner/pin.go +++ b/pinning/pinner/dspinner/pin.go @@ -10,6 +10,10 @@ import ( "path" "sync" + "github.com/ipfs/boxo/ipld/merkledag" + "github.com/ipfs/boxo/ipld/merkledag/dagutils" + ipfspinner "github.com/ipfs/boxo/pinning/pinner" + "github.com/ipfs/boxo/pinning/pinner/dsindex" "github.com/ipfs/go-cid" ds "github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore/query" @@ -17,11 +21,6 @@ import ( logging "github.com/ipfs/go-log/v2" "github.com/polydawn/refmt/cbor" "github.com/polydawn/refmt/obj/atlas" - - "github.com/ipfs/boxo/ipld/merkledag" - "github.com/ipfs/boxo/ipld/merkledag/dagutils" - ipfspinner "github.com/ipfs/boxo/pinning/pinner" - "github.com/ipfs/boxo/pinning/pinner/dsindex" ) const ( diff --git a/pinning/pinner/dspinner/pin_test.go b/pinning/pinner/dspinner/pin_test.go index 153a3bc16..1b9c1fe0e 100644 --- a/pinning/pinner/dspinner/pin_test.go +++ b/pinning/pinner/dspinner/pin_test.go @@ -9,21 +9,18 @@ import ( "time" bs "github.com/ipfs/boxo/blockservice" + blockstore "github.com/ipfs/boxo/blockstore" + offline "github.com/ipfs/boxo/exchange/offline" mdag "github.com/ipfs/boxo/ipld/merkledag" - "github.com/stretchr/testify/require" - + ipfspin "github.com/ipfs/boxo/pinning/pinner" cid "github.com/ipfs/go-cid" ds "github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore/query" dssync "github.com/ipfs/go-datastore/sync" ipld "github.com/ipfs/go-ipld-format" logging "github.com/ipfs/go-log/v2" - - blockstore "github.com/ipfs/boxo/blockstore" - offline "github.com/ipfs/boxo/exchange/offline" "github.com/ipfs/go-test/random" - - ipfspin "github.com/ipfs/boxo/pinning/pinner" + "github.com/stretchr/testify/require" ) type fakeLogger struct { diff --git a/provider/reprovider.go b/provider/reprovider.go index 048a2067d..2959b64b8 100644 --- a/provider/reprovider.go +++ b/provider/reprovider.go @@ -355,7 +355,7 @@ func (s *reprovider) run() { recentAvgProvideDuration := dur / time.Duration(len(keys)) s.statLk.Lock() - s.avgProvideDuration = time.Duration((totalProvideTime + dur) / (time.Duration(s.totalProvides) + time.Duration(len(keys)))) + s.avgProvideDuration = (totalProvideTime + dur) / (time.Duration(s.totalProvides) + time.Duration(len(keys))) s.totalProvides += uint64(len(keys)) log.Debugf("finished providing of %d keys. It took %v with an average of %v per provide", len(keys), dur, recentAvgProvideDuration) diff --git a/routing/http/client/client.go b/routing/http/client/client.go index ca9841946..0dedff1de 100644 --- a/routing/http/client/client.go +++ b/routing/http/client/client.go @@ -55,6 +55,7 @@ type Client struct { // Called immediately after signing a provide request. It is used // for testing, e.g., testing the server with a mangled signature. + //nolint:staticcheck //lint:ignore SA1019 // ignore staticcheck afterSignCallback func(req *types.WriteBitswapRecord) @@ -353,8 +354,10 @@ func (c *Client) ProvideBitswap(ctx context.Context, keys []cid.Cid, ttl time.Du // ProvideAsync makes a provide request to a delegated router // +//nolint:staticcheck //lint:ignore SA1019 // ignore staticcheck func (c *Client) provideSignedBitswapRecord(ctx context.Context, bswp *types.WriteBitswapRecord) (time.Duration, error) { + //nolint:staticcheck //lint:ignore SA1019 // ignore staticcheck req := jsontypes.WriteProvidersRequest{Providers: []types.Record{bswp}} diff --git a/routing/http/client/client_test.go b/routing/http/client/client_test.go index 639da5418..689e3b91c 100644 --- a/routing/http/client/client_test.go +++ b/routing/http/client/client_test.go @@ -18,7 +18,6 @@ import ( "github.com/ipfs/boxo/routing/http/types" "github.com/ipfs/boxo/routing/http/types/iter" "github.com/ipfs/go-cid" - "github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/peer" "github.com/multiformats/go-multiaddr" @@ -36,6 +35,7 @@ func (m *mockContentRouter) FindProviders(ctx context.Context, key cid.Cid, limi return args.Get(0).(iter.ResultIter[types.Record]), args.Error(1) } +//nolint:staticcheck //lint:ignore SA1019 // ignore staticcheck func (m *mockContentRouter) ProvideBitswap(ctx context.Context, req *server.BitswapWriteProvideRequest) (time.Duration, error) { args := m.Called(ctx, req) @@ -170,6 +170,7 @@ func makePeerRecord(protocols []string) types.PeerRecord { } } +//nolint:staticcheck //lint:ignore SA1019 // ignore staticcheck func makeBitswapRecord() types.BitswapRecord { peerID, addrs, _ := makeProviderAndIdentity() @@ -312,7 +313,7 @@ func TestClient_FindProviders(t *testing.T) { }, }, { - name: "returns no providers if the HTTP server returns a 404 respones", + name: "returns no providers if the HTTP server returns a 404 response", httpStatusCode: 404, expResult: nil, }, @@ -471,6 +472,7 @@ func TestClient_Provide(t *testing.T) { deps.server.Close() } if c.mangleSignature { + //nolint:staticcheck //lint:ignore SA1019 // ignore staticcheck client.afterSignCallback = func(req *types.WriteBitswapRecord) { mh, err := multihash.Encode([]byte("boom"), multihash.SHA2_256) @@ -482,6 +484,7 @@ func TestClient_Provide(t *testing.T) { } } + //nolint:staticcheck //lint:ignore SA1019 // ignore staticcheck expectedProvReq := &server.BitswapWriteProvideRequest{ Keys: c.cids, @@ -597,7 +600,7 @@ func TestClient_FindPeers(t *testing.T) { }, }, { - name: "returns no providers if the HTTP server returns a 404 respones", + name: "returns no providers if the HTTP server returns a 404 response", httpStatusCode: 404, expResult: nil, }, diff --git a/routing/http/contentrouter/contentrouter.go b/routing/http/contentrouter/contentrouter.go index 11496b0bd..8a8cfb8ae 100644 --- a/routing/http/contentrouter/contentrouter.go +++ b/routing/http/contentrouter/contentrouter.go @@ -37,11 +37,13 @@ type contentRouter struct { maxProvideBatchSize int } -var _ routing.ContentRouting = (*contentRouter)(nil) -var _ routing.PeerRouting = (*contentRouter)(nil) -var _ routing.ValueStore = (*contentRouter)(nil) -var _ routinghelpers.ProvideManyRouter = (*contentRouter)(nil) -var _ routinghelpers.ReadyAbleRouter = (*contentRouter)(nil) +var ( + _ routing.ContentRouting = (*contentRouter)(nil) + _ routing.PeerRouting = (*contentRouter)(nil) + _ routing.ValueStore = (*contentRouter)(nil) + _ routinghelpers.ProvideManyRouter = (*contentRouter)(nil) + _ routinghelpers.ReadyAbleRouter = (*contentRouter)(nil) +) type option func(c *contentRouter) @@ -145,9 +147,11 @@ func readProviderResponses(ctx context.Context, iter iter.ResultIter[types.Recor return case ch <- peer.AddrInfo{ ID: *result.ID, - Addrs: addrs}: + Addrs: addrs, + }: } + //nolint:staticcheck //lint:ignore SA1019 // ignore staticcheck case types.SchemaBitswap: //lint:ignore SA1019 // ignore staticcheck @@ -171,7 +175,8 @@ func readProviderResponses(ctx context.Context, iter iter.ResultIter[types.Recor return case ch <- peer.AddrInfo{ ID: *result.ID, - Addrs: addrs}: + Addrs: addrs, + }: } } } diff --git a/routing/http/contentrouter/contentrouter_test.go b/routing/http/contentrouter/contentrouter_test.go index 63072ca54..839293617 100644 --- a/routing/http/contentrouter/contentrouter_test.go +++ b/routing/http/contentrouter/contentrouter_test.go @@ -136,6 +136,7 @@ func TestFindProvidersAsync(t *testing.T) { ID: &p1, Protocols: []string{"transport-bitswap"}, }, + //nolint:staticcheck //lint:ignore SA1019 // ignore staticcheck &types.BitswapRecord{ //lint:ignore SA1019 // ignore staticcheck diff --git a/routing/http/filters/filters.go b/routing/http/filters/filters.go index c88bbcf41..9af7bf8b9 100644 --- a/routing/http/filters/filters.go +++ b/routing/http/filters/filters.go @@ -79,6 +79,7 @@ func ApplyFiltersToIter(recordsIter iter.ResultIter[types.Record], filterAddrs, } v.Val = record + //nolint:staticcheck //lint:ignore SA1019 // ignore staticcheck case types.SchemaBitswap: //lint:ignore SA1019 // ignore staticcheck @@ -244,7 +245,6 @@ func protocolsAllowed(peerProtocols []string, filterProtocols []string) bool { if strings.EqualFold(peerProtocol, filterProtocol) { return true } - } } return false diff --git a/routing/http/server/server.go b/routing/http/server/server.go index c951701c3..3252f798f 100644 --- a/routing/http/server/server.go +++ b/routing/http/server/server.go @@ -22,13 +22,12 @@ import ( "github.com/ipfs/boxo/routing/http/types/iter" jsontypes "github.com/ipfs/boxo/routing/http/types/json" "github.com/ipfs/go-cid" + logging "github.com/ipfs/go-log/v2" "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/routing" "github.com/multiformats/go-multiaddr" "github.com/multiformats/go-multibase" "github.com/prometheus/client_golang/prometheus" - - logging "github.com/ipfs/go-log/v2" metrics "github.com/slok/go-http-metrics/metrics/prometheus" "github.com/slok/go-http-metrics/middleware" middlewarestd "github.com/slok/go-http-metrics/middleware/std" @@ -300,6 +299,7 @@ func (s *server) findProvidersJSON(w http.ResponseWriter, provIter iter.ResultIt Providers: providers, }) } + func (s *server) findProvidersNDJSON(w http.ResponseWriter, provIter iter.ResultIter[types.Record], filterAddrs, filterProtocols []string) { filteredIter := filters.ApplyFiltersToIter(provIter, filterAddrs, filterProtocols) @@ -318,7 +318,6 @@ func (s *server) findPeers(w http.ResponseWriter, r *http.Request) { // Attempt to parse PeerID pid, err := peer.Decode(pidStr) - if err != nil { // Retry by parsing PeerID as CID, then setting codec to libp2p-key // and turning that back to PeerID. @@ -380,6 +379,7 @@ func (s *server) findPeers(w http.ResponseWriter, r *http.Request) { } func (s *server) provide(w http.ResponseWriter, httpReq *http.Request) { + //nolint:staticcheck //lint:ignore SA1019 // ignore staticcheck req := jsontypes.WriteProvidersRequest{} err := json.NewDecoder(httpReq.Body).Decode(&req) @@ -389,11 +389,13 @@ func (s *server) provide(w http.ResponseWriter, httpReq *http.Request) { return } + //nolint:staticcheck //lint:ignore SA1019 // ignore staticcheck resp := jsontypes.WriteProvidersResponse{} for i, prov := range req.Providers { switch v := prov.(type) { + //nolint:staticcheck //lint:ignore SA1019 // ignore staticcheck case *types.WriteBitswapRecord: err := v.Verify() @@ -444,7 +446,6 @@ func (s *server) findPeersJSON(w http.ResponseWriter, peersIter iter.ResultIter[ peersIter = filters.ApplyFiltersToPeerRecordIter(peersIter, filterAddrs, filterProtocols) peers, err := iter.ReadAllResults(peersIter) - if err != nil { writeErr(w, "FindPeers", http.StatusInternalServerError, fmt.Errorf("delegate error: %w", err)) return diff --git a/routing/http/server/server_test.go b/routing/http/server/server_test.go index bf84e4155..d5b8a7102 100644 --- a/routing/http/server/server_test.go +++ b/routing/http/server/server_test.go @@ -39,8 +39,8 @@ func TestHeaders(t *testing.T) { {Val: &types.PeerRecord{ Schema: types.SchemaPeer, Protocols: []string{"transport-bitswap"}, - }}}, - ) + }}, + }) c := "baeabep4vu3ceru7nerjjbk37sxb7wmftteve4hcosmyolsbsiubw2vr6pqzj6mw7kv6tbn6nqkkldnklbjgm5tzbi4hkpkled4xlcr7xz4bq" cb, err := cid.Decode(c) @@ -320,7 +320,6 @@ func TestPeers(t *testing.T) { // Expect response to default to application/json require.Equal(t, 404, resp.StatusCode) require.Equal(t, mediaTypeJSON, resp.Header.Get("Content-Type")) - }) t.Run("GET /routing/v1/peers/{cid-libp2p-key-peer-id} returns 404 with correct body and headers (No Results, implicit JSON, no Accept header)", func(t *testing.T) { @@ -637,7 +636,6 @@ func TestPeers(t *testing.T) { require.Equal(t, expectedBody, string(body)) }) } - } func makeName(t *testing.T) (crypto.PrivKey, ipns.Name) { diff --git a/routing/http/types/iter/json.go b/routing/http/types/iter/json.go index 428331e28..4967fe7f7 100644 --- a/routing/http/types/iter/json.go +++ b/routing/http/types/iter/json.go @@ -12,7 +12,7 @@ func FromReaderJSON[T any](r io.Reader) *JSONIter[T] { } // JSONIter iterates over whitespace-delimited JSON values of a byte stream. -// This closes the reader if it is a closer, to faciliate easy reading of HTTP responses. +// This closes the reader if it is a closer, to facilitate easy reading of HTTP responses. type JSONIter[T any] struct { Decoder *json.Decoder Reader io.Reader diff --git a/routing/http/types/json/requests.go b/routing/http/types/json/requests.go index 4b582c3ba..c0bbfafdf 100644 --- a/routing/http/types/json/requests.go +++ b/routing/http/types/json/requests.go @@ -29,8 +29,10 @@ func (r *WriteProvidersRequest) UnmarshalJSON(b []byte) error { } switch rawProv.Schema { + //nolint:staticcheck //lint:ignore SA1019 // ignore staticcheck case types.SchemaBitswap: + //nolint:staticcheck //lint:ignore SA1019 // ignore staticcheck var prov types.WriteBitswapRecord err := json.Unmarshal(rawProv.Bytes, &prov) diff --git a/routing/http/types/json/responses.go b/routing/http/types/json/responses.go index d8f659ac5..7ce92965b 100644 --- a/routing/http/types/json/responses.go +++ b/routing/http/types/json/responses.go @@ -49,8 +49,10 @@ func (r *RecordsArray) UnmarshalJSON(b []byte) error { return err } *r = append(*r, &prov) + //nolint:staticcheck //lint:ignore SA1019 // ignore staticcheck case types.SchemaBitswap: + //nolint:staticcheck //lint:ignore SA1019 // ignore staticcheck var prov types.BitswapRecord err := json.Unmarshal(provBytes, &prov) @@ -92,8 +94,10 @@ func (r *WriteProvidersResponse) UnmarshalJSON(b []byte) error { } switch rawProv.Schema { + //nolint:staticcheck //lint:ignore SA1019 // ignore staticcheck case types.SchemaBitswap: + //nolint:staticcheck //lint:ignore SA1019 // ignore staticcheck var prov types.WriteBitswapRecordResponse err := json.Unmarshal(rawProv.Bytes, &prov) diff --git a/routing/http/types/ndjson/records.go b/routing/http/types/ndjson/records.go index 819cd521d..4363e82ab 100644 --- a/routing/http/types/ndjson/records.go +++ b/routing/http/types/ndjson/records.go @@ -26,6 +26,7 @@ func NewRecordsIter(r io.Reader) iter.Iter[iter.Result[types.Record]] { return result } result.Val = &prov + //nolint:staticcheck //lint:ignore SA1019 // ignore staticcheck case types.SchemaBitswap: //lint:ignore SA1019 // ignore staticcheck diff --git a/routing/http/types/record_bitswap.go b/routing/http/types/record_bitswap.go index 0780fc3eb..bf749e515 100644 --- a/routing/http/types/record_bitswap.go +++ b/routing/http/types/record_bitswap.go @@ -17,9 +17,7 @@ import ( // [IPIP-417]: https://github.com/ipfs/specs/pull/417 const SchemaBitswap = "bitswap" -var ( - _ Record = &BitswapRecord{} -) +var _ Record = &BitswapRecord{} // Deprecated: use the more versatile [PeerRecord] instead. For more information, read [IPIP-417]. // diff --git a/routing/offline/offline_test.go b/routing/offline/offline_test.go index 9a17e8689..10ee155ed 100644 --- a/routing/offline/offline_test.go +++ b/routing/offline/offline_test.go @@ -7,10 +7,8 @@ import ( cid "github.com/ipfs/go-cid" ds "github.com/ipfs/go-datastore" - "github.com/libp2p/go-libp2p/core/routing" "github.com/libp2p/go-libp2p/core/test" - mh "github.com/multiformats/go-multihash" ) diff --git a/tar/extractor_test.go b/tar/extractor_test.go index 7e31fbea5..fa855ec7e 100644 --- a/tar/extractor_test.go +++ b/tar/extractor_test.go @@ -68,7 +68,7 @@ func TestSingleFile(t *testing.T) { func TestSingleFileWithMeta(t *testing.T) { fileName := "file2..ext" fileData := "file2 data" - mode := 0654 + mode := 0o654 mtime := time.Now().Round(time.Second) testTarExtraction(t, nil, []tarEntry{ @@ -111,7 +111,7 @@ func TestSingleDirectory(t *testing.T) { func TestSingleDirectoryWithMeta(t *testing.T) { dirName := "dir2..sfx" - mode := 0765 + mode := 0o765 mtime := time.Now().Round(time.Second) testTarExtraction(t, nil, []tarEntry{ @@ -300,13 +300,19 @@ func TestFilesAndFoldersWithMetadata(t *testing.T) { entries := []tarEntry{ &dirTarEntry{path: "root", mtime: tm.Add(5 * time.Second)}, - &dirTarEntry{path: "root/childdir", mode: 03775}, - &fileTarEntry{path: "root/childdir/file1", buf: []byte("some data"), mode: 04744, - mtime: tm.Add(10 * time.Second)}, - &fileTarEntry{path: "root/childdir/file2", buf: []byte("some data"), mode: 0560, - mtime: tm.Add(10 * time.Second)}, - &fileTarEntry{path: "root/childdir/file3", buf: []byte("some data"), mode: 06540, - mtime: tm.Add(10 * time.Second)}, + &dirTarEntry{path: "root/childdir", mode: 0o3775}, + &fileTarEntry{ + path: "root/childdir/file1", buf: []byte("some data"), mode: 0o4744, + mtime: tm.Add(10 * time.Second), + }, + &fileTarEntry{ + path: "root/childdir/file2", buf: []byte("some data"), mode: 0o560, + mtime: tm.Add(10 * time.Second), + }, + &fileTarEntry{ + path: "root/childdir/file3", buf: []byte("some data"), mode: 0o6540, + mtime: tm.Add(10 * time.Second), + }, } testTarExtraction(t, nil, entries, func(t *testing.T, extractDir string) { @@ -321,36 +327,36 @@ func TestFilesAndFoldersWithMetadata(t *testing.T) { assert.Equal(t, tm.Add(5*time.Second), fi.ModTime()) case 1: // childdir if runtime.GOOS != "windows" { - assert.Equal(t, 0775, int(fi.Mode()&0xFFF)) + assert.Equal(t, 0o775, int(fi.Mode()&0xFFF)) assert.Equal(t, os.ModeSetgid, fi.Mode()&os.ModeSetgid) assert.Equal(t, os.ModeSticky, fi.Mode()&os.ModeSticky) } else { - assert.Equal(t, 0777, int(fi.Mode()&0xFFF)) + assert.Equal(t, 0o777, int(fi.Mode()&0xFFF)) } case 2: // file1 assert.Equal(t, tm.Add(10*time.Second), fi.ModTime()) if runtime.GOOS != "windows" { - assert.Equal(t, 0744, int(fi.Mode()&0xFFF)) + assert.Equal(t, 0o744, int(fi.Mode()&0xFFF)) assert.Equal(t, os.ModeSetuid, fi.Mode()&os.ModeSetuid) } else { - assert.Equal(t, 0666, int(fi.Mode()&0xFFF)) + assert.Equal(t, 0o666, int(fi.Mode()&0xFFF)) } case 3: // file2 assert.Equal(t, tm.Add(10*time.Second), fi.ModTime()) if runtime.GOOS != "windows" { - assert.Equal(t, 0560, int(fi.Mode()&0xFFF)) + assert.Equal(t, 0o560, int(fi.Mode()&0xFFF)) assert.Equal(t, 0, int(fi.Mode()&os.ModeSetuid)) } else { - assert.Equal(t, 0666, int(fi.Mode()&0xFFF)) + assert.Equal(t, 0o666, int(fi.Mode()&0xFFF)) } case 4: // file3 assert.Equal(t, tm.Add(10*time.Second), fi.ModTime()) if runtime.GOOS != "windows" { - assert.Equal(t, 0540, int(fi.Mode()&0xFFF)) + assert.Equal(t, 0o540, int(fi.Mode()&0xFFF)) assert.Equal(t, os.ModeSetgid, fi.Mode()&os.ModeSetgid) assert.Equal(t, os.ModeSetuid, fi.Mode()&os.ModeSetuid) } else { - assert.Equal(t, 0444, int(fi.Mode()&0xFFF)) + assert.Equal(t, 0o444, int(fi.Mode()&0xFFF)) } default: assert.Fail(t, "has more than 5 entries", path) @@ -415,7 +421,7 @@ func TestDeferredUpdate(t *testing.T) { entries := []tarEntry{ &dirTarEntry{path: "root", mtime: add5()}, &dirTarEntry{path: "root/a", mtime: add5()}, - &dirTarEntry{path: "root/a/beta", mtime: add5(), mode: 0500}, + &dirTarEntry{path: "root/a/beta", mtime: add5(), mode: 0o500}, &dirTarEntry{path: "root/a/beta/centauri", mtime: add5()}, &dirTarEntry{path: "root/a/beta/lima", mtime: add5()}, &dirTarEntry{path: "root/a/beta/papa", mtime: add5()}, @@ -440,7 +446,6 @@ func TestDeferredUpdate(t *testing.T) { assert.NoError(t, err) }, nil) - } func TestInternalSymlinkTraverse(t *testing.T) { @@ -555,11 +560,11 @@ func testMeta(t *testing.T, path string, mode int, now time.Time) { m := files.ModePermsToUnixPerms(fi.Mode()) if runtime.GOOS == "windows" { if fi.IsDir() { - mode = 0777 - } else if mode&0220 != 0 { - mode = 0666 - } else if mode&0440 != 0 { - mode = 0444 + mode = 0o777 + } else if mode&0o220 != 0 { + mode = 0o666 + } else if mode&0o440 != 0 { + mode = 0o444 } } assert.Equal(t, mode, int(m)) diff --git a/verifcid/allowlist_test.go b/verifcid/allowlist_test.go index ab8c415e1..b6057502f 100644 --- a/verifcid/allowlist_test.go +++ b/verifcid/allowlist_test.go @@ -3,9 +3,8 @@ package verifcid import ( "testing" - mh "github.com/multiformats/go-multihash" - "github.com/ipfs/go-cid" + mh "github.com/multiformats/go-multihash" ) func TestDefaultAllowList(t *testing.T) {