-
Notifications
You must be signed in to change notification settings - Fork 185
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
Conversation
This adds a basic Watchable struct for use on the Endpoint API.
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 |
@flub |
@mepi262 the current implementation is racy and needs fixing. What makes you interested in this? |
The reason in which I'm interested is followings.
I wish you good health, good luck and success. |
Made some changes:
For anyone who's interested in running the loom test, you get some fun output like this:
|
Should we (well, I) maybe address #2860 (comment) in here too?
|
There was a problem hiding this 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?
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 So, I'm still learning! |
Makes sense as well. No big deal if you'd like to do this all in one place. |
…b(crate)` again
There was a problem hiding this 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>> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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 🙃
Description
This implements a
Watchable
struct and aWatcher
which provides access to the watched value in several ways, including some streams.Breaking Changes
iroh::Endpoint::conn_type_stream
is renamed toiroh::Endpoint::conn_type
and returnsResult<Watcher<ConnectionType>>
instead ofResult<ConnectionTypeStream>
To migrate, use
endpoint.conn_type()?.stream()
instead ofendpoint.conn_type_stream()?
.iroh::Endpoint::home_relay
now returnsWatcher<Option<RelayUrl>>
instead ofOption<RelayUrl>
.To migrate, use
endpoint.home_relay().get()?
instead ofendpoint.home_relay()
.iroh::Endpoint::watch_home_relay
To migrate, use
endpoint.home_relay().initialized().await?
instead ofendpoint.watch_home_relay().next().await
anduse
endpoint.home_relay().stream()
instead ofendpoint.watch_home_relay().next().await
.DirectAddrsStream
andConnTypeStream
.Use
iroh::watchable::WatcherStream
for as named types instead.Change checklist