Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(iroh-net)!: DiscoveredDirectAddrs need to update the timestamp (#…
…2808) ## Description DiscoverdDirectAddrs has a timestamp of when it was last changed, which is used to decide if the direct addr information is recent enough to use in call-me-maybe messages. However when it was updated this timestamp was not included in the comparison to see if there were changes, so that watchers would not get updates when the direct addresses did not change. Unfortunately this meant the timestamp also never updated and the DiscoveredDirectAddrs was always considered out of date (unless there were changes in the discovered addresses). This fixes this by putting only the DirectAddrs in the watcher. It does a few other improvements: - Moves all logic about DiscoveredDirectAddrs into one place. This could be split out to a module now if desired. - Tidies up the code which creates the DirectAddrs from the portmapper, netcheck and the local addresses. Again this is just a first pass in cleaning up this code, there is so much more that could be done. ## Breaking Changes * `iroh_net::Endpoint::direct_addresses` now returns a stream yielding Items of `BTreeSet<DirectAddr>` instead of `Vec<DirectAddr>`. * `iroh_base::node_addr::NodeAddr::from_parts` now takes a `impl IntoIterator<Item = DirectAddr>` instead of `Vec<DirectAddr>`. But since `Vec` implements `IntoIterator` that is not really a breaking change. ## Notes & open questions The crux of this fix is moving from `Watchable<DiscoveredDirectAddresses>` to `DiscoveredDirectAddresses::addrs` being `Watchable<Vec<DirectAddr>>` instead of the whole struct being watchable. I could split the refactoring of store_direct_addr_update and the renaming of it's related functions into a separate PR in front of this bugfix if desired. I had to change that code because of the format change from `Vec<DirectAddrs>` to `BTreeSet<DirectAddr>` and it was just way clearer doing it with the refactoring. As indicated in the (already existing) comments that whole direct address updating logic can still be more refactored and improved. But many small steps is how we improve. I went very opinionated on the imports... apologies. ## Change checklist - [x] Self-review. - [x] 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. - [x] Tests if relevant. - [x] All breaking changes documented. --------- Co-authored-by: Asmir Avdicevic <asmir.avdicevic64@gmail.com> Co-authored-by: Divma <26765164+divagant-martian@users.noreply.github.com> Co-authored-by: Diva M <divma@protonmail.com>
- Loading branch information