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
27193bde
Commit
27193bde
authored
Dec 01, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup, use a workgroup over channels
parent
badec8dc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
5 deletions
+6
-5
bitswap.go
bitswap.go
+6
-5
No files found.
bitswap.go
View file @
27193bde
...
...
@@ -3,6 +3,7 @@
package
bitswap
import
(
"sync"
"time"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
...
...
@@ -180,8 +181,9 @@ func (bs *bitswap) sendWantListTo(ctx context.Context, peers <-chan peer.Peer) e
}
func
(
bs
*
bitswap
)
sendWantlistToProviders
(
ctx
context
.
Context
,
ks
[]
u
.
Key
)
{
done
:=
make
(
chan
struct
{}
)
wg
:=
sync
.
WaitGroup
{}
for
_
,
k
:=
range
ks
{
wg
.
Add
(
1
)
go
func
(
k
u
.
Key
)
{
providers
:=
bs
.
routing
.
FindProvidersAsync
(
ctx
,
k
,
maxProvidersPerRequest
)
...
...
@@ -189,12 +191,10 @@ func (bs *bitswap) sendWantlistToProviders(ctx context.Context, ks []u.Key) {
if
err
!=
nil
{
log
.
Errorf
(
"error sending wantlist: %s"
,
err
)
}
done
<-
struct
{}{}
wg
.
Done
()
}(
k
)
}
for
_
=
range
ks
{
<-
done
}
wg
.
Wait
()
}
// TODO ensure only one active request per key
...
...
@@ -255,6 +255,7 @@ func (bs *bitswap) HasBlock(ctx context.Context, blk *blocks.Block) error {
return
bs
.
routing
.
Provide
(
ctx
,
blk
.
Key
())
}
// receiveBlock handles storing the block in the blockstore and calling HasBlock
func
(
bs
*
bitswap
)
receiveBlock
(
ctx
context
.
Context
,
block
*
blocks
.
Block
)
{
// TODO verify blocks?
if
err
:=
bs
.
blockstore
.
Put
(
block
);
err
!=
nil
{
...
...
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