Skip to content

Commit c5a805e

Browse files
committed
style: run gofumpt
1 parent aa73ad5 commit c5a805e

File tree

135 files changed

+522
-336
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+522
-336
lines changed

bitswap/benchmarks_test.go

+25-23
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func BenchmarkFixedDelay(b *testing.B) {
114114
}
115115

116116
out, _ := json.MarshalIndent(benchmarkLog, "", " ")
117-
_ = os.WriteFile("tmp/benchmark.json", out, 0666)
117+
_ = os.WriteFile("tmp/benchmark.json", out, 0o666)
118118
printResults(benchmarkLog)
119119
}
120120

@@ -182,28 +182,30 @@ func BenchmarkFetchFromOldBitswap(b *testing.B) {
182182
}
183183

184184
out, _ := json.MarshalIndent(benchmarkLog, "", " ")
185-
_ = os.WriteFile("tmp/benchmark.json", out, 0666)
185+
_ = os.WriteFile("tmp/benchmark.json", out, 0o666)
186186
printResults(benchmarkLog)
187187
}
188188

189-
const datacenterSpeed = 5 * time.Millisecond
190-
const fastSpeed = 60 * time.Millisecond
191-
const mediumSpeed = 200 * time.Millisecond
192-
const slowSpeed = 800 * time.Millisecond
193-
const superSlowSpeed = 4000 * time.Millisecond
194-
const datacenterDistribution = 3 * time.Millisecond
195-
const distribution = 20 * time.Millisecond
196-
const datacenterBandwidth = 125000000.0
197-
const datacenterBandwidthDeviation = 3000000.0
198-
const fastBandwidth = 1250000.0
199-
const fastBandwidthDeviation = 300000.0
200-
const mediumBandwidth = 500000.0
201-
const mediumBandwidthDeviation = 80000.0
202-
const slowBandwidth = 100000.0
203-
const slowBandwidthDeviation = 16500.0
204-
const rootBlockSize = 800
205-
const stdBlockSize = 8000
206-
const largeBlockSize = int64(256 * 1024)
189+
const (
190+
datacenterSpeed = 5 * time.Millisecond
191+
fastSpeed = 60 * time.Millisecond
192+
mediumSpeed = 200 * time.Millisecond
193+
slowSpeed = 800 * time.Millisecond
194+
superSlowSpeed = 4000 * time.Millisecond
195+
datacenterDistribution = 3 * time.Millisecond
196+
distribution = 20 * time.Millisecond
197+
datacenterBandwidth = 125000000.0
198+
datacenterBandwidthDeviation = 3000000.0
199+
fastBandwidth = 1250000.0
200+
fastBandwidthDeviation = 300000.0
201+
mediumBandwidth = 500000.0
202+
mediumBandwidthDeviation = 80000.0
203+
slowBandwidth = 100000.0
204+
slowBandwidthDeviation = 16500.0
205+
rootBlockSize = 800
206+
stdBlockSize = 8000
207+
largeBlockSize = int64(256 * 1024)
208+
)
207209

208210
func BenchmarkRealWorld(b *testing.B) {
209211
benchmarkLog = nil
@@ -240,7 +242,7 @@ func BenchmarkRealWorld(b *testing.B) {
240242
subtestDistributeAndFetchRateLimited(b, 300, 200, slowNetworkDelay, slowBandwidthGenerator, stdBlockSize, bstoreLatency, allToAll, batchFetchAll)
241243
})
242244
out, _ := json.MarshalIndent(benchmarkLog, "", " ")
243-
_ = os.WriteFile("tmp/rw-benchmark.json", out, 0666)
245+
_ = os.WriteFile("tmp/rw-benchmark.json", out, 0o666)
244246
printResults(benchmarkLog)
245247
}
246248

