interface.go 1.27 KB
Newer Older
1 2 3 4 5 6 7 8 9
package strategy

import (
	bsmsg "github.com/jbenet/go-ipfs/exchange/bitswap/message"
	peer "github.com/jbenet/go-ipfs/peer"
	u "github.com/jbenet/go-ipfs/util"
)

type Strategy interface {
10
	// Returns a slice of Peers with whom the local node has active sessions
11 12
	Peers() []*peer.Peer

13 14
	// BlockIsWantedByPeer returns true if peer wants the block given by this
	// key
15 16 17 18 19 20 21 22 23 24 25 26 27
	BlockIsWantedByPeer(u.Key, *peer.Peer) bool

	// ShouldSendTo(Peer) decides whether to send data to this Peer
	ShouldSendBlockToPeer(u.Key, *peer.Peer) bool

	// Seed initializes the decider to a deterministic state
	Seed(int64)

	// MessageReceived records receipt of message for accounting purposes
	MessageReceived(*peer.Peer, bsmsg.BitSwapMessage) error

	// MessageSent records sending of message for accounting purposes
	MessageSent(*peer.Peer, bsmsg.BitSwapMessage) error
28 29 30 31

	NumBytesSentTo(*peer.Peer) uint64

	NumBytesReceivedFrom(*peer.Peer) uint64
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
}

type WantList interface {
	// Peer returns the owner of the WantList
	Peer() *peer.Peer

	// Intersection returns the keys common to both WantLists
	Intersection(WantList) WantList

	KeySet
}

// TODO(brian): potentially move this somewhere more generic. For now, it's
// useful in BitSwap operations.

type KeySet interface {
	Contains(u.Key) bool
	Keys() []u.Key
}