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

Commit

Permalink
refactor: use internal context in sessionWantSender
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkmc committed Mar 24, 2020
1 parent ac258ab commit 70c3111
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion internal/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func New(ctx context.Context,
periodicSearchDelay: periodicSearchDelay,
self: self,
}
s.sws = newSessionWantSender(ctx, id, pm, sprm, bpm, s.onWantsSent, s.onPeersExhausted)
s.sws = newSessionWantSender(id, pm, sprm, bpm, s.onWantsSent, s.onPeersExhausted)

go s.run(ctx)

Expand Down
6 changes: 3 additions & 3 deletions internal/session/sessionwantsender.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type sessionWantSender struct {
ctx context.Context
// Called to shutdown the sessionWantSender
shutdown func()
// The sessionWantSender uses the close channel to signal when it's
// The sessionWantSender uses the closed channel to signal when it's
// finished shutting down
closed chan struct{}
// The session ID
Expand All @@ -102,10 +102,10 @@ type sessionWantSender struct {
onPeersExhausted onPeersExhaustedFn
}

func newSessionWantSender(ctx context.Context, sid uint64, pm PeerManager, spm SessionPeerManager,
func newSessionWantSender(sid uint64, pm PeerManager, spm SessionPeerManager,
bpm *bsbpm.BlockPresenceManager, onSend onSendFn, onPeersExhausted onPeersExhaustedFn) sessionWantSender {

ctx, cancel := context.WithCancel(ctx)
ctx, cancel := context.WithCancel(context.Background())
sws := sessionWantSender{
ctx: ctx,
shutdown: cancel,
Expand Down
22 changes: 11 additions & 11 deletions internal/session/sessionwantsender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func TestSendWants(t *testing.T) {
bpm := bsbpm.New()
onSend := func(peer.ID, []cid.Cid, []cid.Cid) {}
onPeersExhausted := func([]cid.Cid) {}
spm := newSessionWantSender(context.Background(), sid, pm, fpm, bpm, onSend, onPeersExhausted)
spm := newSessionWantSender(sid, pm, fpm, bpm, onSend, onPeersExhausted)

go spm.Run()

Expand Down Expand Up @@ -176,7 +176,7 @@ func TestSendsWantBlockToOnePeerOnly(t *testing.T) {
bpm := bsbpm.New()
onSend := func(peer.ID, []cid.Cid, []cid.Cid) {}
onPeersExhausted := func([]cid.Cid) {}
spm := newSessionWantSender(context.Background(), sid, pm, fpm, bpm, onSend, onPeersExhausted)
spm := newSessionWantSender(sid, pm, fpm, bpm, onSend, onPeersExhausted)

go spm.Run()

Expand Down Expand Up @@ -234,7 +234,7 @@ func TestReceiveBlock(t *testing.T) {
bpm := bsbpm.New()
onSend := func(peer.ID, []cid.Cid, []cid.Cid) {}
onPeersExhausted := func([]cid.Cid) {}
spm := newSessionWantSender(context.Background(), sid, pm, fpm, bpm, onSend, onPeersExhausted)
spm := newSessionWantSender(sid, pm, fpm, bpm, onSend, onPeersExhausted)

go spm.Run()

Expand Down Expand Up @@ -294,7 +294,7 @@ func TestPeerUnavailable(t *testing.T) {
bpm := bsbpm.New()
onSend := func(peer.ID, []cid.Cid, []cid.Cid) {}
onPeersExhausted := func([]cid.Cid) {}
spm := newSessionWantSender(context.Background(), sid, pm, fpm, bpm, onSend, onPeersExhausted)
spm := newSessionWantSender(sid, pm, fpm, bpm, onSend, onPeersExhausted)

go spm.Run()

Expand Down Expand Up @@ -360,7 +360,7 @@ func TestPeersExhausted(t *testing.T) {
onSend := func(peer.ID, []cid.Cid, []cid.Cid) {}

ep := exhaustedPeers{}
spm := newSessionWantSender(context.Background(), sid, pm, fpm, bpm, onSend, ep.onPeersExhausted)
spm := newSessionWantSender(sid, pm, fpm, bpm, onSend, ep.onPeersExhausted)

go spm.Run()

Expand Down Expand Up @@ -436,7 +436,7 @@ func TestPeersExhaustedLastWaitingPeerUnavailable(t *testing.T) {
onSend := func(peer.ID, []cid.Cid, []cid.Cid) {}

ep := exhaustedPeers{}
spm := newSessionWantSender(context.Background(), sid, pm, fpm, bpm, onSend, ep.onPeersExhausted)
spm := newSessionWantSender(sid, pm, fpm, bpm, onSend, ep.onPeersExhausted)

go spm.Run()

Expand Down Expand Up @@ -484,7 +484,7 @@ func TestPeersExhaustedAllPeersUnavailable(t *testing.T) {
onSend := func(peer.ID, []cid.Cid, []cid.Cid) {}

ep := exhaustedPeers{}
spm := newSessionWantSender(context.Background(), sid, pm, fpm, bpm, onSend, ep.onPeersExhausted)
spm := newSessionWantSender(sid, pm, fpm, bpm, onSend, ep.onPeersExhausted)

go spm.Run()

Expand Down Expand Up @@ -522,7 +522,7 @@ func TestConsecutiveDontHaveLimit(t *testing.T) {
bpm := bsbpm.New()
onSend := func(peer.ID, []cid.Cid, []cid.Cid) {}
onPeersExhausted := func([]cid.Cid) {}
spm := newSessionWantSender(context.Background(), sid, pm, fpm, bpm, onSend, onPeersExhausted)
spm := newSessionWantSender(sid, pm, fpm, bpm, onSend, onPeersExhausted)

go spm.Run()

Expand Down Expand Up @@ -578,7 +578,7 @@ func TestConsecutiveDontHaveLimitInterrupted(t *testing.T) {
bpm := bsbpm.New()
onSend := func(peer.ID, []cid.Cid, []cid.Cid) {}
onPeersExhausted := func([]cid.Cid) {}
spm := newSessionWantSender(context.Background(), sid, pm, fpm, bpm, onSend, onPeersExhausted)
spm := newSessionWantSender(sid, pm, fpm, bpm, onSend, onPeersExhausted)

go spm.Run()

Expand Down Expand Up @@ -633,7 +633,7 @@ func TestConsecutiveDontHaveReinstateAfterRemoval(t *testing.T) {
bpm := bsbpm.New()
onSend := func(peer.ID, []cid.Cid, []cid.Cid) {}
onPeersExhausted := func([]cid.Cid) {}
spm := newSessionWantSender(context.Background(), sid, pm, fpm, bpm, onSend, onPeersExhausted)
spm := newSessionWantSender(sid, pm, fpm, bpm, onSend, onPeersExhausted)

go spm.Run()

Expand Down Expand Up @@ -717,7 +717,7 @@ func TestConsecutiveDontHaveDontRemoveIfHasWantedBlock(t *testing.T) {
bpm := bsbpm.New()
onSend := func(peer.ID, []cid.Cid, []cid.Cid) {}
onPeersExhausted := func([]cid.Cid) {}
spm := newSessionWantSender(context.Background(), sid, pm, fpm, bpm, onSend, onPeersExhausted)
spm := newSessionWantSender(sid, pm, fpm, bpm, onSend, onPeersExhausted)

go spm.Run()

Expand Down

0 comments on commit 70c3111

Please sign in to comment.