@@ -263,7 +265,7 @@ func BenchmarkDatacenter(b *testing.B) {
263265
subtestDistributeAndFetchRateLimited(b, 3, 100, datacenterNetworkDelay, datacenterBandwidthGenerator, largeBlockSize, bstoreLatency, allToAll, unixfsFileFetch)
264266
})
265267
out, _ := json.MarshalIndent(benchmarkLog, "", " ")
266-
_ = os.WriteFile("tmp/rb-benchmark.json", out, 0666)
268+
_ = os.WriteFile("tmp/rb-benchmark.json", out, 0o666)
267269
printResults(benchmarkLog)
268270
}
269271

@@ -304,7 +306,7 @@ func BenchmarkDatacenterMultiLeechMultiSeed(b *testing.B) {
304306
})
305307

306308
out, _ := json.MarshalIndent(benchmarkLog, "", " ")
307-
_ = os.WriteFile("tmp/rb-benchmark.json", out, 0666)
309+
_ = os.WriteFile("tmp/rb-benchmark.json", out, 0o666)
308310
printResults(benchmarkLog)
309311
}
310312

bitswap/bitswap.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ type bitswap interface {
4444
WantlistForPeer(p peer.ID) []cid.Cid
4545
}
4646

47-
var _ exchange.SessionExchange = (*Bitswap)(nil)
48-
var _ bitswap = (*Bitswap)(nil)
49-
var HasBlockBufferSize = defaults.HasBlockBufferSize
47+
var (
48+
_ exchange.SessionExchange = (*Bitswap)(nil)
49+
_ bitswap = (*Bitswap)(nil)
50+
HasBlockBufferSize = defaults.HasBlockBufferSize
51+
)
5052

