Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

add RemovePeer method to PeerMetadata, Metrics, Protobook and Keybook #218

Merged
merged 1 commit into from
Oct 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions peerstore/peerstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,18 @@ type Peerstore interface {
// Refer to the docs of the underlying implementation for more
// information.
type PeerMetadata interface {
// 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 / 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(p peer.ID, key string) (interface{}, error)
Put(p peer.ID, key string, val interface{}) error

// RemovePeer removes all values stored for a peer.
RemovePeer(peer.ID)
}

// AddrBook holds the multiaddrs of peers.
type AddrBook interface {

// AddAddr calls AddAddrs(p, []ma.Multiaddr{addr}, ttl)
AddAddr(p peer.ID, addr ma.Multiaddr, ttl time.Duration)

Expand Down Expand Up @@ -212,19 +214,24 @@ type KeyBook interface {
// AddPrivKey stores the private key of a peer.
AddPrivKey(peer.ID, ic.PrivKey) error

// PeersWithKeys returns all the peer IDs stored in the KeyBook
// PeersWithKeys returns all the peer IDs stored in the KeyBook.
PeersWithKeys() peer.IDSlice

// RemovePeer removes all keys associated with a peer.
RemovePeer(peer.ID)
}

// Metrics is just an object that tracks metrics
// across a set of peers.
// Metrics tracks metrics across a set of peers.
type Metrics interface {
// RecordLatency records a new latency measurement
RecordLatency(peer.ID, time.Duration)

// LatencyEWMA returns an exponentially-weighted moving avg.
// of all measurements of a peer's latency.
LatencyEWMA(peer.ID) time.Duration

// RemovePeer removes all metrics stored for a peer.
RemovePeer(peer.ID)
}

// ProtoBook tracks the protocols supported by peers.
Expand All @@ -242,4 +249,7 @@ type ProtoBook interface {
// If the peer does not support any of the given protocols, this function will return an empty string and a nil error.
// If the returned error is not nil, the result is indeterminate.
FirstSupportedProtocol(peer.ID, ...string) (string, error)

// RemovePeer removes all protocols associated with a peer.
RemovePeer(peer.ID)
}