misc/metrics: Track # connected nodes supporting specific protocol (#2734)

* misc/metrics: Explicitly delegate event recording to each recorder

This allows delegating a single event to multiple `Recorder`s. That enables e.g. the
`identify::Metrics` `Recorder` to act both on `IdentifyEvent` and `SwarmEvent`. The latter enables
it to garbage collect per peer data on disconnects.

* protocols/dcutr: Expose PROTOCOL_NAME

* protocols/identify: Expose PROTOCOL_NAME and PUSH_PROTOCOL_NAME

* protocols/ping: Expose PROTOCOL_NAME

* protocols/relay: Expose HOP_PROTOCOL_NAME and STOP_PROTOCOL_NAME

* misc/metrics: Track # connected nodes supporting specific protocol

An example metric exposed with this patch:

```
libp2p_identify_protocols{protocol="/ipfs/ping/1.0.0"} 10
```

This implies that 10 of the currently connected nodes support the ping protocol.
This commit is contained in:
Max Inden
2022-07-15 09:16:03 +02:00
committed by GitHub
parent 7c8a97739f
commit d4f8ec2d48
21 changed files with 259 additions and 78 deletions

View File

@ -57,8 +57,8 @@ use std::{
note = "Use re-exports that omit `Ping` prefix, i.e. `libp2p::ping::Config` etc"
)]
pub use self::{
Config as PingConfig, Event as PingEvent, Failure as PingFailure, Result as PingResult,
Success as PingSuccess,
protocol::PROTOCOL_NAME, Config as PingConfig, Event as PingEvent, Failure as PingFailure,
Result as PingResult, Success as PingSuccess,
};
#[deprecated(since = "0.30.0", note = "Use libp2p::ping::Behaviour instead.")]
pub use Behaviour as Ping;

View File

@ -26,6 +26,8 @@ use rand::{distributions, prelude::*};
use std::{io, iter, time::Duration};
use void::Void;
pub const PROTOCOL_NAME: &[u8; 16] = b"/ipfs/ping/1.0.0";
/// The `Ping` protocol upgrade.
///
/// The ping protocol sends 32 bytes of random data in configurable
@ -55,7 +57,7 @@ impl UpgradeInfo for Ping {
type InfoIter = iter::Once<Self::Info>;
fn protocol_info(&self) -> Self::InfoIter {
iter::once(b"/ipfs/ping/1.0.0")
iter::once(PROTOCOL_NAME)
}
}