-
Notifications
You must be signed in to change notification settings - Fork 211
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
base: main
Are you sure you want to change the base?
Conversation
ca929db
to
efb9410
Compare
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 |
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.
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); |
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'm assuming the "lagging" concept will prevent this from ever locking/hanging correct?
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.
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? |
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'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 |
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.
What do you think should happen when StaticProvider::add_node_addr
is called? Should it show up here?
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.
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.
efb9410
to
0894cb9
Compare
0894cb9
to
c28273e
Compare
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 whenEndpoint::connect
is called for nodes we don't have addressing info), and nodes discovered passively (throughDiscovery::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