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

feat(iroh-net): Add a Watchable struct for use in the Endpoint API #2806

Merged
merged 32 commits into from
Dec 13, 2024

Conversation

flub
Copy link
Contributor

@flub flub commented Oct 15, 2024

Description

This implements a Watchable struct and a Watcher which provides access to the watched value in several ways, including some streams.

Breaking Changes

  • iroh::Endpoint::conn_type_stream is renamed to iroh::Endpoint::conn_type and returns Result<Watcher<ConnectionType>> instead of Result<ConnectionTypeStream>
    To migrate, use endpoint.conn_type()?.stream() instead of endpoint.conn_type_stream()?.
  • iroh::Endpoint::home_relay now returns Watcher<Option<RelayUrl>> instead of Option<RelayUrl>.
    To migrate, use endpoint.home_relay().get()? instead of endpoint.home_relay().
  • removed iroh::Endpoint::watch_home_relay
    To migrate, use endpoint.home_relay().initialized().await? instead of endpoint.watch_home_relay().next().await and
    use endpoint.home_relay().stream() instead of endpoint.watch_home_relay().next().await.
  • removed DirectAddrsStream and ConnTypeStream.
    Use iroh::watchable::WatcherStream for as named types instead.

Change checklist

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

matheus23 and others added 2 commits October 1, 2024 17:41
@flub flub requested a review from dignifiedquire October 15, 2024 15:01
Copy link

github-actions bot commented Oct 15, 2024

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

Last updated: 2024-12-13T09:40:10Z

@mepi262
Copy link

mepi262 commented Nov 8, 2024

@flub
Any update on this pull request?

@flub
Copy link
Contributor Author

flub commented Nov 8, 2024

@mepi262 the current implementation is racy and needs fixing.

What makes you interested in this?

@mepi262
Copy link

mepi262 commented Nov 9, 2024

The reason in which I'm interested is followings.

  • I'm very much looking forward to the iroh v1.0.0.
  • This pull request is related to the issue, which is contained milestone v1.0.0
  • I'm worry about whether this pull request is merged, because this pull request has not been active since last month.
    • People forget memory
    • Merging pull request is difficult when time has gone, because of risk of conflict.

I wish you good health, good luck and success.

@matheus23
Copy link
Contributor

Made some changes:

  • Added loom to watchable.rs (conditionally on the iroh_loom cfg)
  • Added a loom-based test that was failing in exactly the way @flub predicted
  • Fixed the race condition
  • Changed wakers from using a RwLock to using a Mutex, because we were only using RwLock::write
  • Removed Either by making initialized simpler

For anyone who's interested in running the loom test, you get some fun output like this:

LOOM_LOG=trace RUSTFLAGS="--cfg iroh_loom" cargo test --package iroh-net --lib -- util::watchable::tests::test_initialized_always_resolves --exact --nocapture

@matheus23
Copy link
Contributor

matheus23 commented Nov 21, 2024

Should we (well, I) maybe address #2860 (comment) in here too?

What's the relationship between Endpoint::conn_type_stream and Connection::remote_address? It seems like remote_address should be deprecated and replaced with a method that returns a ConnectionType based on the current state of the connection.

Copy link
Contributor Author

@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.

Looks good! Any reason this is still draft?

iroh-net/src/util/watchable.rs Outdated Show resolved Hide resolved
iroh-net/src/util/watchable.rs Outdated Show resolved Hide resolved
iroh-net/src/util/watchable.rs Outdated Show resolved Hide resolved
iroh-net/src/util/watchable.rs Outdated Show resolved Hide resolved
iroh-net/src/util/watchable.rs Outdated Show resolved Hide resolved
iroh-net/src/util/watchable.rs Outdated Show resolved Hide resolved
iroh-net/src/util/watchable.rs Outdated Show resolved Hide resolved
iroh-net/src/util/watchable.rs Outdated Show resolved Hide resolved
iroh-net/src/util/watchable.rs Outdated Show resolved Hide resolved
iroh-net/src/util/watchable.rs Outdated Show resolved Hide resolved
@flub
Copy link
Contributor Author

flub commented Nov 22, 2024

Should we (well, I) maybe address #2860 (comment) in here too?

What's the relationship between Endpoint::conn_type_stream and Connection::remote_address? It seems like remote_address should be deprecated and replaced with a method that returns a ConnectionType based on the current state of the connection.

I think this PR just introduces the watchable, follow-up PRs can start using it.

@matheus23
Copy link
Contributor

Looks good! Any reason this is still draft?

I think this PR just introduces the watchable, follow-up PRs can start using it.

Ah okay. Well my plan was to learn from the refactor of making iroh-net use this new watchable.

And I'm already finding things. E.g. do we want the Watchable to have shutdown functionality.

So, I'm still learning!
In any case, I'll split up the PR into watchable introduction & the refactor anyways.

@flub
Copy link
Contributor Author

flub commented Nov 22, 2024

Looks good! Any reason this is still draft?

I think this PR just introduces the watchable, follow-up PRs can start using it.

Ah okay. Well my plan was to learn from the refactor of making iroh-net use this new watchable.

And I'm already finding things. E.g. do we want the Watchable to have shutdown functionality.

So, I'm still learning! In any case, I'll split up the PR into watchable introduction & the refactor anyways.

Makes sense as well. No big deal if you'd like to do this all in one place.

Cargo.toml Outdated Show resolved Hide resolved
@matheus23 matheus23 self-assigned this Dec 10, 2024
@matheus23 matheus23 added this to the v0.30.0 milestone Dec 10, 2024
Copy link

github-actions bot commented Dec 10, 2024

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: 5066045

@matheus23 matheus23 marked this pull request as ready for review December 11, 2024 17:29
Copy link
Contributor Author

@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.

LGTM

/// # Errors
///
/// Will error if we do not have any address information for the given `node_id`.
pub fn conn_type_stream(&self, node_id: NodeId) -> Result<ConnectionTypeStream> {
self.msock.conn_type_stream(node_id)
pub fn conn_type(&self, node_id: NodeId) -> Result<Watcher<ConnectionType>> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably out of scope for this PR. But what would folks think of changing fn conn_type(node_id) into fn network_path(node_id)? And Also rename ConnectionType into NetworkPath.

This name has always bothered me a bit, I'm not sure why. Maybe because this doesn't actually have much to do with a Connection, it is on a different level as shown by the fact this is an Endpoint API. But this is subtle and not very clear.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the idea :)
I have a bunch of follow-up PR ideas brewing anyways, maybe I'll just add them to the follow-up.

Copy link
Contributor

@matheus23 matheus23 left a comment

Choose a reason for hiding this comment

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

Turning @flub's "LGTM" into a github-approved LGTM 🙃

@matheus23 matheus23 added this pull request to the merge queue Dec 13, 2024
Merged via the queue into main with commit 1a79a19 Dec 13, 2024
25 of 26 checks passed
@dignifiedquire dignifiedquire deleted the flub/watchable branch December 13, 2024 12:49
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