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(provider): add 'CollectionAdded' Provider event #1131

Merged
merged 6 commits into from
Jun 27, 2023
Merged

Conversation

b5
Copy link
Member

@b5 b5 commented Jun 23, 2023

Need this for iroh.network, which listens to an in-process node for provider collection construction.

I'm piggybacking this to also add a test that does minimal node setup, which should form the basis of writing examples later. Learned many things in the process.

@b5 b5 self-assigned this Jun 23, 2023
Comment on lines +178 to 179
/// Makes a an RPC endpoint that uses a QUIC transport
fn make_rpc_endpoint(
Copy link
Member Author

Choose a reason for hiding this comment

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

went on a wild goose chase looking for a way to construct an RPC endpoint to give to the builder, and at one point wanted to move this, only to discover node.controller(). This comment is a momento of hour(s) lost.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry about this. So the idea is that you always want a cheap in memory way to control your node via RPC like calls.

Basically like an in memory message channel between you and the node, but nicer than the usual pattern of sending messages that contain a oneshot sender for the reply. This is what the controller is for.

Comment on lines +597 to +598
)) {
warn!("failed to send CollectionAdded event: {:?}", e);
Copy link
Member Author

Choose a reason for hiding this comment

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

this might be overkill, but I figured I'd err on the side of being pedantic

iroh/src/node.rs Outdated
Comment on lines 756 to 762
while let Ok(msg) = events.recv().await {
match msg {
Event::ByteProvide(e) => {
if let iroh_bytes::provider::Event::CollectionAdded { hash } = e {
got_hash = Some(hash);
break;
}
}
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This test could be expanded in the future for more extensive provider event testing

.await
.unwrap();

let _drop_guard = node.cancel_token().drop_guard();
Copy link
Member Author

Choose a reason for hiding this comment

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

do I need to do this?

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure, @flub ?

@b5 b5 requested a review from dignifiedquire June 23, 2023 11:16
@b5 b5 force-pushed the collection-added-event branch from 729e44e to 5a16586 Compare June 23, 2023 11:28
Copy link
Contributor

@rklaehn rklaehn left a comment

Choose a reason for hiding this comment

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

This seems quite reasonable.

However, please be aware that there is a problem with using the events for any bookkeeping. I frequently have the problem that the many_files test fails because as you optimize things it can produce events very quickly, and the broadcast channel has only a fixed buffer size before it starts dropping messages.

If you want to use these events for anything important, we would have to have a way to prevent the dropping. Unbounded channels, or blocking when you are unable to send.

@dignifiedquire
Copy link
Contributor

I frequently have the problem that the many_files test fails because as you optimize things it can produce events very quickly, and the broadcast channel has only a fixed buffer size before it starts dropping messages.

See failing test in ci, because of exactly that reason

@@ -34,6 +34,11 @@ pub use ticket::Ticket;
/// Events emitted by the provider informing about the current status.
#[derive(Debug, Clone)]
pub enum Event {
/// A new collection has been added via an RPC call
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make this more generic, so it always happens, not just on RPC call, like the other events?

Copy link
Member Author

Choose a reason for hiding this comment

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

After talking it over with @flub, they're one-and-the-same. I've updated the comment to match.

I've confirmed that: All of these events require a provider (duh), and that all call sites where a provider calls collection::create_collection, the provider is wrapping with a CollectionCreated event. This works rn b/c everything is flowing through node::provide0.

We should keep an eye on this for the moment when we can do getting & providing in the same process "mode".

@Winterhuman
Copy link

(Feel free to mark this as offtopic, I couldn't find a repo for iroh.network)

@b5 https://iroh.network shows <meta name="frontend-version" content="%REACT_APP_GIT_SHA%"> in it's <head> element btw, I think that means something's broken.

@b5
Copy link
Member Author

b5 commented Jun 26, 2023

@Winterhuman, lol yeah the %REACT_APP_GIT_SHA% isn't supposed to be there, will fix :)

with regard to https://iroh.network, nice find 😄 . It isn't open source atm, and isn't scheduled for wide release until later this year. If you'd like an invite to test it out, feel free to email me using [my github handle] @ n0.computer.

Thanks!

@Arqu
Copy link
Collaborator

Arqu commented Jun 26, 2023

Dunno what this did, but seems tests run forever. Canceling the current batch, but needs looking into it.

@b5 b5 force-pushed the collection-added-event branch from 5e46d1a to e1e09cb Compare June 27, 2023 12:41
Copy link
Contributor

@dignifiedquire dignifiedquire left a comment

Choose a reason for hiding this comment

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

assuming CI passes, lgtm

@b5 b5 merged commit 8b6a5bc into main Jun 27, 2023
@b5 b5 deleted the collection-added-event branch June 27, 2023 13:58
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