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
7787e3d1
Commit
7787e3d1
authored
Feb 05, 2018
by
Jeromy
Committed by
Steven Allen
Feb 09, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP: fix wantlist clearing by closing down session
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
8028bc49
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
0 deletions
+41
-0
session.go
session.go
+8
-0
session_test.go
session_test.go
+33
-0
No files found.
session.go
View file @
7787e3d1
...
...
@@ -84,6 +84,14 @@ func (bs *Bitswap) NewSession(ctx context.Context) *Session {
func
(
bs
*
Bitswap
)
removeSession
(
s
*
Session
)
{
s
.
notif
.
Shutdown
()
live
:=
make
([]
*
cid
.
Cid
,
0
,
len
(
s
.
liveWants
))
for
c
:=
range
s
.
liveWants
{
cs
,
_
:=
cid
.
Cast
([]
byte
(
c
))
live
=
append
(
live
,
cs
)
}
bs
.
CancelWants
(
live
,
s
.
id
)
bs
.
sessLk
.
Lock
()
defer
bs
.
sessLk
.
Unlock
()
for
i
:=
0
;
i
<
len
(
bs
.
sessions
);
i
++
{
...
...
session_test.go
View file @
7787e3d1
...
...
@@ -285,3 +285,36 @@ func TestMultipleSessions(t *testing.T) {
}
_
=
blkch
}
func
TestWantlistClearsOnCancel
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
vnet
:=
getVirtualNetwork
()
sesgen
:=
NewTestSessionGenerator
(
vnet
)
defer
sesgen
.
Close
()
bgen
:=
blocksutil
.
NewBlockGenerator
()
blks
:=
bgen
.
Blocks
(
10
)
var
cids
[]
*
cid
.
Cid
for
_
,
blk
:=
range
blks
{
cids
=
append
(
cids
,
blk
.
Cid
())
}
inst
:=
sesgen
.
Instances
(
1
)
a
:=
inst
[
0
]
ctx1
,
cancel1
:=
context
.
WithCancel
(
ctx
)
ses
:=
a
.
Exchange
.
NewSession
(
ctx1
)
_
,
err
:=
ses
.
GetBlocks
(
ctx
,
cids
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
cancel1
()
if
len
(
a
.
Exchange
.
GetWantlist
())
>
0
{
t
.
Fatal
(
"expected empty wantlist"
)
}
}
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