Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: cleanup code by golangci-lint #797

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions bitswap/bitswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
3 changes: 1 addition & 2 deletions bitswap/client/internal/getter/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 1 addition & 2 deletions bitswap/client/internal/peermanager/peermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
1 change: 0 additions & 1 deletion bitswap/client/internal/peermanager/peerwantmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion bitswap/client/internal/session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}:
Expand Down Expand Up @@ -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")
Expand Down
1 change: 0 additions & 1 deletion bitswap/client/internal/session/sessionwantsender.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"sync"

blocks "github.com/ipfs/go-block-format"

cid "github.com/ipfs/go-cid"
)

Expand Down
9 changes: 4 additions & 5 deletions bitswap/client/internal/sessionmanager/sessionmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"sync"

logging "github.com/ipfs/go-log/v2"

peer "github.com/libp2p/go-libp2p/core/peer"
)

Expand Down
1 change: 0 additions & 1 deletion bitswap/client/wantlist/wantlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"slices"

pb "github.com/ipfs/boxo/bitswap/message/pb"

cid "github.com/ipfs/go-cid"
)

Expand Down
8 changes: 3 additions & 5 deletions bitswap/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions bitswap/message/pb/cid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions bitswap/network/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion bitswap/network/ipfs_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions bitswap/server/internal/decision/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
9 changes: 3 additions & 6 deletions bitswap/server/internal/decision/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion bitswap/server/internal/decision/peer_ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
4 changes: 2 additions & 2 deletions bitswap/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion bitswap/testnet/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 0 additions & 2 deletions bitswap/testnet/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
1 change: 0 additions & 1 deletion bitswap/testnet/peernet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 4 additions & 6 deletions blockservice/blockservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@ 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"
blocks "github.com/ipfs/go-block-format"
"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")
Expand Down Expand Up @@ -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)
}

Expand Down
1 change: 0 additions & 1 deletion blockservice/test/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions blockstore/blockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion blockstore/caching.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion bootstrap/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ func TestNoTempPeersLoadAndSave(t *testing.T) {

time.Sleep(4 * period)
bootstrapper.Close()

}

func assertPanics(t *testing.T, name string, f func()) {
Expand Down
5 changes: 2 additions & 3 deletions fetcher/impl/blockservice/fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)
Expand Down
1 change: 0 additions & 1 deletion fetcher/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading
Loading