mirror of
https://github.com/libp2p/go-libp2p-core.git
synced 2024-12-26 23:30:27 +08:00
add RemovePeer method to PeerMetadata, Metrics, ProtoBook and Keybook (#218)
This commit is contained in:
parent
8bf73f7e2f
commit
b18a4c9c56
@ -78,16 +78,18 @@ type Peerstore interface {
|
|||||||
// Refer to the docs of the underlying implementation for more
|
// Refer to the docs of the underlying implementation for more
|
||||||
// information.
|
// information.
|
||||||
type PeerMetadata interface {
|
type PeerMetadata interface {
|
||||||
// Get/Put is a simple registry for other peer-related key/value pairs.
|
// 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
|
// If we find something we use often, it should become its own set of
|
||||||
// methods. this is a last resort.
|
// methods. This is a last resort.
|
||||||
Get(p peer.ID, key string) (interface{}, error)
|
Get(p peer.ID, key string) (interface{}, error)
|
||||||
Put(p peer.ID, key string, val 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.
|
// AddrBook holds the multiaddrs of peers.
|
||||||
type AddrBook interface {
|
type AddrBook interface {
|
||||||
|
|
||||||
// AddAddr calls AddAddrs(p, []ma.Multiaddr{addr}, ttl)
|
// AddAddr calls AddAddrs(p, []ma.Multiaddr{addr}, ttl)
|
||||||
AddAddr(p peer.ID, addr ma.Multiaddr, ttl time.Duration)
|
AddAddr(p peer.ID, addr ma.Multiaddr, ttl time.Duration)
|
||||||
|
|
||||||
@ -212,12 +214,14 @@ type KeyBook interface {
|
|||||||
// AddPrivKey stores the private key of a peer.
|
// AddPrivKey stores the private key of a peer.
|
||||||
AddPrivKey(peer.ID, ic.PrivKey) error
|
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
|
PeersWithKeys() peer.IDSlice
|
||||||
|
|
||||||
|
// RemovePeer removes all keys associated with a peer.
|
||||||
|
RemovePeer(peer.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Metrics is just an object that tracks metrics
|
// Metrics tracks metrics across a set of peers.
|
||||||
// across a set of peers.
|
|
||||||
type Metrics interface {
|
type Metrics interface {
|
||||||
// RecordLatency records a new latency measurement
|
// RecordLatency records a new latency measurement
|
||||||
RecordLatency(peer.ID, time.Duration)
|
RecordLatency(peer.ID, time.Duration)
|
||||||
@ -225,6 +229,9 @@ type Metrics interface {
|
|||||||
// LatencyEWMA returns an exponentially-weighted moving avg.
|
// LatencyEWMA returns an exponentially-weighted moving avg.
|
||||||
// of all measurements of a peer's latency.
|
// of all measurements of a peer's latency.
|
||||||
LatencyEWMA(peer.ID) time.Duration
|
LatencyEWMA(peer.ID) time.Duration
|
||||||
|
|
||||||
|
// RemovePeer removes all metrics stored for a peer.
|
||||||
|
RemovePeer(peer.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProtoBook tracks the protocols supported by peers.
|
// ProtoBook tracks the protocols supported by peers.
|
||||||
@ -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 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.
|
// If the returned error is not nil, the result is indeterminate.
|
||||||
FirstSupportedProtocol(peer.ID, ...string) (string, error)
|
FirstSupportedProtocol(peer.ID, ...string) (string, error)
|
||||||
|
|
||||||
|
// RemovePeer removes all protocols associated with a peer.
|
||||||
|
RemovePeer(peer.ID)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user