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
64329ed1
Commit
64329ed1
authored
Feb 26, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make sure not to orphan any extra goroutines
parent
5fb913d6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
1 deletion
+14
-1
bitswap.go
bitswap.go
+5
-0
workers.go
workers.go
+9
-1
No files found.
bitswap.go
View file @
64329ed1
...
@@ -368,14 +368,19 @@ func (bs *bitswap) wantNewBlocks(ctx context.Context, bkeys []u.Key) {
...
@@ -368,14 +368,19 @@ func (bs *bitswap) wantNewBlocks(ctx context.Context, bkeys []u.Key) {
for
i
,
k
:=
range
bkeys
{
for
i
,
k
:=
range
bkeys
{
message
.
AddEntry
(
k
,
kMaxPriority
-
i
)
message
.
AddEntry
(
k
,
kMaxPriority
-
i
)
}
}
wg
:=
sync
.
WaitGroup
{}
for
_
,
p
:=
range
bs
.
engine
.
Peers
()
{
for
_
,
p
:=
range
bs
.
engine
.
Peers
()
{
wg
.
Add
(
1
)
go
func
(
p
peer
.
ID
)
{
go
func
(
p
peer
.
ID
)
{
defer
wg
.
Done
()
err
:=
bs
.
send
(
ctx
,
p
,
message
)
err
:=
bs
.
send
(
ctx
,
p
,
message
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Debugf
(
"Error sending message: %s"
,
err
)
log
.
Debugf
(
"Error sending message: %s"
,
err
)
}
}
}(
p
)
}(
p
)
}
}
wg
.
Wait
()
}
}
func
(
bs
*
bitswap
)
ReceiveError
(
err
error
)
{
func
(
bs
*
bitswap
)
ReceiveError
(
err
error
)
{
...
...
workers.go
View file @
64329ed1
...
@@ -90,7 +90,11 @@ func (bs *bitswap) clientWorker(parent context.Context) {
...
@@ -90,7 +90,11 @@ func (bs *bitswap) clientWorker(parent context.Context) {
bs
.
wantlist
.
Add
(
k
,
kMaxPriority
-
i
)
bs
.
wantlist
.
Add
(
k
,
kMaxPriority
-
i
)
}
}
bs
.
wantNewBlocks
(
req
.
ctx
,
keys
)
done
:=
make
(
chan
struct
{})
go
func
()
{
bs
.
wantNewBlocks
(
req
.
ctx
,
keys
)
close
(
done
)
}()
// NB: Optimization. Assumes that providers of key[0] are likely to
// NB: Optimization. Assumes that providers of key[0] are likely to
// be able to provide for all keys. This currently holds true in most
// be able to provide for all keys. This currently holds true in most
...
@@ -101,6 +105,10 @@ func (bs *bitswap) clientWorker(parent context.Context) {
...
@@ -101,6 +105,10 @@ func (bs *bitswap) clientWorker(parent context.Context) {
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Debugf
(
"error sending wantlist: %s"
,
err
)
log
.
Debugf
(
"error sending wantlist: %s"
,
err
)
}
}
// Wait for wantNewBlocks to finish
<-
done
case
<-
parent
.
Done
()
:
case
<-
parent
.
Done
()
:
return
return
}
}
...
...
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