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

Commit

Permalink
add RemovePeer method to PeerMetadata, Metrics, ProtoBook and Keybook (
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Oct 24, 2021
1 parent 8bf73f7 commit b18a4c9
Showing 1 changed file with 17 additions and 7 deletions.
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)
}

0 comments on commit b18a4c9

Please sign in to comment.