Skip to content

Commit 6b5fcf1

Browse files
committed
refactor: change naming to reflect blocks -> keys
This commit was moved from ipfs/go-bitswap@693e97d
1 parent 561ffe9 commit 6b5fcf1

File tree

5 files changed

+30
-30
lines changed

5 files changed

+30
-30
lines changed

bitswap/bitswap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ func (bs *Bitswap) receiveBlocksFrom(from peer.ID, blks []blocks.Block) error {
330330

331331
// Send all block keys (including duplicates) to any sessions that want them.
332332
// (The duplicates are needed by sessions for accounting purposes)
333-
bs.sm.ReceiveBlocksFrom(from, allKs)
333+
bs.sm.ReceiveFrom(from, allKs)
334334

335335
// Send wanted block keys to decision engine
336336
bs.engine.AddBlocks(wantedKs)

bitswap/session/session.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ type interestReq struct {
5252
resp chan bool
5353
}
5454

55-
type blksRecv struct {
55+
type rcvFrom struct {
5656
from peer.ID
57-
ks []cid.Cid
57+
ks []cid.Cid
5858
}
5959

6060
// Session holds state for an individual bitswap transfer operation.
@@ -68,7 +68,7 @@ type Session struct {
6868
srs RequestSplitter
6969

7070
// channels
71-
incoming chan blksRecv
71+
incoming chan rcvFrom
7272
newReqs chan []cid.Cid
7373
cancelKeys chan []cid.Cid
7474
interestReqs chan interestReq
@@ -117,7 +117,7 @@ func New(ctx context.Context,
117117
wm: wm,
118118
pm: pm,
119119
srs: srs,
120-
incoming: make(chan blksRecv),
120+
incoming: make(chan rcvFrom),
121121
notif: notif,
122122
uuid: loggables.Uuid("GetBlockRequest"),
123123
baseTickDelay: time.Millisecond * 500,
@@ -134,10 +134,10 @@ func New(ctx context.Context,
134134
return s
135135
}
136136

137-
// ReceiveBlocksFrom receives incoming blocks from the given peer.
138-
func (s *Session) ReceiveBlocksFrom(from peer.ID, ks []cid.Cid) {
137+
// ReceiveFrom receives incoming blocks from the given peer.
138+
func (s *Session) ReceiveFrom(from peer.ID, ks []cid.Cid) {
139139
select {
140-
case s.incoming <- blksRecv{from: from, ks: ks}:
140+
case s.incoming <- rcvFrom{from: from, ks: ks}:
141141
case <-s.ctx.Done():
142142
}
143143
}
@@ -232,13 +232,13 @@ func (s *Session) run(ctx context.Context) {
232232
for {
233233
select {
234234
case rcv := <-s.incoming:
235-
s.cancelIncomingBlocks(ctx, rcv)
235+
s.cancelIncoming(ctx, rcv)
236236
// Record statistics only if the blocks came from the network
237237
// (blocks can also be received from the local node)
238238
if rcv.from != "" {
239239
s.updateReceiveCounters(ctx, rcv)
240240
}
241-
s.handleIncomingBlocks(ctx, rcv)
241+
s.handleIncoming(ctx, rcv)
242242
case keys := <-s.newReqs:
243243
s.handleNewRequest(ctx, keys)
244244
case keys := <-s.cancelKeys:
@@ -260,7 +260,7 @@ func (s *Session) run(ctx context.Context) {
260260
}
261261
}
262262

263-
func (s *Session) cancelIncomingBlocks(ctx context.Context, rcv blksRecv) {
263+
func (s *Session) cancelIncoming(ctx context.Context, rcv rcvFrom) {
264264
// We've received the blocks so we can cancel any outstanding wants for them
265265
wanted := make([]cid.Cid, 0, len(rcv.ks))
266266
for _, k := range rcv.ks {
@@ -272,11 +272,11 @@ func (s *Session) cancelIncomingBlocks(ctx context.Context, rcv blksRecv) {
272272
s.wm.CancelWants(s.ctx, wanted, nil, s.id)
273273
}
274274

275-
func (s *Session) handleIncomingBlocks(ctx context.Context, rcv blksRecv) {
275+
func (s *Session) handleIncoming(ctx context.Context, rcv rcvFrom) {
276276
s.idleTick.Stop()
277277

278278
// Process the received blocks
279-
s.receiveBlocks(ctx, rcv.ks)
279+
s.processIncoming(ctx, rcv.ks)
280280

281281
s.resetIdleTick()
282282
}
@@ -376,7 +376,7 @@ func (s *Session) cidIsWanted(c cid.Cid) bool {
376376
return ok
377377
}
378378

379-
func (s *Session) receiveBlocks(ctx context.Context, ks []cid.Cid) {
379+
func (s *Session) processIncoming(ctx context.Context, ks []cid.Cid) {
380380
for _, c := range ks {
381381
if s.cidIsWanted(c) {
382382
// If the block CID was in the live wants queue, remove it
@@ -414,7 +414,7 @@ func (s *Session) receiveBlocks(ctx context.Context, ks []cid.Cid) {
414414
}
415415
}
416416

417-
func (s *Session) updateReceiveCounters(ctx context.Context, rcv blksRecv) {
417+
func (s *Session) updateReceiveCounters(ctx context.Context, rcv rcvFrom) {
418418
for _, k := range rcv.ks {
419419
// Inform the request splitter of unique / duplicate blocks
420420
if s.cidIsWanted(k) {

bitswap/session/session_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ func TestSessionGetBlocks(t *testing.T) {
126126
var receivedBlocks []blocks.Block
127127
for i, p := range peers {
128128
// simulate what bitswap does on receiving a message:
129-
// - calls ReceiveBlocksFrom() on session
129+
// - calls ReceiveFrom() on session
130130
// - publishes block to pubsub channel
131131
blk := blks[testutil.IndexOf(blks, receivedWantReq.cids[i])]
132-
session.ReceiveBlocksFrom(p, []cid.Cid{blk.Cid()})
132+
session.ReceiveFrom(p, []cid.Cid{blk.Cid()})
133133
notif.Publish(blk)
134134

135135
select {
@@ -188,10 +188,10 @@ func TestSessionGetBlocks(t *testing.T) {
188188
// receive remaining blocks
189189
for i, p := range peers {
190190
// simulate what bitswap does on receiving a message:
191-
// - calls ReceiveBlocksFrom() on session
191+
// - calls ReceiveFrom() on session
192192
// - publishes block to pubsub channel
193193
blk := blks[testutil.IndexOf(blks, newCidsRequested[i])]
194-
session.ReceiveBlocksFrom(p, []cid.Cid{blk.Cid()})
194+
session.ReceiveFrom(p, []cid.Cid{blk.Cid()})
195195
notif.Publish(blk)
196196

197197
receivedBlock := <-getBlocksCh
@@ -252,10 +252,10 @@ func TestSessionFindMorePeers(t *testing.T) {
252252
p := testutil.GeneratePeers(1)[0]
253253

254254
// simulate what bitswap does on receiving a message:
255-
// - calls ReceiveBlocksFrom() on session
255+
// - calls ReceiveFrom() on session
256256
// - publishes block to pubsub channel
257257
blk := blks[0]
258-
session.ReceiveBlocksFrom(p, []cid.Cid{blk.Cid()})
258+
session.ReceiveFrom(p, []cid.Cid{blk.Cid()})
259259
notif.Publish(blk)
260260
select {
261261
case <-cancelReqs:

bitswap/sessionmanager/sessionmanager.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
type Session interface {
1919
exchange.Fetcher
2020
InterestedIn(cid.Cid) bool
21-
ReceiveBlocksFrom(peer.ID, []cid.Cid)
21+
ReceiveFrom(peer.ID, []cid.Cid)
2222
}
2323

2424
type sesTrk struct {
@@ -114,9 +114,9 @@ func (sm *SessionManager) GetNextSessionID() uint64 {
114114
return sm.sessID
115115
}
116116

117-
// ReceiveBlocksFrom receives blocks from a peer and dispatches to interested
117+
// ReceiveFrom receives blocks from a peer and dispatches to interested
118118
// sessions.
119-
func (sm *SessionManager) ReceiveBlocksFrom(from peer.ID, ks []cid.Cid) {
119+
func (sm *SessionManager) ReceiveFrom(from peer.ID, ks []cid.Cid) {
120120
sm.sessLk.Lock()
121121
defer sm.sessLk.Unlock()
122122

@@ -128,6 +128,6 @@ func (sm *SessionManager) ReceiveBlocksFrom(from peer.ID, ks []cid.Cid) {
128128
sessKs = append(sessKs, k)
129129
}
130130
}
131-
s.session.ReceiveBlocksFrom(from, sessKs)
131+
s.session.ReceiveFrom(from, sessKs)
132132
}
133133
}

bitswap/sessionmanager/sessionmanager_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (fs *fakeSession) InterestedIn(c cid.Cid) bool {
4040
}
4141
return false
4242
}
43-
func (fs *fakeSession) ReceiveBlocksFrom(p peer.ID, ks []cid.Cid) {
43+
func (fs *fakeSession) ReceiveFrom(p peer.ID, ks []cid.Cid) {
4444
fs.ks = append(fs.ks, ks...)
4545
}
4646

@@ -137,7 +137,7 @@ func TestAddingSessions(t *testing.T) {
137137
thirdSession.id != secondSession.id+2 {
138138
t.Fatal("session does not have correct id set")
139139
}
140-
sm.ReceiveBlocksFrom(p, []cid.Cid{block.Cid()})
140+
sm.ReceiveFrom(p, []cid.Cid{block.Cid()})
141141
if len(firstSession.ks) == 0 ||
142142
len(secondSession.ks) == 0 ||
143143
len(thirdSession.ks) == 0 {
@@ -167,7 +167,7 @@ func TestReceivingBlocksWhenNotInterested(t *testing.T) {
167167
nextInterestedIn = []cid.Cid{}
168168
thirdSession := sm.NewSession(ctx, time.Second, delay.Fixed(time.Minute)).(*fakeSession)
169169

170-
sm.ReceiveBlocksFrom(p, []cid.Cid{blks[0].Cid(), blks[1].Cid()})
170+
sm.ReceiveFrom(p, []cid.Cid{blks[0].Cid(), blks[1].Cid()})
171171

172172
if !cmpSessionCids(firstSession, []cid.Cid{cids[0], cids[1]}) ||
173173
!cmpSessionCids(secondSession, []cid.Cid{cids[0]}) ||
@@ -194,7 +194,7 @@ func TestRemovingPeersWhenManagerContextCancelled(t *testing.T) {
194194
cancel()
195195
// wait for sessions to get removed
196196
time.Sleep(10 * time.Millisecond)
197-
sm.ReceiveBlocksFrom(p, []cid.Cid{block.Cid()})
197+
sm.ReceiveFrom(p, []cid.Cid{block.Cid()})
198198
if len(firstSession.ks) > 0 ||
199199
len(secondSession.ks) > 0 ||
200200
len(thirdSession.ks) > 0 {
@@ -222,7 +222,7 @@ func TestRemovingPeersWhenSessionContextCancelled(t *testing.T) {
222222
sessionCancel()
223223
// wait for sessions to get removed
224224
time.Sleep(10 * time.Millisecond)
225-
sm.ReceiveBlocksFrom(p, []cid.Cid{block.Cid()})
225+
sm.ReceiveFrom(p, []cid.Cid{block.Cid()})
226226
if len(firstSession.ks) == 0 ||
227227
len(secondSession.ks) > 0 ||
228228
len(thirdSession.ks) == 0 {

0 commit comments

Comments
 (0)