Expose connected peer user-agents over RPC - #3780
Conversation
jsdanielh
left a comment
There was a problem hiding this comment.
While I agree that this adds useful data, it only reports data of connected peers while a solution implemented on top of the discovery protocol could allow to relay this information and be able to retrieve versions of connected peers + other observed peers. The complication with this latter approach would be the backwards compatibility
|
|
||
| let identify = identify::Behaviour::new( | ||
| identify::Config::new(IDENTIFY_PROTOCOL.to_string(), public_key) | ||
| .with_agent_version(config.user_agent.clone()), |
There was a problem hiding this comment.
We'd need to disable the peer cache to disallow the behaviour to add new peer addresses that can pollute kad and peer dialing
| .with_agent_version(config.user_agent.clone()), | |
| .with_agent_version(config.user_agent.clone()). | |
| with_cache_size(0), |
| let network_config = NetworkConfig::new( | ||
| identity_keypair, | ||
| peer_contact, | ||
| config.network.user_agent.to_string(), |
There was a problem hiding this comment.
User agent has two issues IMO:
- Contains much more info than what is needed.
- Can be changed from the config file.
| async fn get_address_book(&self) -> RPCResult<Vec<(String, PeerType)>, (), Self::Error>; | ||
|
|
||
| /// Returns user-agent strings announced by connected peers. | ||
| async fn get_peer_user_agents(&self) -> RPCResult<Vec<(String, String)>, (), Self::Error>; |
There was a problem hiding this comment.
We'd need to get this also implemented in the rpc-client
I agree that a discovery-based solution would be more complete, since it could expose versions for connected peers plus observed/discovered peers. It would also be better for network-wide observability. My intent with this PR was narrower: expose only metadata that the local node can directly observe from currently connected peers, without changing discovery semantics or relaying extra data through the network. So the RPC result should be interpreted as “connected peer reported user-agents from this observer node”, not as a full network census. I’m happy to adjust the naming/docs to make that limitation explicit, e.g. getConnectedPeers / “connected peers only”, and document that user-agent is self-reported. If you think the discovery-based approach is the preferred long-term direction, I see two possible paths: keep this PR as a small first step for local observability of direct peers; |
What
This PR wires the configured Nimiq user-agent into libp2p identify and exposes the user-agents reported by connected peers through RPC.
It adds:
/nimiq/identify/0.0.1)agent_versionstrings keyed byPeerIdgetPeerUserAgents, returning(peerId, userAgent)pairsWhy
At the moment the configured
user_agentappears to be local-only from an observer's point of view: it is configured and printed locally, but peer client versions are not available through RPC and did not show up in TRACE logs during a quick experiment.For network observability tools such as public node maps, exposing reported peer versions makes it possible to show:
The user-agent should still be treated as self-reported metadata, similar to browser user-agents.
Verification
Ran locally:
cargo check -p nimiq-network-libp2p --all-featurescargo check -p nimiq-rpc-interface -p nimiq-rpc-serverBoth completed successfully.