style(bitswap) rename strategist -> strategy

This commit is contained in:
Brian Tiger Chow 2014-09-18 15:02:16 -07:00
parent b780694757
commit de9fcf5d12
3 changed files with 17 additions and 17 deletions

View File

@ -41,10 +41,10 @@ type bitswap struct {
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.
// TODO(brian): save the strategist's state to the datastore
strategist strategy.Strategist
// TODO(brian): save the strategy's state to the datastore
strategy strategy.Strategy
}
// NewSession initializes a bitswap session.
@ -55,7 +55,7 @@ func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d
bs := &bitswap{
blockstore: blockstore.NewBlockstore(d),
notifications: notifications.New(),
strategist: strategy.New(),
strategy: strategy.New(),
peer: p,
routing: directory,
sender: bsnet.NewNetworkAdapter(s, &receiver),
@ -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
// ReceiveMessage are called
bs.sender.SendMessage(ctx, p, message)
bs.strategist.MessageSent(p, message)
bs.strategy.MessageSent(p, message)
block, ok := <-blockChannel
if !ok {
@ -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) {
for _, p := range bs.strategist.Peers() {
if bs.strategist.IsWantedByPeer(block.Key(), p) {
if bs.strategist.ShouldSendToPeer(block.Key(), p) {
for _, p := range bs.strategy.Peers() {
if bs.strategy.BlockIsWantedByPeer(block.Key(), p) {
if bs.strategy.ShouldSendBlockToPeer(block.Key(), p) {
go bs.send(p, block)
}
}
@ -144,7 +144,7 @@ func (bs *bitswap) send(p *peer.Peer, b blocks.Block) {
message.AppendBlock(b)
// FIXME(brian): pass ctx
bs.sender.SendMessage(context.Background(), p, message)
bs.strategist.MessageSent(p, message)
bs.strategy.MessageSent(p, message)
}
// TODO(brian): handle errors
@ -152,7 +152,7 @@ func (bs *bitswap) ReceiveMessage(
ctx context.Context, sender *peer.Peer, incoming bsmsg.BitSwapMessage) (
*peer.Peer, bsmsg.BitSwapMessage, error) {
bs.strategist.MessageReceived(sender, incoming)
bs.strategy.MessageReceived(sender, incoming)
if incoming.Blocks() != nil {
for _, block := range incoming.Blocks() {
@ -163,7 +163,7 @@ func (bs *bitswap) ReceiveMessage(
if incoming.Wantlist() != nil {
for _, key := range incoming.Wantlist() {
if bs.strategist.ShouldSendToPeer(key, sender) {
if bs.strategy.ShouldSendBlockToPeer(key, sender) {
block, errBlockNotFound := bs.blockstore.Get(key)
if errBlockNotFound != nil {
// TODO(brian): log/return the error

View File

@ -6,17 +6,17 @@ import (
u "github.com/jbenet/go-ipfs/util"
)
type Strategist interface {
type Strategy interface {
Accountant
// Returns a slice of Peers that
Peers() []*peer.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
ShouldSendToPeer(u.Key, *peer.Peer) bool
ShouldSendBlockToPeer(u.Key, *peer.Peer) bool
// Seed initializes the decider to a deterministic state
Seed(int64)

View File

@ -9,7 +9,7 @@ import (
)
// TODO declare thread-safe datastore
func New() Strategist {
func New() Strategy {
return &strategist{
ledgerMap: ledgerMap{},
strategyFunc: yesManStrategy,
@ -36,12 +36,12 @@ func (s *strategist) Peers() []*peer.Peer {
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)
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)
return ledger.ShouldSend()
}