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-dms3
Commits
b7806947
Commit
b7806947
authored
Sep 18, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(bitswap) init wantlist
+ test that a partners wants are remembered by message receiver
parent
be8e0867
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
0 deletions
+19
-0
bitswap/strategy/ledger.go
bitswap/strategy/ledger.go
+1
-0
bitswap/strategy/strategy_test.go
bitswap/strategy/strategy_test.go
+18
-0
No files found.
bitswap/strategy/ledger.go
View file @
b7806947
...
@@ -14,6 +14,7 @@ type keySet map[u.Key]struct{}
...
@@ -14,6 +14,7 @@ type keySet map[u.Key]struct{}
func
newLedger
(
p
*
peer
.
Peer
,
strategy
strategyFunc
)
*
ledger
{
func
newLedger
(
p
*
peer
.
Peer
,
strategy
strategyFunc
)
*
ledger
{
return
&
ledger
{
return
&
ledger
{
wantList
:
keySet
{},
Strategy
:
strategy
,
Strategy
:
strategy
,
Partner
:
p
,
Partner
:
p
,
}
}
...
...
bitswap/strategy/strategy_test.go
View file @
b7806947
...
@@ -5,6 +5,7 @@ import (
...
@@ -5,6 +5,7 @@ import (
message
"github.com/jbenet/go-ipfs/bitswap/message"
message
"github.com/jbenet/go-ipfs/bitswap/message"
"github.com/jbenet/go-ipfs/peer"
"github.com/jbenet/go-ipfs/peer"
"github.com/jbenet/go-ipfs/util/testutil"
)
)
type
peerAndStrategist
struct
{
type
peerAndStrategist
struct
{
...
@@ -19,6 +20,23 @@ func newPeerAndStrategist(idStr string) peerAndStrategist {
...
@@ -19,6 +20,23 @@ func newPeerAndStrategist(idStr string) peerAndStrategist {
}
}
}
}
func
TestBlockRecordedAsWantedAfterMessageReceived
(
t
*
testing
.
T
)
{
beggar
:=
newPeerAndStrategist
(
"can't be chooser"
)
chooser
:=
newPeerAndStrategist
(
"chooses JIF"
)
block
:=
testutil
.
NewBlockOrFail
(
t
,
"data wanted by beggar"
)
messageFromBeggarToChooser
:=
message
.
New
()
messageFromBeggarToChooser
.
AppendWanted
(
block
.
Key
())
chooser
.
MessageReceived
(
beggar
.
Peer
,
messageFromBeggarToChooser
)
// for this test, doesn't matter if you record that beggar sent
if
!
chooser
.
IsWantedByPeer
(
block
.
Key
(),
beggar
.
Peer
)
{
t
.
Fatal
(
"chooser failed to record that beggar wants block"
)
}
}
func
TestPeerIsAddedToPeersWhenMessageReceivedOrSent
(
t
*
testing
.
T
)
{
func
TestPeerIsAddedToPeersWhenMessageReceivedOrSent
(
t
*
testing
.
T
)
{
sanfrancisco
:=
newPeerAndStrategist
(
"sf"
)
sanfrancisco
:=
newPeerAndStrategist
(
"sf"
)
...
...
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