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

refactor(iroh-net): Make derp_map not an option in MagicEndpoint #1363

Merged
merged 10 commits into from
Aug 28, 2023

Conversation

flub
Copy link
Contributor

@flub flub commented Aug 16, 2023

Description

This changes the public API to set the derp map to enable_derp(derp_map)
and disable_derp(). As part of this the DerpMap itself is changed so it
can only be constructed as a valid DerpMap and consistency checks are made.
The public endpoints also ensure the derp map is not empty.

Internally this removes the Option from MagicEndpoint::derp_map. An empty
DerpMap is treated the same as a missing DerpMap in all the code so
this is just a noisy indirection.

Notes & open questions

Change checklist

  • Self-review.
  • Documentation updates if relevant.
  • Tests if relevant.

This removes the Option from MagicEndpoint::derp_map.  An empty
DerpMap is treated the same as a missing DerpMap in all the code so
this is just a noisy indirection.
@Arqu
Copy link
Collaborator

Arqu commented Aug 21, 2023

Allowing None gives us the ability to force non-derp connections only and to talk directly through the provided addresses in tickets.

@flub
Copy link
Contributor Author

flub commented Aug 21, 2023

Allowing None gives us the ability to force non-derp connections only and to talk directly through the provided addresses in tickets.

You can still do this by using an empty DerpMap. Though there should probably be a DerpMap::empty() constructor to make this easy and obvious.

@flub
Copy link
Contributor Author

flub commented Aug 21, 2023

Allowing None gives us the ability to force non-derp connections only and to talk directly through the provided addresses in tickets.

You can still do this by using an empty DerpMap. Though there should probably be a DerpMap::empty() constructor to make this easy and obvious.

oh wait, the public API still has it as an option, but with a TODO to consider this.

So yes the question is both about the internal and external api. I think internal it makes sense. External maybe too and I could like a DerpMap::emtpy() for this.

@dignifiedquire
Copy link
Contributor

I would like to see sth like this

enum Derp {
  Enabled(DerpMap), // Constructor checks that this is not empty and the node checks that at least the local region id is available
  Disabled,
}

@flub
Copy link
Contributor Author

flub commented Aug 22, 2023

I would like to see sth like this

enum Derp {
  Enabled(DerpMap), // Constructor checks that this is not empty and the node checks that at least the local region id is available
  Disabled,
}

So the only really public API is the MagicEndpointBuilder::derp_map(mut self, derp_map: Option<DerpMap) call. Are you saying this for there or for internal as well?

This PR started as just acknowledging that internally the code does not ever distinguish a None DerpMap from an empty one, it does eventually end up as an empty one. So it just peeled back some layers and simplified this. As this is internal I'm largely fine with that.

I think switching internally to this Disabled enum will be a lot more work. Maybe the code will end up being clearer, maybe not. Hard to say ahead of time.

@dignifiedquire
Copy link
Contributor

for the public api I would do sth like disable_derp() and enable_derp(map) which forces map to not be empty

@dignifiedquire
Copy link
Contributor

you are right internal is annoying and we should just drop the optiob there for now

@flub
Copy link
Contributor Author

flub commented Aug 23, 2023

I've now updated the public API to be MagicEndpointBuilder::enable_derp(derp_map) and .disable_derp(). This touches a surprising number of places.

I've moved validation of the DerpMap into the constructors itself, the constructor is basically DerpMap::from_regions which is now fallible. This again touches a lot of places but ensures that if the type exists we have a valid one, which was nicer than having a separate validation function.

(I tried having this constructor in TryFrom<T: Into<Iterarator<Item = DerpRegion>>> since the old one was in such a From, but I lost that fight with the compiler)

@flub flub requested a review from dignifiedquire August 24, 2023 08:15
@dignifiedquire
Copy link
Contributor

can you update the Node::builder api as well, to match this new public api?

This is much more consistent.

Note that this also changes the default derp servers.
@flub
Copy link
Contributor Author

flub commented Aug 24, 2023

can you update the Node::builder api as well, to match this new public api?

oh yes, good call. sorry to gloss over that at first.

Note that I also changed the default DerpMap used in iroh::Node::builder: this was also empty originally and now uses defaults::default_derp_map.

flub added 2 commits August 24, 2023 12:33
An empty DerpMap is valid so can be constructed.  But in the public
builder APIs we still want to reject this.
@flub flub enabled auto-merge August 24, 2023 11:30
@b5 b5 added this to the v0.6.0-alpha: Sync! milestone Aug 24, 2023
@flub flub added this pull request to the merge queue Aug 24, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 24, 2023
@flub flub added this pull request to the merge queue Aug 24, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 24, 2023
@flub flub added this pull request to the merge queue Aug 24, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 24, 2023
@flub flub added this pull request to the merge queue Aug 24, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 24, 2023
@flub flub enabled auto-merge August 25, 2023 10:02
@flub flub added this pull request to the merge queue Aug 25, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 25, 2023
@flub flub added this pull request to the merge queue Aug 25, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 25, 2023
@flub flub added this pull request to the merge queue Aug 25, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 25, 2023
@flub flub added this pull request to the merge queue Aug 25, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 25, 2023
@flub flub added this pull request to the merge queue Aug 25, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 25, 2023
@flub flub added this pull request to the merge queue Aug 28, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 28, 2023
@flub flub enabled auto-merge August 28, 2023 13:24
@flub flub added this pull request to the merge queue Aug 28, 2023
Merged via the queue into main with commit 93147ac Aug 28, 2023
@flub flub deleted the flub/derpmap-no-option branch August 28, 2023 13:52
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.

4 participants