Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(iroh-net): Remove need for relay info in best_addr #2579

Merged
merged 2 commits into from
Aug 2, 2024

Conversation

flub
Copy link
Contributor

@flub flub commented Aug 2, 2024

Description

This moves metrics for when switches between direct connections and
relayed connections to the NodeState. This is after all where this
decision is made. BestAddr only knows about the best UDP address, it
has no business keeping track of relays.

Cleaning this up enables further refactoring of BestAddr and PathState
which need to improve because they depend on each other, but are
hindered by the relay state sneaking into there.

Breaking Changes

None

Notes & open questions

These metrics ignore the fact that we have mixed as a possibility so
over-simplify the situation. This makes the logic to increment them
complex, which in turn makes it no one will really know what they
mean.

I need this to move on with #2546 so don't really want to get into
designing our metrics though. I believe this way the keep the same
behaviour.

Change checklist

  • Self-review.
  • Documentation updates following the style guide, if relevant.
  • Tests if relevant.
  • All breaking changes documented.

@flub flub requested a review from Arqu August 2, 2024 12:59
Copy link

github-actions bot commented Aug 2, 2024

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

Last updated: 2024-08-02T15:08:22Z

Copy link
Collaborator

@Arqu Arqu left a comment

Choose a reason for hiding this comment

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

Nice little state machine you got there :D

Comment on lines 308 to 330
// Update some metrics
if matches!(prev_typ, ConnectionType::Direct(_)) {
inc!(MagicsockMetrics, num_direct_conns_removed);
}
if matches!(typ, ConnectionType::Direct(_)) {
inc!(MagicsockMetrics, num_direct_conns_added);
}
if matches!(typ, ConnectionType::Relay(_) | ConnectionType::Mixed(_, _))
&& !matches!(
prev_typ,
ConnectionType::Relay(_) | ConnectionType::Mixed(_, _)
)
{
inc!(MagicsockMetrics, num_relay_conns_added);
}
if matches!(typ, ConnectionType::Direct(_) | ConnectionType::None)
&& matches!(
prev_typ,
ConnectionType::Relay(_) | ConnectionType::Mixed(_, _)
)
{
inc!(MagicsockMetrics, num_relay_conns_removed);
}
Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't mind if this were refactored into a match (prev_typ, typ) expression.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Be careful what you wish for... This version is huge and contains a whole bunch of states that are unreachable. Admittedly the if version has to be read backwards, where you think about what conditions are needed for a certain state. So I guess the big match is less of a head-twister.

Copy link
Member

Choose a reason for hiding this comment

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

I'd didn't necessarily want it to be an exhaustive match 😅 so yeah I guess I have to be careful in what I wish for haha!
Basically, having a last _ => {} case would've been fine by me :)

@flub flub enabled auto-merge August 2, 2024 15:11
@flub flub added this pull request to the merge queue Aug 2, 2024
Merged via the queue into main with commit d662bfc Aug 2, 2024
28 checks passed
@flub flub deleted the flub/best-addr-no-relay branch August 2, 2024 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants