-
Notifications
You must be signed in to change notification settings - Fork 163
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-gossip)!: dispatch gossip events and updates by topic #2570
Conversation
Documentation for this PR has been generated and is available at: https://n0-computer.github.io/iroh/pr/2570/docs/iroh/ Last updated: 2024-08-05T18:44:20Z |
Direct link to the gossip docs: https://n0-computer.github.io/iroh/pr/2570/docs/iroh/gossip/net/index.html :) |
… read errors (#2572) ## Description The connection loop of iroh-gossip misused tokio-select by selecting over a future that is not cancellation safe. This means that if the timings are bad, the message reading future would be aborted midway in a message, and then restart by reading a length, which would then yield some random number because it would be reading some random bytes in the middle of a message. This means it would lead to random connection drops. ## Breaking Changes Backport from #2570 <!-- Optional, if there are any breaking changes document them, including how to migrate older code. --> ## Notes & open questions <!-- Any notes, remarks or open questions you have to make about the PR. --> ## Change checklist - [x] Self-review. - [ ] ~~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.~~ - [x] All breaking changes documented.
Tentatively marking ready for review. Still has TODOs (see description) but that could also be a followup. |
n0-computer/iroh-ffi#173 is now green, so this definitely helps |
|
||
use super::gossip::{GossipActor, ToGossipActor}; | ||
// use super::gossip::{GossipActor, ToGossipActor}; |
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.
delete
self.gossip_actor_tx | ||
.send(ToGossipActor::Shutdown) | ||
.await | ||
.ok(); |
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.
can't we wait for the gossip actor exit anymore?
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.
there's no gossip actor anymore in the live engine! the GossipState
is not a loop of its own, it just contains state and a joinset with the topic loop tasks. i will check again if that is terminated properly on shutdown.
the main Gossip
is passed into the live engine, so should be shutdown outside it as well.
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.
Pushed a commit that properly joins the topic task loops in the sync engine to catch panics. Also added a TODO to catch panics when aborthing other joinsets in the sync engine too.
/// Waits until we are connected to at least one node. | ||
pub async fn joined(&mut self) -> Result<()> { | ||
while self.neighbors.is_empty() { | ||
let _ = self.try_next().await?; |
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.
shouldn't this be explicit about the type of event?
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.
the Joined
event is handled in try_next
. But we could be more explict and return an error if any other event than Joined
is returned, yes.
…opic (#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 <!-- Any notes, remarks or open questions you have to make about the PR. --> ## 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.
Description
This PR changes the main public
iroh_gossip
to keep track of client-side gossip subscriptions. Thenet::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.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)?:
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 fromiroh_gossip::net::Gossip
instead (see below).iroh_gossip::net::Gossip
methods changed:join
now returns aGossipTopic
broadcast
,broadcast_neighbors
,subscribe
,subscribe_all
,quit
.subscribe
usejoin
instead, which returns aGossipTopic
broadcast
andbroadcast_neighbors
use the respective methods onGossipTopic
.quit
is obsolete now, the topic will be quitted once allGossipTopic
handles are dropped.subscribe_all
is no longer availableiroh_gossip::net::JoinTopicFut
is removed (is now obsolete)Notes & open questions
Change checklist