Skip to content

feat(identify): allow updating agent_version at runtime - #6576

Open
yexiyue wants to merge 2 commits into
libp2p:masterfrom
yexiyue:feat/identify-set-agent-version
Open

feat(identify): allow updating agent_version at runtime#6576
yexiyue wants to merge 2 commits into
libp2p:masterfrom
yexiyue:feat/identify-set-agent-version

Conversation

@yexiyue

@yexiyue yexiyue commented Jul 31, 2026

Copy link
Copy Markdown

Description

Config::agent_version is cloned into every Handler when a connection is established, so
mutating the configuration afterwards has no effect on already established connections. The only
way to change the advertised agent version today is to rebuild the Behaviour, which means
tearing down every connection.

This adds Behaviour::set_agent_version, which writes the new value to the config and notifies
every established connection through a new InEvent::AgentVersionChanged. The notification is
per connection (NotifyHandler::One) rather than NotifyHandler::Any, because a peer may be
reachable over several connections at once and each of them holds its own copy of the agent
version.

Setting the currently advertised value is a no-op. The method does not push by itself; combine it
with Behaviour::push to propagate the change immediately, otherwise peers pick it up with the
next periodic identify exchange.

The motivating use case is an application that encodes a user-visible device name into
agent_version. Renaming a device previously required restarting the whole node, which
disconnects every peer and interrupts in-flight transfers.

AI Assistance Disclosure

Tools used (required — write none if no AI was used): Claude Code

Attestation (required):

  • I have read every line of this diff, understand what it does, and can explain it in review.

Notes & open questions

  • The changelog entry is filed under the unreleased 0.48.0 heading, so no version bump is
    needed. I will add the See [PR ...] link once this PR has a number.
  • set_agent_version deliberately does not push on its own, mirroring how
    Behaviour::push is already an explicit, separate step. Happy to change it to push
    automatically if you would rather have a single call.
  • Verified against current master: cargo test -p libp2p-identify passes (4 unit + 9 smoke,
    including the new runtime_agent_version_update), cargo fmt --check clean, and
    cargo clippy -p libp2p-identify --all-targets reports no warnings for this crate.

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

yexiyue added 2 commits August 1, 2026 00:33
`Config::agent_version` is cloned into every `Handler` when a connection is
established, so mutating the configuration afterwards has no effect on already
established connections.

Add `Behaviour::set_agent_version`, which writes the new value to the config
and notifies every established connection through a new
`InEvent::AgentVersionChanged`. The notification is per connection
(`NotifyHandler::One`) because a peer may be reachable over several
connections at once and each of them holds its own copy of the agent version.

Setting the currently advertised value is a no-op. The method does not push by
itself; combine it with `Behaviour::push` to propagate the change immediately,
otherwise peers pick it up with the next periodic identify exchange.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant