feat(identify): allow updating agent_version at runtime - #6576
Open
yexiyue wants to merge 2 commits into
Open
Conversation
`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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Config::agent_versionis cloned into everyHandlerwhen a connection is established, somutating 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 meanstearing down every connection.
This adds
Behaviour::set_agent_version, which writes the new value to the config and notifiesevery established connection through a new
InEvent::AgentVersionChanged. The notification isper connection (
NotifyHandler::One) rather thanNotifyHandler::Any, because a peer may bereachable 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::pushto propagate the change immediately, otherwise peers pick it up with thenext 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, whichdisconnects every peer and interrupts in-flight transfers.
AI Assistance Disclosure
Tools used (required — write
noneif no AI was used): Claude CodeAttestation (required):
Notes & open questions
0.48.0heading, so no version bump isneeded. I will add the
See [PR ...]link once this PR has a number.set_agent_versiondeliberately does not push on its own, mirroring howBehaviour::pushis already an explicit, separate step. Happy to change it to pushautomatically if you would rather have a single call.
master:cargo test -p libp2p-identifypasses (4 unit + 9 smoke,including the new
runtime_agent_version_update),cargo fmt --checkclean, andcargo clippy -p libp2p-identify --all-targetsreports no warnings for this crate.Change checklist