5153
type Bitswap struct {
5254
*client.Client

bitswap/bitswap_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,6 @@ func TestSendToWantingPeer(t *testing.T) {
390390
if !blkrecvd.Cid().Equals(alpha.Cid()) {
391391
t.Fatal("Wrong block!")
392392
}
393-
394393
}
395394

396395
func TestEmptyKey(t *testing.T) {
@@ -828,6 +827,7 @@ func (tsl *testingScoreLedger) Start(scorePeer server.ScorePeerFunc) {
828827
tsl.scorePeer = scorePeer
829828
close(tsl.started)
830829
}
830+
831831
func (tsl *testingScoreLedger) Stop() {
832832
close(tsl.closed)
833833
}

bitswap/client/client.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ func New(parent context.Context, network bsnet.BitSwapNetwork, bstore blockstore
132132
notif notifications.PubSub,
133133
provSearchDelay time.Duration,
134134
rebroadcastDelay delay.D,
135-
self peer.ID) bssm.Session {
135+
self peer.ID,
136+
) bssm.Session {
136137
return bssession.New(sessctx, sessmgr, id, spm, pqm, sim, pm, bpm, notif, provSearchDelay, rebroadcastDelay, self)
137138
}
138139
sessionPeerManagerFactory := func(ctx context.Context, id uint64) bssession.SessionPeerManager {

bitswap/client/internal/getter/getter.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ type WantFunc func(context.Context, []cid.Cid)
6868
// blocks, a want function, and a close function, and returns a channel of
6969
// incoming blocks.
7070
func AsyncGetBlocks(ctx context.Context, sessctx context.Context, keys []cid.Cid, notif notifications.PubSub,
71-
want WantFunc, cwants func([]cid.Cid)) (<-chan blocks.Block, error) {
71+
want WantFunc, cwants func([]cid.Cid),
72+
) (<-chan blocks.Block, error) {
7273
ctx, span := internal.StartSpan(ctx, "Getter.AsyncGetBlocks")
7374
defer span.End()
7475

@@ -99,8 +100,8 @@ func AsyncGetBlocks(ctx context.Context, sessctx context.Context, keys []cid.Cid
99100
// If the context is cancelled or the incoming channel closes, calls cfun with
100101
// any keys corresponding to blocks that were never received.
101102
func handleIncoming(ctx context.Context, sessctx context.Context, remaining *cid.Set,
102-
in <-chan blocks.Block, out chan blocks.Block, cfun func([]cid.Cid)) {
103-
103+
in <-chan blocks.Block, out chan blocks.Block, cfun func([]cid.Cid),
104+
) {
104105
ctx, cancel := context.WithCancel(ctx)
105106

106107
// Clean up before exiting this function, and call the cancel function on

bitswap/client/internal/messagequeue/donthavetimeoutmgr.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ func newDontHaveTimeoutMgrWithParams(
107107
messageLatencyMultiplier int,
108108
maxExpectedWantProcessTime time.Duration,
109109
clock clock.Clock,
110-
timeoutsTriggered chan struct{}) *dontHaveTimeoutMgr {
111-
110+
timeoutsTriggered chan struct{},
111+
) *dontHaveTimeoutMgr {
112112
ctx, shutdown := context.WithCancel(context.Background())
113113
mqp := &dontHaveTimeoutMgr{
114114
clock: clock,
@@ -222,7 +222,6 @@ func (dhtm *dontHaveTimeoutMgr) measurePingLatency() {
222222
// checkForTimeouts checks pending wants to see if any are over the timeout.
223223
// Note: this function should only be called within the lock.
224224
func (dhtm *dontHaveTimeoutMgr) checkForTimeouts() {
225-
226225
if len(dhtm.wantQueue) == 0 {
227226
return
228227
}

bitswap/client/internal/messagequeue/messagequeue.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ import (
1818
"go.uber.org/zap"
1919
)
2020

21-
var log = logging.Logger("bitswap")
22-
var sflog = log.Desugar()
21+
var (
22+
log = logging.Logger("bitswap")
23+
sflog = log.Desugar()
24+
)
2325

2426
const (
2527
defaultRebroadcastInterval = 30 * time.Second
@@ -240,8 +242,8 @@ func newMessageQueue(
240242
maxValidLatency time.Duration,
241243
dhTimeoutMgr DontHaveTimeoutManager,
242244
clock clock.Clock,
243-
events chan messageEvent) *MessageQueue {
244-
245+
events chan messageEvent,
246+
) *MessageQueue {
245247
ctx, cancel := context.WithCancel(ctx)
246248
return &MessageQueue{
247249
ctx: ctx,

bitswap/client/internal/messagequeue/messagequeue_test.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func (fp *fakeDontHaveTimeoutMgr) AddPending(ks []cid.Cid) {
6161
}
6262
fp.ks = s.Keys()
6363
}
64+
6465
func (fp *fakeDontHaveTimeoutMgr) CancelPending(ks []cid.Cid) {
6566
fp.lk.Lock()
6667
defer fp.lk.Unlock()
@@ -74,18 +75,21 @@ func (fp *fakeDontHaveTimeoutMgr) CancelPending(ks []cid.Cid) {
7475
}
7576
fp.ks = s.Keys()
7677
}
78+
7779
func (fp *fakeDontHaveTimeoutMgr) UpdateMessageLatency(elapsed time.Duration) {
7880
fp.lk.Lock()
7981
defer fp.lk.Unlock()
8082

8183
fp.latencyUpds = append(fp.latencyUpds, elapsed)
8284
}
85+
8386
func (fp *fakeDontHaveTimeoutMgr) latencyUpdates() []time.Duration {
8487
fp.lk.Lock()
8588
defer fp.lk.Unlock()
8689

8790
return fp.latencyUpds
8891
}
92+
8993
func (fp *fakeDontHaveTimeoutMgr) pendingCount() int {
9094
fp.lk.Lock()
9195
defer fp.lk.Unlock()
@@ -101,8 +105,8 @@ type fakeMessageSender struct {
101105
}
102106

103107
func newFakeMessageSender(reset chan<- struct{},
104-
messagesSent chan<- []bsmsg.Entry, supportsHave bool) *fakeMessageSender {
105-
108+
messagesSent chan<- []bsmsg.Entry, supportsHave bool,
109+
) *fakeMessageSender {
106110
return &fakeMessageSender{
107111
reset: reset,
108112
messagesSent: messagesSent,
@@ -126,7 +130,8 @@ func mockTimeoutCb(peer.ID, []cid.Cid) {}
126130
func collectMessages(ctx context.Context,
127131
t *testing.T,
128132
messagesSent <-chan []bsmsg.Entry,
129-
timeout time.Duration) [][]bsmsg.Entry {
133+
timeout time.Duration,
134+
) [][]bsmsg.Entry {
130135
var messagesReceived [][]bsmsg.Entry
131136
timeoutctx, cancel := context.WithTimeout(ctx, timeout)
132137
defer cancel()

bitswap/client/internal/notifications/notifications.go

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ func (ps *impl) Shutdown() {
6868
// is closed if the |ctx| times out or is cancelled, or after receiving the blocks
6969
// corresponding to |keys|.
7070
func (ps *impl) Subscribe(ctx context.Context, keys ...cid.Cid) <-chan blocks.Block {
71-
7271
blocksCh := make(chan blocks.Block, len(keys))
7372
valuesCh := make(chan interface{}, len(keys)) // provide our own channel to control buffer, prevent blocking
7473
if len(keys) == 0 {

bitswap/client/internal/notifications/notifications_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ func TestPublishSubscribe(t *testing.T) {
5858
}
5959

6060
assertBlocksEqual(t, blockRecvd, blockSent)
61-
6261
}
6362

6463
func TestSubscribeMany(t *testing.T) {

bitswap/client/internal/peermanager/peermanager_test.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ func (fp *mockPeerQueue) Shutdown() {}
3030
func (fp *mockPeerQueue) AddBroadcastWantHaves(whs []cid.Cid) {
3131
fp.msgs <- msg{fp.p, nil, whs, nil}
3232
}
33+
3334
func (fp *mockPeerQueue) AddWants(wbs []cid.Cid, whs []cid.Cid) {
3435
fp.msgs <- msg{fp.p, wbs, whs, nil}
3536
}
37+
3638
func (fp *mockPeerQueue) AddCancels(cs []cid.Cid) {
3739
fp.msgs <- msg{fp.p, nil, nil, cs}
3840
}
41+
3942
func (fp *mockPeerQueue) ResponseReceived(ks []cid.Cid) {
4043
}
4144

@@ -271,6 +274,7 @@ func TestSendCancels(t *testing.T) {
271274
func (s *sess) ID() uint64 {
272275
return s.id
273276
}
277+
274278
func (s *sess) SignalAvailability(p peer.ID, isAvailable bool) {
275279
s.available[p] = isAvailable
276280
}
@@ -332,8 +336,7 @@ func TestSessionRegistration(t *testing.T) {
332336
}
333337
}
334338

335-
type benchPeerQueue struct {
336-
}
339+
type benchPeerQueue struct{}
337340

338341
func (*benchPeerQueue) Startup() {}
339342
func (*benchPeerQueue) Shutdown() {}

bitswap/client/internal/peermanager/peerwantmanager_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type gauge struct {
1616
func (g *gauge) Inc() {
1717
g.count++
1818
}
19+
1920
func (g *gauge) Dec() {
2021
g.count--
2122
}
@@ -40,13 +41,16 @@ func (mpq *mockPQ) Shutdown() {}
4041
func (mpq *mockPQ) AddBroadcastWantHaves(whs []cid.Cid) {
4142
mpq.bcst = append(mpq.bcst, whs...)
4243
}
44+
4345
func (mpq *mockPQ) AddWants(wbs []cid.Cid, whs []cid.Cid) {
4446
mpq.wbs = append(mpq.wbs, wbs...)
4547
mpq.whs = append(mpq.whs, whs...)
4648
}
49+
4750
func (mpq *mockPQ) AddCancels(cs []cid.Cid) {
4851
mpq.cancels = append(mpq.cancels, cs...)
4952
}
53+
5054
func (mpq *mockPQ) ResponseReceived(ks []cid.Cid) {
5155
}
5256

bitswap/client/internal/providerquerymanager/providerquerymanager_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ func TestNormalSimultaneousFetch(t *testing.T) {
9595
if fpn.queriesMade != 2 {
9696
t.Fatal("Did not dedup provider requests running simultaneously")
9797
}
98-
9998
}
10099

101100
func TestDedupingProviderRequests(t *testing.T) {
@@ -256,7 +255,6 @@ func TestPeersWithConnectionErrorsNotAddedToPeerList(t *testing.T) {
256255
if len(firstPeersReceived) != 0 || len(secondPeersReceived) != 0 {
257256
t.Fatal("Did not filter out peers with connection issues")
258257
}
259-
260258
}
261259

262260
func TestRateLimitingRequests(t *testing.T) {

bitswap/client/internal/session/session.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ import (
1818
"go.uber.org/zap"
1919
)
2020

21-
var log = logging.Logger("bs:sess")
22-
var sflog = log.Desugar()
21+
var (
22+
log = logging.Logger("bs:sess")
23+
sflog = log.Desugar()
24+
)
2325

2426
const (
2527
broadcastLiveWantsLimit = 64
@@ -146,8 +148,8 @@ func New(
146148
notif notifications.PubSub,
147149
initialSearchDelay time.Duration,
148150
periodicSearchDelay delay.D,
149-
self peer.ID) *Session {
150-
151+
self peer.ID,
152+
) *Session {
151153
ctx, cancel := context.WithCancel(ctx)
152154
s := &Session{
153155
sw: newSessionWants(broadcastLiveWantsLimit),

bitswap/client/internal/session/session_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ func TestSessionGetBlocks(t *testing.T) {
170170
}
171171

172172
_, err := session.GetBlocks(ctx, cids)
173-
174173
if err != nil {
175174
t.Fatal("error getting blocks")
176175
}
@@ -344,7 +343,6 @@ func TestSessionOnPeersExhausted(t *testing.T) {
344343
cids = append(cids, block.Cid())
345344
}
346345
_, err := session.GetBlocks(ctx, cids)
347-
348346
if err != nil {
349347
t.Fatal("error getting blocks")
350348
}

bitswap/client/internal/session/sessionwantsender.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ type change struct {
6767
availability peerAvailability
6868
}
6969

70-
type onSendFn func(to peer.ID, wantBlocks []cid.Cid, wantHaves []cid.Cid)
71-
type onPeersExhaustedFn func([]cid.Cid)
70+
type (
71+
onSendFn func(to peer.ID, wantBlocks []cid.Cid, wantHaves []cid.Cid)
72+
onPeersExhaustedFn func([]cid.Cid)
73+
)
7274

7375
// sessionWantSender is responsible for sending want-have and want-block to
7476
// peers. For each want, it sends a single optimistic want-block request to
@@ -111,8 +113,8 @@ type sessionWantSender struct {
111113
}
112114

113115
func newSessionWantSender(sid uint64, pm PeerManager, spm SessionPeerManager, canceller SessionWantsCanceller,
114-
bpm *bsbpm.BlockPresenceManager, onSend onSendFn, onPeersExhausted onPeersExhaustedFn) sessionWantSender {
115-
116+
bpm *bsbpm.BlockPresenceManager, onSend onSendFn, onPeersExhausted onPeersExhaustedFn,
117+
) sessionWantSender {
116118
ctx, cancel := context.WithCancel(context.Background())
117119
sws := sessionWantSender{
118120
ctx: ctx,

0 commit comments

Comments
 (0)