Documentation
¶
Overview ¶
package peer implements an object used to represent peers in the ipfs network.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var LatencyEWMASmoothing = 0.1
LatencyEWMASmooting governs the decay of the EWMA (the speed at which it changes). This must be a normalized (0-1) value. 1 is 100% change, 0 is no change.
Functions ¶
Types ¶
type AddressBook ¶
type AddressBook interface {
Addresses(ID) []ma.Multiaddr
AddAddress(ID, ma.Multiaddr)
AddAddresses(ID, []ma.Multiaddr)
}
AddressBook tracks the addresses of Peers
type ID ¶
type ID string
ID represents the identity of a peer.
func IDFromBytes ¶
func IDFromBytes(b []byte) (ID, error)
IDFromBytes cast a string to ID type, and validate the id to make sure it is a multihash.
func IDFromPrivateKey ¶
func IDFromPrivateKey(sk ic.PrivKey) (ID, error)
IDFromPrivateKey returns the Peer ID corresponding to sk
func IDFromPublicKey ¶
func IDFromPublicKey(pk ic.PubKey) (ID, error)
IDFromPublicKey returns the Peer ID corresponding to pk
func IDFromString ¶
func IDFromString(s string) (ID, error)
IDFromString cast a string to ID type, and validate the id to make sure it is a multihash.
func PeerInfoIDs ¶
func PeerInfoIDs(pis []PeerInfo) []ID
func (ID) MatchesPrivateKey ¶
func (id ID) MatchesPrivateKey(sk ic.PrivKey) bool
MatchesPrivateKey tests whether this ID was derived from sk
func (ID) MatchesPublicKey ¶
func (id ID) MatchesPublicKey(pk ic.PubKey) bool
MatchesPublicKey tests whether this ID was derived from pk
type KeyBook ¶
type KeyBook interface {
PubKey(ID) ic.PubKey
AddPubKey(ID, ic.PubKey) error
PrivKey(ID) ic.PrivKey
AddPrivKey(ID, ic.PrivKey) error
}
KeyBook tracks the Public keys of Peers.
type Metrics ¶
type Metrics interface {
// RecordLatency records a new latency measurement
RecordLatency(ID, time.Duration)
// LatencyEWMA returns an exponentially-weighted moving avg.
// of all measurements of a peer's latency.
LatencyEWMA(ID) time.Duration
}
Metrics is just an object that tracks metrics across a set of peers.
func NewMetrics ¶
func NewMetrics() Metrics
type PeerInfo ¶
type PeerInfo struct {
ID ID
Addrs []ma.Multiaddr
}
PeerInfo is a small struct used to pass around a peer with a set of addresses (and later, keys?). This is not meant to be a complete view of the system, but rather to model updates to the peerstore. It is used by things like the routing system.
type Peerstore ¶
type Peerstore interface {
KeyBook
AddressBook
Metrics
// Peers returns a list of all peer.IDs in this Peerstore
Peers() []ID
// PeerInfo returns a peer.PeerInfo struct for given peer.ID.
// This is a small slice of the information Peerstore has on
// that peer, useful to other services.
PeerInfo(ID) PeerInfo
// AddPeerInfo absorbs the information listed in given PeerInfo.
AddPeerInfo(PeerInfo)
// Get/Put is a simple registry for other peer-related key/value pairs.
// if we find something we use often, it should become its own set of
// methods. this is a last resort.
Get(id ID, key string) (interface{}, error)
Put(id ID, key string, val interface{}) error
}
Peerstore provides a threadsafe store of Peer related information.
func NewPeerstore ¶
func NewPeerstore() Peerstore
NewPeerstore creates a threadsafe collection of peers.