mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-01 02:23:18 +08:00
feat(bitswap:strategy) add interfaces
refac(bitswap:strategy) update interface
This commit is contained in:
49
bitswap/strategy/interface.go
Normal file
49
bitswap/strategy/interface.go
Normal file
@ -0,0 +1,49 @@
|
||||
package strategy
|
||||
|
||||
import (
|
||||
bsmsg "github.com/jbenet/go-ipfs/bitswap/message"
|
||||
peer "github.com/jbenet/go-ipfs/peer"
|
||||
u "github.com/jbenet/go-ipfs/util"
|
||||
)
|
||||
|
||||
type Strategist 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
|
||||
|
||||
// ShouldSendTo(Peer) decides whether to send data to this Peer
|
||||
ShouldSendToPeer(u.Key, *peer.Peer) bool
|
||||
|
||||
// Seed initializes the decider to a deterministic state
|
||||
Seed(int64)
|
||||
}
|
||||
|
||||
type Accountant interface {
|
||||
// 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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user