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-gossip)!: dispatch gossip events and updates by topic #2570

Merged
merged 14 commits into from
Aug 5, 2024

Conversation

Frando
Copy link
Member

@Frando Frando commented Jul 31, 2024

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.

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

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

@Frando Frando changed the title [wip] Refactor gossip API to expose subscriptions streams and sinks per topic [wip] refactor(iroh-gossip) change API to expose subscriptions streams and sinks per topic Jul 31, 2024
@Frando Frando changed the title [wip] refactor(iroh-gossip) change API to expose subscriptions streams and sinks per topic [wip] refactor(iroh-gossip) dispatch gossip events and updates by topic Jul 31, 2024
@Frando Frando changed the title [wip] refactor(iroh-gossip) dispatch gossip events and updates by topic [wip] refactor(iroh-gossip): dispatch gossip events and updates by topic Jul 31, 2024
@Frando Frando changed the title [wip] refactor(iroh-gossip): dispatch gossip events and updates by topic [wip] refactor(iroh-gossip)!: dispatch gossip events and updates by topic Jul 31, 2024
Copy link

github-actions bot commented Jul 31, 2024

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

@matheus23
Copy link
Contributor

Direct link to the gossip docs: https://n0-computer.github.io/iroh/pr/2570/docs/iroh/gossip/net/index.html :)

github-merge-queue bot pushed a commit that referenced this pull request Aug 1, 2024
… 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.
@Frando Frando marked this pull request as ready for review August 5, 2024 12:21
@Frando
Copy link
Member Author

Frando commented Aug 5, 2024

Tentatively marking ready for review. Still has TODOs (see description) but that could also be a followup.

@dignifiedquire
Copy link
Contributor

n0-computer/iroh-ffi#173 is now green, so this definitely helps


use super::gossip::{GossipActor, ToGossipActor};
// use super::gossip::{GossipActor, ToGossipActor};
Copy link
Contributor

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();
Copy link
Contributor

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?

Copy link
Member Author

@Frando Frando Aug 5, 2024

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.

Copy link
Member Author

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?;
Copy link
Contributor

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?

Copy link
Member Author

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.

@dignifiedquire dignifiedquire added this pull request to the merge queue Aug 5, 2024
@dignifiedquire dignifiedquire changed the title [wip] refactor(iroh-gossip)!: dispatch gossip events and updates by topic feat(iroh-gossip)!: dispatch gossip events and updates by topic Aug 5, 2024
Merged via the queue into main with commit bdc1c45 Aug 5, 2024
28 of 29 checks passed
@dignifiedquire dignifiedquire deleted the gossip-refactor branch August 5, 2024 19:27
matheus23 pushed a commit that referenced this pull request Nov 14, 2024
…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.
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.

3 participants