From 228cfa9607aa06d3351105f124a8467c7aeaa763 Mon Sep 17 00:00:00 2001 From: Franz Heinzmann Date: Mon, 5 Aug 2024 21:04:54 +0200 Subject: [PATCH] [wip] refactor(iroh-gossip)!: dispatch gossip events and updates by topic (#2570) ## Description This PR changes the main public `iroh_gossip` to keep track of client-side gossip subscriptions. The `net::Gossip` struct now keeps track of client-side subscribers per topic, which are made up of a pair of two streams/channels: from the client to the actor a stream of updates (outgoing messages) and from the actor to the client a stream of events (incoming messages). Once all client streams&sinks for a topic are dropped, the topic is being quit. This builds on the client API added in #2258, but completely removes the `dispatcher` module, integrating its features directly into the gossip actor. See below for a short list of the API changes. The new API can be browsed [here](https://n0-computer.github.io/iroh/pr/2570/docs/iroh/gossip/net/index.html). The refactor turned out bigger than initially intended, sorry for that, but I did not see a good way to reduce the scope. What's still missing (can also be follow-ups)?: - [ ] Review the new public API - [ ] Align the client API to the iroh_gossip API. The `GossipTopic` can be made to work on both the client and the native API, as it only deals with streams and sinks. ## Breaking Changes * `iroh_gossip::dispatcher` is removed with everything that was in it. use the new API from `iroh_gossip::net::Gossip` instead (see below). * `iroh_gossip::net::Gossip` methods changed: * changed: `join` now returns a `GossipTopic` * removed: `broadcast`, `broadcast_neighbors`, `subscribe`, `subscribe_all`, `quit`. * for `subscribe` use `join` instead, which returns a `GossipTopic` * for `broadcast` and `broadcast_neighbors` use the respective methods on `GossipTopic` . * `quit` is obsolete now, the topic will be quitted once all `GossipTopic` handles are dropped. * `subscribe_all` is no longer available * `iroh_gossip::net::JoinTopicFut` is removed (is now obsolete) ## Notes & open questions ## Change checklist - [x] Self-review. - [x] Documentation updates following the [style guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text), if relevant. - [ ] Tests if relevant. - [ ] All breaking changes documented. --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 32932a5825..87bf9e4359 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2781,9 +2781,9 @@ dependencies = [ "clap", "derive_more", "ed25519-dalek", + "futures-concurrency", "futures-lite 2.3.0", "futures-util", - "genawaiter", "indexmap 2.2.6", "iroh-base", "iroh-blake3",