Commit b7806947 authored by Brian Tiger Chow's avatar Brian Tiger Chow

fix(bitswap) init wantlist

+ test that a partners wants are remembered by message receiver
parent be8e0867
...@@ -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,
} }
......
...@@ -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")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment