Skip to content

Conversation

@Frando
Copy link
Member

@Frando Frando commented Nov 10, 2025

Description

Currently the Connection stores a Watchable for the open and selected paths. This means, though, that a watcher stream for the open paths will only close once the last connection is dropped, not once the connection is closed. That is bad API and will lead to confusion.

In an initial version, I swapped the Watchables for a n0_watcher::Map<(Direct, Direct)> but this increases the size of the Connection struct from ~80 to ~700 bytes, because it would store both the two unmapped values and the mapped final value inline. It is also completely unneeded, because we'd clone out the watcher anyways on Connection::watch and get or stream on the watcher would refetch the value.

Instead, this now uses n0-computer/n0-watcher#31 to only store a weak pointer to the watchable's shared state without keeping it alive, and then creates the PathInfos on demand from that. The stats are now fetched while iterating, so if you're e.g. only checking the number of paths, the stats won't be fetched at all.

We fetch the paths through upgrading the handle in the next method, so that we can return None if the connection was dropped in the meantime (the alternative would be a fallible PathInfo::stats method)

Breaking Changes

Notes & open questions

Change checklist

  • Self-review.
  • Documentation updates following the style guide, if relevant.
  • Tests if relevant.
  • All breaking changes documented.
    • List all breaking changes in the above "Breaking Changes" section.
    • Open an issue or PR on any number0 repos that are affected by this breaking change. Give guidance on how the updates should be handled or do the actual updates themselves. The major ones are:

@Frando Frando force-pushed the Frando/mp-smaller-watchers branch from d953b42 to 959ddaf Compare November 10, 2025 12:55
@n0bot n0bot bot added this to iroh Nov 10, 2025
@github-project-automation github-project-automation bot moved this to 🏗 In progress in iroh Nov 10, 2025
@Frando Frando changed the base branch from Frando/mp-async-register to feat-multipath November 10, 2025 13:30
Frando added a commit that referenced this pull request Nov 11, 2025
## Description

Alternative to #3631

Replaces the `Watchable`s for path changes on the `Connection` with a
boxed `Watcher`. The watcher is boxed because it would increase the
`Connection` struct size significantly otherwise because the
mapped-and-joined watcher with a `SmallVec` of `PathInfo` inside is ~600
bytes atm.

The benefit of storing a `Watcher` and not a `Watchable` is that the
watcher streams now close once the EndpointStateActor drops the state
for the connection, which it does after the connection is closed.

Also adds a test for path watching, including testing that the streams
now close when the connection closes.

## Breaking Changes

<!-- Optional, if there are any breaking changes document them,
including how to migrate older code. -->

## Notes & open questions

<!-- Any notes, remarks or open questions you have to make about the PR.
-->

## Change checklist
<!-- Remove any that are not relevant. -->
- [ ] Self-review.
- [ ] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [ ] Tests if relevant.
- [ ] All breaking changes documented.
- [ ] List all breaking changes in the above "Breaking Changes" section.
- [ ] Open an issue or PR on any number0 repos that are affected by this
breaking change. Give guidance on how the updates should be handled or
do the actual updates themselves. The major ones are:
    - [ ] [`quic-rpc`](https://github.com/n0-computer/quic-rpc)
    - [ ] [`iroh-gossip`](https://github.com/n0-computer/iroh-gossip)
    - [ ] [`iroh-blobs`](https://github.com/n0-computer/iroh-blobs)
    - [ ] [`dumbpipe`](https://github.com/n0-computer/dumbpipe)
    - [ ] [`sendme`](https://github.com/n0-computer/sendme)
@Frando
Copy link
Member Author

Frando commented Nov 12, 2025

Closing this - n0-computer/n0-watcher#31 is likely not going to be merged and #3632 was merged for now.

@Frando Frando closed this Nov 12, 2025
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in iroh Nov 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants