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: streamline local endpoint discovery #1847

Merged
merged 9 commits into from
Dec 12, 2023

Conversation

dignifiedquire
Copy link
Contributor

To avoid the issues seen when setting up an iroh-net node, this allows to dynamically subscribe to endpoint changes. It also removes the other callbacks on the magicsock, which where unused.

iroh-net/src/magic_endpoint.rs Outdated Show resolved Hide resolved
iroh-net/src/magicsock.rs Outdated Show resolved Hide resolved
iroh-net/src/magicsock.rs Outdated Show resolved Hide resolved
iroh-net/src/magicsock.rs Outdated Show resolved Hide resolved
@@ -380,6 +352,11 @@ impl MagicEndpoint {
self.msock.local_endpoints().await
}

/// Returns the next non empty version of `local_endpoints`.
pub async fn ensure_local_endpoints(&self) -> Result<Vec<config::Endpoint>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

why not build this into the local_endpoints() call instead of adding a new API? The first time it is called it could ensure that it waits - it already is async.

The address-related API of MagicEndpoint is already large, and this addition does not make it clearer. This is supposed to be the high-level-easy-to-use API...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, agreed, fixed

@Septias
Copy link
Contributor

Septias commented Dec 9, 2023

How is progress here? This is kind of a blocker for deltachat/deltachat-core-rust#5041

@@ -106,35 +105,17 @@ async fn main() -> anyhow::Result<()> {
// init a cell that will hold our gossip handle to be used in endpoint callbacks
let gossip_cell: OnceCell<Gossip> = OnceCell::new();
Copy link
Contributor

Choose a reason for hiding this comment

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

unused variable I guess

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, looks like it is .set() and then dropped.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@link2xt
Copy link
Contributor

link2xt commented Dec 10, 2023

How is progress here? This is kind of a blocker for deltachat/deltachat-core-rust#5041

This is a nicer API, but dc core PR can use existing one? The real blocker is #1831 because we don't want to depend on central DERP servers, but no rush, we are not planning to merge deltachat/deltachat-core-rust#5041 this month.

To avoid the issues seen when setting up an `iroh-net` node, this allows to dynamically subscribe to endpoint changes.
It also removes the other callbacks on the magicsock, which where unused.
@dignifiedquire dignifiedquire force-pushed the refactor-improved-startup branch from 891077d to 6b3d8af Compare December 12, 2023 12:21
{
// check if we have some value already
let current_value = self.inner.endpoints.read();
if !current_value.is_empty() {
Copy link
Contributor

Choose a reason for hiding this comment

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

is it ever possible this will never contain an endpoint? That would probably already be a bug so just fine to hang indefinitely?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is expected on startup for this to be empty

.update(DiscoveredEndpoints::new(eps))
.is_ok();
if updated {
let eps = self.inner.endpoints.read();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this code is fine. But seeing .read() here did make me go round and check all the docs on what exactly we're reading, who we're notifying and why we must have a lock. Instinctively I would have cloned the endpoints before storing and then worked of the clone. It's much of a muchness though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did it this way, to avoid having to clone in all cases, and only if we actually need to do so

}

/// Waits for local endpoints to change and returns the new ones.
pub async fn local_endpoints_change(&self) -> Result<Vec<config::Endpoint>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't help but bikeshed, something about _change doesn't feel right. It's almost like you want to return a Watchable<Vec<config::Endpoint>>, but that would expose a foreign crate on the API which is no good.

Maybe just local_endpoints_updated() is better already? I think the tense of change is also bothering me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

both changed and updated sound to me like it should return a boolean to me

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe next_local_endpoints, matching the stream api, as it behaves similarly like that

Copy link
Contributor

Choose a reason for hiding this comment

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

next_local_endpoints gives me the expectation of an Option... naming is hard. maybe putting the verb at the front is better? updated_local_endpoints

let's not make this a blocker, it's not worth it. and whatever we'll come up with now probably won't be great anyway. maybe someone will realise a great name while using it and then we can change the name as long as we're not 1.0.

@dignifiedquire dignifiedquire added this pull request to the merge queue Dec 12, 2023
Merged via the queue into main with commit cb20bb8 Dec 12, 2023
27 checks passed
@dignifiedquire dignifiedquire deleted the refactor-improved-startup branch December 12, 2023 17:08
matheus23 pushed a commit that referenced this pull request Nov 14, 2024
To avoid the issues seen when setting up an `iroh-net` node, this allows
to dynamically subscribe to endpoint changes. It also removes the other
callbacks on the magicsock, which where unused.
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.

5 participants