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
0881636a
Commit
0881636a
authored
Sep 19, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refac(bitswap) less concurrency while testing and iterating
parent
c34211a7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
9 deletions
+8
-9
bitswap.go
bitswap.go
+8
-9
No files found.
bitswap.go
View file @
0881636a
...
...
@@ -79,7 +79,7 @@ func (bs *bitswap) Block(parent context.Context, k u.Key) (*blocks.Block, error)
message
:=
bsmsg
.
New
()
message
.
AppendWanted
(
k
)
for
i
:=
range
peersToQuery
{
go
func
(
p
*
peer
.
Peer
)
{
func
(
p
*
peer
.
Peer
)
{
response
,
err
:=
bs
.
sender
.
SendRequest
(
ctx
,
p
,
message
)
if
err
!=
nil
{
return
...
...
@@ -109,7 +109,7 @@ func (bs *bitswap) Block(parent context.Context, k u.Key) (*blocks.Block, error)
// HasBlock announces the existance of a block to bitswap, potentially sending
// it to peers (Partners) whose WantLists include it.
func
(
bs
*
bitswap
)
HasBlock
(
ctx
context
.
Context
,
blk
blocks
.
Block
)
error
{
go
bs
.
sendToPeersThatWant
(
ctx
,
blk
)
bs
.
sendToPeersThatWant
(
ctx
,
blk
)
return
bs
.
routing
.
Provide
(
blk
.
Key
())
}
...
...
@@ -128,9 +128,9 @@ func (bs *bitswap) ReceiveMessage(
if
incoming
.
Blocks
()
!=
nil
{
for
_
,
block
:=
range
incoming
.
Blocks
()
{
go
bs
.
blockstore
.
Put
(
block
)
// FIXME(brian): err ignored
go
bs
.
notifications
.
Publish
(
block
)
go
bs
.
HasBlock
(
ctx
,
block
)
// FIXME err ignored
bs
.
blockstore
.
Put
(
block
)
// FIXME(brian): err ignored
bs
.
notifications
.
Publish
(
block
)
bs
.
HasBlock
(
ctx
,
block
)
// FIXME err ignored
}
}
...
...
@@ -139,12 +139,11 @@ func (bs *bitswap) ReceiveMessage(
if
bs
.
strategy
.
ShouldSendBlockToPeer
(
key
,
p
)
{
block
,
errBlockNotFound
:=
bs
.
blockstore
.
Get
(
key
)
if
errBlockNotFound
!=
nil
{
// TODO(brian): log/return the error
continue
return
nil
,
nil
,
errBlockNotFound
}
message
:=
bsmsg
.
New
()
message
.
AppendBlock
(
*
block
)
go
bs
.
send
(
ctx
,
p
,
message
)
bs
.
send
(
ctx
,
p
,
message
)
}
}
}
...
...
@@ -168,7 +167,7 @@ func (bs *bitswap) sendToPeersThatWant(ctx context.Context, block blocks.Block)
if
bs
.
strategy
.
ShouldSendBlockToPeer
(
block
.
Key
(),
p
)
{
message
:=
bsmsg
.
New
()
message
.
AppendBlock
(
block
)
go
bs
.
send
(
ctx
,
p
,
message
)
bs
.
send
(
ctx
,
p
,
message
)
}
}
}
...
...
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