@cryptotaxi247 / kubo / commits / de9fcf5d1

style(bitswap) rename strategist -> strategy

Brian Tiger Chow committed Sep 18, 2014 at 15:02 UTC de9fcf5d120abbf5207514b73cf4dd269469a9f0
3 files changed +17 -17
bitswap/bitswap.go
+11 -11
@@ -41,10 +41,10 @@ type bitswap struct {
41
42 notifications notifications.PubSub
43
44 - // strategist listens to network traffic and makes decisions about how to
44 + // strategy listens to network traffic and makes decisions about how to
45 // interact with partners.
46 - // TODO(brian): save the strategist's state to the datastore
47 - strategist strategy.Strategist
46 + // TODO(brian): save the strategy's state to the datastore
47 + strategy strategy.Strategy
48 }
49
50 // NewSession initializes a bitswap session.
@@ -55,7 +55,7 @@ func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d
55 bs := &bitswap{
56 blockstore: blockstore.NewBlockstore(d),
57 notifications: notifications.New(),
58 - strategist: strategy.New(),
58 + strategy: strategy.New(),
59 peer: p,
60 routing: directory,
61 sender: bsnet.NewNetworkAdapter(s, &receiver),
@@ -112,7 +112,7 @@ func (bs *bitswap) getBlock(k u.Key, p *peer.Peer, timeout time.Duration) (*bloc
112 // that accounting is _always_ performed when SendMessage and
113 // ReceiveMessage are called
114 bs.sender.SendMessage(ctx, p, message)
115 - bs.strategist.MessageSent(p, message)
115 + bs.strategy.MessageSent(p, message)
116
117 block, ok := <-blockChannel
118 if !ok {
@@ -122,9 +122,9 @@ func (bs *bitswap) getBlock(k u.Key, p *peer.Peer, timeout time.Duration) (*bloc
122 }
123
124 func (bs *bitswap) sendToPeersThatWant(block blocks.Block) {
125 - for _, p := range bs.strategist.Peers() {
126 - if bs.strategist.IsWantedByPeer(block.Key(), p) {
127 - if bs.strategist.ShouldSendToPeer(block.Key(), p) {
125 + for _, p := range bs.strategy.Peers() {
126 + if bs.strategy.BlockIsWantedByPeer(block.Key(), p) {
127 + if bs.strategy.ShouldSendBlockToPeer(block.Key(), p) {
128 go bs.send(p, block)
129 }
130 }
@@ -144,7 +144,7 @@ func (bs *bitswap) send(p *peer.Peer, b blocks.Block) {
144 message.AppendBlock(b)
145 // FIXME(brian): pass ctx
146 bs.sender.SendMessage(context.Background(), p, message)
147 - bs.strategist.MessageSent(p, message)
147 + bs.strategy.MessageSent(p, message)
148 }
149
150 // TODO(brian): handle errors
@@ -152,7 +152,7 @@ func (bs *bitswap) ReceiveMessage(
152 ctx context.Context, sender *peer.Peer, incoming bsmsg.BitSwapMessage) (
153 *peer.Peer, bsmsg.BitSwapMessage, error) {
154
155 - bs.strategist.MessageReceived(sender, incoming)
155 + bs.strategy.MessageReceived(sender, incoming)
156
157 if incoming.Blocks() != nil {
158 for _, block := range incoming.Blocks() {
@@ -163,7 +163,7 @@ func (bs *bitswap) ReceiveMessage(
163
164 if incoming.Wantlist() != nil {
165 for _, key := range incoming.Wantlist() {
166 - if bs.strategist.ShouldSendToPeer(key, sender) {
166 + if bs.strategy.ShouldSendBlockToPeer(key, sender) {
167 block, errBlockNotFound := bs.blockstore.Get(key)
168 if errBlockNotFound != nil {
169 // TODO(brian): log/return the error
bitswap/strategy/interface.go
+3 -3
@@ -6,17 +6,17 @@ import (
6 u "github.com/jbenet/go-ipfs/util"
7 )
8
9 -type Strategist interface {
9 +type Strategy interface {
10 Accountant
11
12 // Returns a slice of Peers that
13 Peers() []*peer.Peer
14
15 // WantList returns the WantList for the given Peer
16 - IsWantedByPeer(u.Key, *peer.Peer) bool
16 + BlockIsWantedByPeer(u.Key, *peer.Peer) bool
17
18 // ShouldSendTo(Peer) decides whether to send data to this Peer
19 - ShouldSendToPeer(u.Key, *peer.Peer) bool
19 + ShouldSendBlockToPeer(u.Key, *peer.Peer) bool
20
21 // Seed initializes the decider to a deterministic state
22 Seed(int64)
bitswap/strategy/strategy.go
+3 -3
@@ -9,7 +9,7 @@ import (
9 )
10
11 // TODO declare thread-safe datastore
12 -func New() Strategist {
12 +func New() Strategy {
13 return &strategist{
14 ledgerMap: ledgerMap{},
15 strategyFunc: yesManStrategy,
@@ -36,12 +36,12 @@ func (s *strategist) Peers() []*peer.Peer {
36 return response
37 }
38
39 -func (s *strategist) IsWantedByPeer(k u.Key, p *peer.Peer) bool {
39 +func (s *strategist) BlockIsWantedByPeer(k u.Key, p *peer.Peer) bool {
40 ledger := s.ledger(p)
41 return ledger.WantListContains(k)
42 }
43
44 -func (s *strategist) ShouldSendToPeer(k u.Key, p *peer.Peer) bool {
44 +func (s *strategist) ShouldSendBlockToPeer(k u.Key, p *peer.Peer) bool {
45 ledger := s.ledger(p)
46 return ledger.ShouldSend()
47 }