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

style(bitswap) rename strategist -> strategy

parent b7806947
...@@ -41,10 +41,10 @@ type bitswap struct { ...@@ -41,10 +41,10 @@ type bitswap struct {
notifications notifications.PubSub notifications notifications.PubSub
// strategist listens to network traffic and makes decisions about how to // strategy listens to network traffic and makes decisions about how to
// interact with partners. // interact with partners.
// TODO(brian): save the strategist's state to the datastore // TODO(brian): save the strategy's state to the datastore
strategist strategy.Strategist strategy strategy.Strategy
} }
// NewSession initializes a bitswap session. // NewSession initializes a bitswap session.
...@@ -55,7 +55,7 @@ func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d ...@@ -55,7 +55,7 @@ func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d
bs := &bitswap{ bs := &bitswap{
blockstore: blockstore.NewBlockstore(d), blockstore: blockstore.NewBlockstore(d),
notifications: notifications.New(), notifications: notifications.New(),
strategist: strategy.New(), strategy: strategy.New(),
peer: p, peer: p,
routing: directory, routing: directory,
sender: bsnet.NewNetworkAdapter(s, &receiver), sender: bsnet.NewNetworkAdapter(s, &receiver),
...@@ -112,7 +112,7 @@ func (bs *bitswap) getBlock(k u.Key, p *peer.Peer, timeout time.Duration) (*bloc ...@@ -112,7 +112,7 @@ func (bs *bitswap) getBlock(k u.Key, p *peer.Peer, timeout time.Duration) (*bloc
// that accounting is _always_ performed when SendMessage and // that accounting is _always_ performed when SendMessage and
// ReceiveMessage are called // ReceiveMessage are called
bs.sender.SendMessage(ctx, p, message) bs.sender.SendMessage(ctx, p, message)
bs.strategist.MessageSent(p, message) bs.strategy.MessageSent(p, message)
block, ok := <-blockChannel block, ok := <-blockChannel
if !ok { if !ok {
...@@ -122,9 +122,9 @@ func (bs *bitswap) getBlock(k u.Key, p *peer.Peer, timeout time.Duration) (*bloc ...@@ -122,9 +122,9 @@ func (bs *bitswap) getBlock(k u.Key, p *peer.Peer, timeout time.Duration) (*bloc
} }
func (bs *bitswap) sendToPeersThatWant(block blocks.Block) { func (bs *bitswap) sendToPeersThatWant(block blocks.Block) {
for _, p := range bs.strategist.Peers() { for _, p := range bs.strategy.Peers() {
if bs.strategist.IsWantedByPeer(block.Key(), p) { if bs.strategy.BlockIsWantedByPeer(block.Key(), p) {
if bs.strategist.ShouldSendToPeer(block.Key(), p) { if bs.strategy.ShouldSendBlockToPeer(block.Key(), p) {
go bs.send(p, block) go bs.send(p, block)
} }
} }
...@@ -144,7 +144,7 @@ func (bs *bitswap) send(p *peer.Peer, b blocks.Block) { ...@@ -144,7 +144,7 @@ func (bs *bitswap) send(p *peer.Peer, b blocks.Block) {
message.AppendBlock(b) message.AppendBlock(b)
// FIXME(brian): pass ctx // FIXME(brian): pass ctx
bs.sender.SendMessage(context.Background(), p, message) bs.sender.SendMessage(context.Background(), p, message)
bs.strategist.MessageSent(p, message) bs.strategy.MessageSent(p, message)
} }
// TODO(brian): handle errors // TODO(brian): handle errors
...@@ -152,7 +152,7 @@ func (bs *bitswap) ReceiveMessage( ...@@ -152,7 +152,7 @@ func (bs *bitswap) ReceiveMessage(
ctx context.Context, sender *peer.Peer, incoming bsmsg.BitSwapMessage) ( ctx context.Context, sender *peer.Peer, incoming bsmsg.BitSwapMessage) (
*peer.Peer, bsmsg.BitSwapMessage, error) { *peer.Peer, bsmsg.BitSwapMessage, error) {
bs.strategist.MessageReceived(sender, incoming) bs.strategy.MessageReceived(sender, incoming)
if incoming.Blocks() != nil { if incoming.Blocks() != nil {
for _, block := range incoming.Blocks() { for _, block := range incoming.Blocks() {
...@@ -163,7 +163,7 @@ func (bs *bitswap) ReceiveMessage( ...@@ -163,7 +163,7 @@ func (bs *bitswap) ReceiveMessage(
if incoming.Wantlist() != nil { if incoming.Wantlist() != nil {
for _, key := range incoming.Wantlist() { for _, key := range incoming.Wantlist() {
if bs.strategist.ShouldSendToPeer(key, sender) { if bs.strategy.ShouldSendBlockToPeer(key, sender) {
block, errBlockNotFound := bs.blockstore.Get(key) block, errBlockNotFound := bs.blockstore.Get(key)
if errBlockNotFound != nil { if errBlockNotFound != nil {
// TODO(brian): log/return the error // TODO(brian): log/return the error
......
...@@ -6,17 +6,17 @@ import ( ...@@ -6,17 +6,17 @@ import (
u "github.com/jbenet/go-ipfs/util" u "github.com/jbenet/go-ipfs/util"
) )
type Strategist interface { type Strategy interface {
Accountant Accountant
// Returns a slice of Peers that // Returns a slice of Peers that
Peers() []*peer.Peer Peers() []*peer.Peer
// WantList returns the WantList for the given Peer // WantList returns the WantList for the given Peer
IsWantedByPeer(u.Key, *peer.Peer) bool BlockIsWantedByPeer(u.Key, *peer.Peer) bool
// ShouldSendTo(Peer) decides whether to send data to this Peer // ShouldSendTo(Peer) decides whether to send data to this Peer
ShouldSendToPeer(u.Key, *peer.Peer) bool ShouldSendBlockToPeer(u.Key, *peer.Peer) bool
// Seed initializes the decider to a deterministic state // Seed initializes the decider to a deterministic state
Seed(int64) Seed(int64)
......
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
) )
// TODO declare thread-safe datastore // TODO declare thread-safe datastore
func New() Strategist { func New() Strategy {
return &strategist{ return &strategist{
ledgerMap: ledgerMap{}, ledgerMap: ledgerMap{},
strategyFunc: yesManStrategy, strategyFunc: yesManStrategy,
...@@ -36,12 +36,12 @@ func (s *strategist) Peers() []*peer.Peer { ...@@ -36,12 +36,12 @@ func (s *strategist) Peers() []*peer.Peer {
return response return response
} }
func (s *strategist) IsWantedByPeer(k u.Key, p *peer.Peer) bool { func (s *strategist) BlockIsWantedByPeer(k u.Key, p *peer.Peer) bool {
ledger := s.ledger(p) ledger := s.ledger(p)
return ledger.WantListContains(k) return ledger.WantListContains(k)
} }
func (s *strategist) ShouldSendToPeer(k u.Key, p *peer.Peer) bool { func (s *strategist) ShouldSendBlockToPeer(k u.Key, p *peer.Peer) bool {
ledger := s.ledger(p) ledger := s.ledger(p)
return ledger.ShouldSend() return ledger.ShouldSend()
} }
......
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