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): add subscription stream to watch all discovery results #3181

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Frando
Copy link
Member

@Frando Frando commented Feb 12, 2025

Description

Implements a subscription stream to watch all items retrieved through discovery services. the stream includes both nodes discovered actively (through Discovery::resolve, which is invoked when Endpoint::connect is called for nodes we don't have addressing info), and nodes discovered passively (through Discovery::subscribe, which is only implemented for the local swarm discovery).

Uses tokio::sync:.broadcast internally (but without exposing this in the public API) which fits well here I think: if a consumer is too slow in processing the stream, it will miss events but can still continue.

Currently the capacity of the broadcast channel is hardcoded to 128. We could also expose this as a setting on the endpoint builder, not sure if there is a default that fits everything.

Breaking Changes

Notes & open questions

Change checklist

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

@Frando Frando changed the title feat(iroh): watch discovery feat(iroh): add subscription stream to watch all discovery results Feb 12, 2025
@Frando Frando force-pushed the feat/discovery-watch branch from ca929db to efb9410 Compare February 12, 2025 13:58
Copy link

github-actions bot commented Feb 12, 2025

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

Last updated: 2025-02-18T22:22:20Z

Copy link

github-actions bot commented Feb 12, 2025

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

Copy link
Contributor

@ramfox ramfox left a comment

Choose a reason for hiding this comment

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

Oh very cool. So the idea here is not to mess with the Discovery trait or impls at all. I think this is a good way to handle it, personally.

@@ -2330,6 +2339,7 @@ impl Actor {
}) {
warn!(?discovery_item.node_addr, "unable to add discovered node address to the node map: {e:?}");
}
self.msock.discovery_subscribers.send(discovery_item);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm assuming the "lagging" concept will prevent this from ever locking/hanging correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes exactly, this is non-blocking. If the broadcast channel is full because a slow subscriber hasn't polled fast enough, the oldest item is dropped and the slow subscriber gets a Lagged event next before continuing from the oldest still available item.


impl DiscoverySubscribers {
pub(crate) fn new() -> Self {
// TODO: Make capacity configurable from the endpoint builder?
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather avoid this if possible. We don't want too many crazy knobs that no one understands in the endpoint builder.

/// [`Discovery::subscribe`], which e.g. [`LocalSwarmDiscovery`] does.
///
/// The stream does not yield information about nodes that are added manually to the endpoint's
/// addressbook by calling [`Endpoint::add_node_addr`] or by supplying a full [`NodeAddr`] to
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think should happen when StaticProvider::add_node_addr is called? Should it show up here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question. I'm not sure?

Right now they would show up in the discovery stream only once you connect to a node added to the StaticProvider, but not at the time you add them to the StaticProvider.

@Frando Frando force-pushed the feat/discovery-watch branch from 0894cb9 to c28273e Compare February 18, 2025 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🏗 In progress
Development

Successfully merging this pull request may close these issues.

3 participants