Skip to content

Conversation

@Frando
Copy link
Member

@Frando Frando commented Nov 7, 2025

Description

This has a few minor cleanups without any functional changes in the endpoint state actor:

  • Remove double handle upgrade
  • Add helper function to_transport_addr on the relay mapped addr map
  • Use hash map entry API instead of get and expect
  • Use if let chains to remove a level of indentation

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:

@github-actions
Copy link

github-actions bot commented Nov 7, 2025

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

Last updated: 2025-11-10T09:17:44Z

@n0bot n0bot bot added this to iroh Nov 8, 2025
@github-project-automation github-project-automation bot moved this to 🏗 In progress in iroh Nov 8, 2025
@Frando Frando changed the title refactor: simplify endpoint state refactor: minor cleanups in endpoint state Nov 8, 2025
@Frando Frando requested a review from flub November 10, 2025 08:12
@Frando Frando marked this pull request as ready for review November 10, 2025 08:30
Copy link
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.

Thanks, I think the path_remote helper can be a bit better still but good improvements!

Comment on lines 358 to 359
if let Some(path) = conn.path(PathId::ZERO)
&& let Some(path_remote) = path_remote(&self.relay_mapped_addrs, &path)
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL you can combine let Some(x) bindings like this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes it's really nice. It's quite new, added in 2024 edition.

}
}

fn path_remote(
Copy link
Contributor

Choose a reason for hiding this comment

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

doc comment please.

I've gone back and forth on this. I used to have a helper for this at some point :) But I never like this kind of helper that just takes a bunch of random things by ref.

What about:

impl AddrMap<(RelayUrl, EndpointId), RelayMappedAddr> {
    /// Convert a mapped socket address to a transport addr.
    ///
    /// To map to a [`transports::Addr`] only the [`RelayMappedAddr`] needs to be able to be
    /// looked up.  So we can have this as a helper here.
    fn to_transport_addr(&self, sockaddr: SocketAddr) -> Option<transports::Addr> {
        MultipathMappedAddr::from(sockaddr).to_transport_addr(self)
    }
}

And probably MultipathMappedAddr::to_transport_addr should be removed and merged into this impl. It's just going to sow confusion over there.

Copy link
Contributor

Choose a reason for hiding this comment

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

I've also always been a little on the fence on whether creating the AddrMap was a useful abstraction level. I'm not that sure.

I think now I'd try and make a single AddrMap struct (not trait) that contained both the mapped addrs in a single lock. It would be a much more natural place for this conversion to live. But anyway, we're here now and this isn't the most blocking thing.

Copy link
Member Author

Choose a reason for hiding this comment

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

sgtm! pushed this.

@Frando Frando requested a review from flub November 10, 2025 09:16
@Frando Frando merged commit 7887fb5 into feat-multipath Nov 10, 2025
15 of 28 checks passed
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in iroh Nov 10, 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.

3 participants