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
bc186b26
Commit
bc186b26
authored
May 27, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
parallelize block processing
parent
89c950aa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
26 deletions
+28
-26
bitswap.go
bitswap.go
+28
-26
No files found.
bitswap.go
View file @
bc186b26
...
...
@@ -279,39 +279,41 @@ func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg
// quickly send out cancels, reduces chances of duplicate block receives
var
keys
[]
u
.
Key
for
_
,
block
:=
range
iblocks
{
keys
=
append
(
keys
,
block
.
Key
())
}
bs
.
wm
.
CancelWants
(
keys
)
for
_
,
block
:=
range
iblocks
{
bs
.
counterLk
.
Lock
()
bs
.
blocksRecvd
++
has
,
err
:=
bs
.
blockstore
.
Has
(
block
.
Key
())
if
err
==
nil
&&
has
{
bs
.
dupBlocksRecvd
++
}
brecvd
:=
bs
.
blocksRecvd
bdup
:=
bs
.
dupBlocksRecvd
bs
.
counterLk
.
Unlock
()
if
has
{
continue
}
// put this after the duplicate check as a block not on our wantlist may
// have already been received.
if
_
,
found
:=
bs
.
wm
.
wl
.
Contains
(
block
.
Key
());
!
found
{
log
.
Notice
(
"received un-asked-for block: %s"
,
block
)
continue
}
keys
=
append
(
keys
,
block
.
Key
())
}
bs
.
wm
.
CancelWants
(
keys
)
log
.
Infof
(
"got block %s from %s (%d,%d)"
,
block
,
p
,
brecvd
,
bdup
)
wg
:=
sync
.
WaitGroup
{}
for
_
,
block
:=
range
iblocks
{
wg
.
Add
(
1
)
go
func
(
b
*
blocks
.
Block
)
{
defer
wg
.
Done
()
bs
.
counterLk
.
Lock
()
bs
.
blocksRecvd
++
has
,
err
:=
bs
.
blockstore
.
Has
(
b
.
Key
())
if
err
==
nil
&&
has
{
bs
.
dupBlocksRecvd
++
}
brecvd
:=
bs
.
blocksRecvd
bdup
:=
bs
.
dupBlocksRecvd
bs
.
counterLk
.
Unlock
()
if
has
{
return
}
hasBlockCtx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
hasBlockTimeout
)
if
err
:=
bs
.
HasBlock
(
hasBlockCtx
,
block
);
err
!=
nil
{
log
.
Warningf
(
"ReceiveMessage HasBlock error: %s"
,
err
)
}
cancel
()
log
.
Debugf
(
"got block %s from %s (%d,%d)"
,
b
,
p
,
brecvd
,
bdup
)
hasBlockCtx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
hasBlockTimeout
)
if
err
:=
bs
.
HasBlock
(
hasBlockCtx
,
b
);
err
!=
nil
{
log
.
Warningf
(
"ReceiveMessage HasBlock error: %s"
,
err
)
}
cancel
()
}(
block
)
}
wg
.
Wait
()
}
// Connected/Disconnected warns bitswap about peer connections
...
...
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