feat(bitswap:strategy) add interfaces
refac(bitswap:strategy) update interface
Brian Tiger Chow committed
Sep 17, 2014 at 03:43 UTC
4448494155a434f5728c0035a652ebf9195177db
1 file changed
+49
bitswap/strategy/interface.go
new
+49
@@ -0,0 +1,49 @@
1
+package strategy
2
+
3
+import (
4
+ bsmsg "github.com/jbenet/go-ipfs/bitswap/message"
5
+ peer "github.com/jbenet/go-ipfs/peer"
6
+ u "github.com/jbenet/go-ipfs/util"
7
+)
8
+
9
+type Strategist 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
17
+
18
+ // ShouldSendTo(Peer) decides whether to send data to this Peer
19
+ ShouldSendToPeer(u.Key, *peer.Peer) bool
20
+
21
+ // Seed initializes the decider to a deterministic state
22
+ Seed(int64)
23
+}
24
+
25
+type Accountant interface {
26
+ // MessageReceived records receipt of message for accounting purposes
27
+ MessageReceived(*peer.Peer, bsmsg.BitSwapMessage) error
28
+
29
+ // MessageSent records sending of message for accounting purposes
30
+ MessageSent(*peer.Peer, bsmsg.BitSwapMessage) error
31
+}
32
+
33
+type WantList interface {
34
+ // Peer returns the owner of the WantList
35
+ Peer() *peer.Peer
36
+
37
+ // Intersection returns the keys common to both WantLists
38
+ Intersection(WantList) WantList
39
+
40
+ KeySet
41
+}
42
+
43
+// TODO(brian): potentially move this somewhere more generic. For now, it's
44
+// useful in BitSwap operations.
45
+
46
+type KeySet interface {
47
+ Contains(u.Key) bool
48
+ Keys() []u.Key
49
+}