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
c5b071da
Unverified
Commit
c5b071da
authored
Nov 15, 2018
by
Hannah Howard
Committed by
GitHub
Nov 15, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #24 from ipfs/bugs/dont-receive-unwanted-blocks-21
fix(Receiver): Ignore unwanted blocks
parents
edf24960
779c923a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
0 deletions
+39
-0
bitswap.go
bitswap.go
+6
-0
bitswap_test.go
bitswap_test.go
+33
-0
No files found.
bitswap.go
View file @
c5b071da
...
...
@@ -388,6 +388,7 @@ func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg
wg
:=
sync
.
WaitGroup
{}
for
_
,
block
:=
range
iblocks
{
wg
.
Add
(
1
)
go
func
(
b
blocks
.
Block
)
{
// TODO: this probably doesnt need to be a goroutine...
defer
wg
.
Done
()
...
...
@@ -396,6 +397,11 @@ func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg
log
.
Debugf
(
"got block %s from %s"
,
b
,
p
)
// skip received blocks that are not in the wantlist
if
_
,
contains
:=
bs
.
wm
.
wl
.
Contains
(
b
.
Cid
());
!
contains
{
return
}
if
err
:=
bs
.
receiveBlockFrom
(
b
,
p
);
err
!=
nil
{
log
.
Warningf
(
"ReceiveMessage recvBlockFrom error: %s"
,
err
)
}
...
...
bitswap_test.go
View file @
c5b071da
...
...
@@ -9,6 +9,7 @@ import (
"time"
decision
"github.com/ipfs/go-bitswap/decision"
"github.com/ipfs/go-bitswap/message"
tn
"github.com/ipfs/go-bitswap/testnet"
blocks
"github.com/ipfs/go-block-format"
...
...
@@ -98,6 +99,38 @@ func TestGetBlockFromPeerAfterPeerAnnounces(t *testing.T) {
}
}
func
TestUnwantedBlockNotAdded
(
t
*
testing
.
T
)
{
net
:=
tn
.
VirtualNetwork
(
mockrouting
.
NewServer
(),
delay
.
Fixed
(
kNetworkDelay
))
block
:=
blocks
.
NewBlock
([]
byte
(
"block"
))
bsMessage
:=
message
.
New
(
true
)
bsMessage
.
AddBlock
(
block
)
g
:=
NewTestSessionGenerator
(
net
)
defer
g
.
Close
()
peers
:=
g
.
Instances
(
2
)
hasBlock
:=
peers
[
0
]
defer
hasBlock
.
Exchange
.
Close
()
if
err
:=
hasBlock
.
Exchange
.
HasBlock
(
block
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
doesNotWantBlock
:=
peers
[
1
]
defer
doesNotWantBlock
.
Exchange
.
Close
()
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
)
defer
cancel
()
doesNotWantBlock
.
Exchange
.
ReceiveMessage
(
ctx
,
hasBlock
.
Peer
,
bsMessage
)
blockInStore
,
err
:=
doesNotWantBlock
.
blockstore
.
Has
(
block
.
Cid
())
if
err
!=
nil
||
blockInStore
{
t
.
Fatal
(
"Unwanted block added to block store"
)
}
}
func
TestLargeSwarm
(
t
*
testing
.
T
)
{
if
testing
.
Short
()
{
t
.
SkipNow
()
...
...
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