Skip to content

feat(iroh)!: make direct_addresses always be initialised#3505

Merged
dignifiedquire merged 4 commits intomainfrom
feat-better-direct-addrs
Oct 7, 2025
Merged

feat(iroh)!: make direct_addresses always be initialised#3505
dignifiedquire merged 4 commits intomainfrom
feat-better-direct-addrs

Conversation

@dignifiedquire
Copy link
Copy Markdown
Contributor

Description

Turns out we just need to call the init early enough.

Thanks to @flub for reminding me of this

Breaking Changes

  • changed
    • iroh::Endpoint::watch_node_addr now returns a watchable for NodeAddr not Option<NodeAddr>

Notes & open questions

Currently this means that in wasm we have a different signature for watch_node_addr() because it can be empty, need some feedback on how to solve this

@dignifiedquire dignifiedquire requested review from flub and ramfox October 7, 2025 13:12
@dignifiedquire dignifiedquire self-assigned this Oct 7, 2025
@dignifiedquire dignifiedquire added this to the v0.93.0 milestone Oct 7, 2025
@n0bot n0bot bot added this to iroh Oct 7, 2025
@github-project-automation github-project-automation bot moved this to 🏗 In progress in iroh Oct 7, 2025
@github-actions
Copy link
Copy Markdown

github-actions bot commented Oct 7, 2025

Documentation for this PR has been generated and is available at: https://n0-computer.github.io/iroh/pr/3505/docs/iroh/

Last updated: 2025-10-07T17:05:16Z

@Frando
Copy link
Copy Markdown
Member

Frando commented Oct 7, 2025

Currently this means that in wasm we have a different signature for watch_node_addr() because it can be empty, need some feedback on how to solve this

Just let it return an empty addr? (I.e. a NodeAddr with only the node id set). That's much preferable than a different signature IMO

@github-actions
Copy link
Copy Markdown

github-actions bot commented Oct 7, 2025

Netsim report & logs for this PR have been generated and is available at: LOGS
This report will remain available for 3 days.

Last updated for commit: 3bab5fc

Copy link
Copy Markdown
Contributor

@flub flub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The effect of this is lovely! Amazing to see this work out. Though I don't understand how we make up the addresses, but that hasn't changed here so not a blocker.

Would love if the doc comment was updated though to explain what you can rely on. And maybe also what you can not rely on.

/// - the endpoint changes its preferred relay server
/// - more addresses are discovered for this endpoint
pub fn node_addr(&self) -> NodeAddr {
let node_id = self.node_id();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first paragraph of the doc comment needs updating I think. It could describe what you'd expect to be in the direct addresses immediately, but that they -and should- still change as discovered direct addresses become available.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

.ip_bind_addrs()
.iter()
.copied()
.zip(self.ip_local_addrs())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't follow why these two iters form pairs? Are they even guaranteed to be the same length?

update: oh, this is moved code. Probably fine then, but I wouldn't mind more comments because I don't understand what it's trying to do.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added some more comments

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, they help! it makes sense now

fn collect_local_addresses(
&self,
netmon_watcher: &mut n0_watcher::Direct<netmon::State>,
addrs: &mut BTreeMap<SocketAddr, DirectAddrType>,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoa, I'm very not used to seeing an "out" parameter in rust code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it actually works out quite nice in rust if you need it, and makes your code go brr ;P

@dignifiedquire dignifiedquire force-pushed the feat-better-direct-addrs branch from 2cb927e to 91a706a Compare October 7, 2025 16:31
@dignifiedquire dignifiedquire added this pull request to the merge queue Oct 7, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 7, 2025
@dignifiedquire dignifiedquire added this pull request to the merge queue Oct 7, 2025
Merged via the queue into main with commit 33aca18 Oct 7, 2025
29 checks passed
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in iroh Oct 7, 2025
@ramfox ramfox deleted the feat-better-direct-addrs branch October 7, 2025 17:54
relay_url,
direct_addresses,
}
self.watch_node_addr().get()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of gets us back to the "why have two methods?" question. This one is now pretty trivial.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though I do appreciate this way people don't have to learn about the Watcher trait.

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.

3 participants