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-dms3
Commits
bcbc268d
Commit
bcbc268d
authored
Mar 09, 2015
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #900 from jbenet/fix/bitswap-ctx-respect
respect contexts in a more timely manner
parents
2274b93a
5eb08c44
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
12 deletions
+45
-12
exchange/bitswap/bitswap.go
exchange/bitswap/bitswap.go
+45
-12
No files found.
exchange/bitswap/bitswap.go
View file @
bcbc268d
...
...
@@ -227,21 +227,43 @@ func (bs *Bitswap) HasBlock(ctx context.Context, blk *blocks.Block) error {
func
(
bs
*
Bitswap
)
sendWantlistMsgToPeers
(
ctx
context
.
Context
,
m
bsmsg
.
BitSwapMessage
,
peers
<-
chan
peer
.
ID
)
error
{
set
:=
pset
.
New
()
wg
:=
sync
.
WaitGroup
{}
for
peerToQuery
:=
range
peers
{
if
!
set
.
TryAdd
(
peerToQuery
)
{
//Do once per peer
continue
}
loop
:
for
{
select
{
case
peerToQuery
,
ok
:=
<-
peers
:
if
!
ok
{
break
loop
}
wg
.
Add
(
1
)
go
func
(
p
peer
.
ID
)
{
defer
wg
.
Done
()
if
err
:=
bs
.
send
(
ctx
,
p
,
m
);
err
!=
nil
{
log
.
Debug
(
err
)
// TODO remove if too verbose
if
!
set
.
TryAdd
(
peerToQuery
)
{
//Do once per peer
continue
}
}(
peerToQuery
)
wg
.
Add
(
1
)
go
func
(
p
peer
.
ID
)
{
defer
wg
.
Done
()
if
err
:=
bs
.
send
(
ctx
,
p
,
m
);
err
!=
nil
{
log
.
Debug
(
err
)
// TODO remove if too verbose
}
}(
peerToQuery
)
case
<-
ctx
.
Done
()
:
return
nil
}
}
done
:=
make
(
chan
struct
{})
go
func
()
{
wg
.
Wait
()
close
(
done
)
}()
select
{
case
<-
done
:
case
<-
ctx
.
Done
()
:
// NB: we may be abandoning goroutines here before they complete
// this shouldnt be an issue because they will complete soon anyways
// we just don't want their being slow to impact bitswap transfer speeds
}
wg
.
Wait
()
return
nil
}
...
...
@@ -385,7 +407,18 @@ func (bs *Bitswap) wantNewBlocks(ctx context.Context, bkeys []u.Key) {
}
}(
p
)
}
wg
.
Wait
()
done
:=
make
(
chan
struct
{})
go
func
()
{
wg
.
Wait
()
close
(
done
)
}()
select
{
case
<-
done
:
case
<-
ctx
.
Done
()
:
// NB: we may be abandoning goroutines here before they complete
// this shouldnt be an issue because they will complete soon anyways
// we just don't want their being slow to impact bitswap transfer speeds
}
}
func
(
bs
*
Bitswap
)
ReceiveError
(
err
error
)
{
...
...
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