Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-bitswap
Commits
70c3111e
Commit
70c3111e
authored
Mar 24, 2020
by
Dirk McCormick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: use internal context in sessionWantSender
parent
ac258abc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
15 deletions
+15
-15
internal/session/session.go
internal/session/session.go
+1
-1
internal/session/sessionwantsender.go
internal/session/sessionwantsender.go
+3
-3
internal/session/sessionwantsender_test.go
internal/session/sessionwantsender_test.go
+11
-11
No files found.
internal/session/session.go
View file @
70c3111e
...
...
@@ -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
)
...
...
internal/session/sessionwantsender.go
View file @
70c3111e
...
...
@@ -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 close
d
channel to signal when it's
// finished shutting down
closed
chan
struct
{}
// The session ID
...
...
@@ -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
(
c
tx
)
ctx
,
cancel
:=
context
.
WithCancel
(
c
ontext
.
Background
()
)
sws
:=
sessionWantSender
{
ctx
:
ctx
,
shutdown
:
cancel
,
...
...
internal/session/sessionwantsender_test.go
View file @
70c3111e
...
...
@@ -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
()
...
...
@@ -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
()
...
...
@@ -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
()
...
...
@@ -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
()
...
...
@@ -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
()
...
...
@@ -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
()
...
...
@@ -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
()
...
...
@@ -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
()
...
...
@@ -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
()
...
...
@@ -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
()
...
...
@@ -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
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment