Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Bitswap Refactor #3: Extract sessions to package #30

Merged
merged 2 commits into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

const activeWantsLimit = 16

// SessionWantmanager is an interface that can be used to request blocks
// SessionWantManager is an interface that can be used to request blocks
// from given peers.
type SessionWantManager interface {
WantBlocks(ctx context.Context, ks []cid.Cid, peers []peer.ID, ses uint64)
Expand Down
16 changes: 6 additions & 10 deletions sessionmanager/sessionmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,12 @@ func (sm *SessionManager) NewSession(ctx context.Context) exchange.Fetcher {
sm.sessions = append(sm.sessions, session)
sm.sessLk.Unlock()
go func() {
for {
defer cancel()
select {
case <-sm.ctx.Done():
sm.removeSession(session)
return
case <-ctx.Done():
sm.removeSession(session)
return
}
defer cancel()
select {
case <-sm.ctx.Done():
sm.removeSession(session)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: duplicate code. We can replace this with:

defer cancel()
select {
case <-sm.ctx.Done():
case <-ctx.Done():
}
sm.removeSession(session)

case <-ctx.Done():
sm.removeSession(session)
}
}()

Expand Down