mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-15 19:11:23 +00:00
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:
@ -34,6 +34,10 @@ use void::Void;
|
||||
|
||||
const MAX_MESSAGE_SIZE_BYTES: usize = 4096;
|
||||
|
||||
pub const PROTOCOL_NAME: &[u8; 14] = b"/ipfs/id/1.0.0";
|
||||
|
||||
pub const PUSH_PROTOCOL_NAME: &[u8; 19] = b"/ipfs/id/push/1.0.0";
|
||||
|
||||
/// Substream upgrade protocol for `/ipfs/id/1.0.0`.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct IdentifyProtocol;
|
||||
@ -104,7 +108,7 @@ impl UpgradeInfo for IdentifyProtocol {
|
||||
type InfoIter = iter::Once<Self::Info>;
|
||||
|
||||
fn protocol_info(&self) -> Self::InfoIter {
|
||||
iter::once(b"/ipfs/id/1.0.0")
|
||||
iter::once(PROTOCOL_NAME)
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,7 +140,7 @@ impl<T> UpgradeInfo for IdentifyPushProtocol<T> {
|
||||
type InfoIter = iter::Once<Self::Info>;
|
||||
|
||||
fn protocol_info(&self) -> Self::InfoIter {
|
||||
iter::once(b"/ipfs/id/push/1.0.0")
|
||||
iter::once(PUSH_PROTOCOL_NAME)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user