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-net)!: add subscribe method to Discovery trait #2656

Merged
merged 40 commits into from
Sep 27, 2024

Conversation

ramfox
Copy link
Contributor

@ramfox ramfox commented Aug 21, 2024

Description

Adds a subscribe method to the Discovery trait that returns an Option<BoxStream>. The subscribe method will send DiscoveryItems each time the discovery service discovers a remote node.

The magicsock is now subscribed to the discovery service and updates the internal address book each time it receives a DiscoveryItem. The source is marked as Source::Discovery{ service: String } and the Instant that the magicsock received the information.

Users can now filter their list of RemoteInfos for sources.

Breaking Changes

  • struct RemoteInfo now has field sources, which is a Vec of (iroh::net::endpoint::Source, Duration). The Source is how we heard about the remote, and the Duration is how long ago we heard about it. The sources field is ordered from the first time we heard about the remote node to the most recent time we learned about the remote node, in this session.

Change checklist

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

iroh-net/src/discovery.rs Outdated Show resolved Hide resolved
iroh-net/src/discovery.rs Outdated Show resolved Hide resolved
iroh-net/src/discovery.rs Outdated Show resolved Hide resolved
iroh-net/src/discovery.rs Outdated Show resolved Hide resolved
iroh-net/src/discovery.rs Outdated Show resolved Hide resolved
iroh-net/src/discovery.rs Outdated Show resolved Hide resolved
@ramfox ramfox force-pushed the discovery_subscribe branch from d71cadf to a188bef Compare August 29, 2024 03:03
Copy link

github-actions bot commented Aug 29, 2024

Documentation for this PR has been generated and is available at: https://n0-computer.github.io/iroh/pr/2656/docs/iroh/

Last updated: 2024-09-27T17:06:25Z

@ramfox ramfox force-pushed the discovery_subscribe branch from 26f4600 to 952bcab Compare August 30, 2024 02:46
@ramfox ramfox modified the milestones: v0.24.0, v0.25.0 Sep 2, 2024
Copy link
Contributor

@divagant-martian divagant-martian left a comment

Choose a reason for hiding this comment

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

about the use of channels:

I generally prefer bounded channels, since they provide back pressure, but by spawning a task that does the send every time the back pressure is lost, making an unbounded channel preferable. In other channel, when sending the event back to the subscriber, there isn't this per-send spawn so it does provide back pressure, but I would argue here it's not what we want. Discovery should not be held up by an outsider reader not making room for another event. Also, a slow subscriber should not be able to held up other subscribers. I think this scenario is somewhat being negated by some other spawn somewhere up in the stack, but the point remains: If we do intend to be held a slow reader (this would make sense for example if we schedule something such that we only care about the last result), or if we are able to drop data when full, then a bounded channel is the best choice. If not, then unbounded channels are the way to go.

I another note, I checked out the cli output and was a bit confused to get the source for the node and no the address. I would think the "source of the node" is the source of the best address we use to communicate. Maybe it's just me, I'm open to leave it like this and understand it in another way, but would like to know what others think

iroh-cli/src/commands/net.rs Outdated Show resolved Hide resolved
iroh-net/src/discovery.rs Outdated Show resolved Hide resolved
iroh-net/src/discovery.rs Outdated Show resolved Hide resolved
iroh-net/src/discovery.rs Outdated Show resolved Hide resolved
iroh-net/src/discovery/local_swarm_discovery.rs Outdated Show resolved Hide resolved
iroh-net/src/endpoint.rs Outdated Show resolved Hide resolved
iroh-net/src/magicsock.rs Outdated Show resolved Hide resolved
iroh-net/src/magicsock/node_map/node_state.rs Outdated Show resolved Hide resolved
@flub
Copy link
Contributor

flub commented Sep 5, 2024

wrt to the bounded/unbounded channel. I only wanted to point out that spawning a task to send on a bounded channel is not a good pattern and is essentially worse than using an unbounded channel. It does always make sense to think about what backpressure is needed and whether something is possible or better without unbounded channels. @divagant-martian and @matheus23 were much more constructive in that regard :)

@ramfox ramfox force-pushed the discovery_subscribe branch from dcbfe3c to e1d0d04 Compare September 11, 2024 03:14
@ramfox ramfox changed the title WIP feat(iroh-net): add subscribe method to Discovery trait feat(iroh-net): add subscribe method to Discovery trait Sep 11, 2024
@ramfox ramfox changed the title feat(iroh-net): add subscribe method to Discovery trait feat(iroh-net)!: add subscribe method to Discovery trait Sep 11, 2024
@ramfox
Copy link
Contributor Author

ramfox commented Sep 11, 2024

After a discussion with dig last week, he suggested I just make the Discovery trait async, to avoid these gotchas.

@ramfox ramfox marked this pull request as ready for review September 11, 2024 03:50
iroh-net/src/discovery.rs Outdated Show resolved Hide resolved
iroh-net/src/discovery.rs Outdated Show resolved Hide resolved
iroh-net/src/discovery.rs Outdated Show resolved Hide resolved
iroh-net/src/discovery.rs Outdated Show resolved Hide resolved
iroh-net/src/discovery.rs Outdated Show resolved Hide resolved
iroh-net/src/discovery.rs Outdated Show resolved Hide resolved
iroh-net/src/discovery/local_swarm_discovery.rs Outdated Show resolved Hide resolved
iroh-net/src/endpoint.rs Outdated Show resolved Hide resolved
iroh-net/src/endpoint.rs Outdated Show resolved Hide resolved
iroh-net/src/magicsock/node_map/node_state.rs Outdated Show resolved Hide resolved
iroh-net/src/discovery.rs Outdated Show resolved Hide resolved
iroh-net/src/discovery.rs Outdated Show resolved Hide resolved
@dignifiedquire dignifiedquire modified the milestones: v0.25.0, v0.26.0 Sep 16, 2024
@ramfox ramfox force-pushed the discovery_subscribe branch 2 times, most recently from 1b14cb7 to 4fd17a4 Compare September 23, 2024 18:59
iroh-net/Cargo.toml Outdated Show resolved Hide resolved
@ramfox ramfox force-pushed the discovery_subscribe branch from 8381d21 to 7f25aa2 Compare September 24, 2024 15:05
@ramfox ramfox requested a review from matheus23 September 24, 2024 15:19
@matheus23
Copy link
Contributor

matheus23 commented Sep 27, 2024

✅ as in "happy from my perspective". But ofc would welcome more ✅s (or comments on addressed feedback) from diva and flub :)

Copy link
Contributor

@flub flub left a comment

Choose a reason for hiding this comment

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

lgtm

iroh-net/examples/locally-discovered-nodes.rs Outdated Show resolved Hide resolved
iroh-net/src/discovery.rs Outdated Show resolved Hide resolved
iroh-net/src/discovery.rs Show resolved Hide resolved
iroh-net/src/discovery.rs Show resolved Hide resolved
iroh-net/src/discovery.rs Outdated Show resolved Hide resolved
iroh-net/src/magicsock/node_map.rs Outdated Show resolved Hide resolved
iroh-net/src/magicsock/node_map/node_state.rs Outdated Show resolved Hide resolved
iroh-net/src/magicsock/node_map/node_state.rs Outdated Show resolved Hide resolved
iroh-net/src/magicsock/node_map/node_state.rs Outdated Show resolved Hide resolved
iroh-net/src/magicsock/node_map/node_state.rs Show resolved Hide resolved
ramfox and others added 7 commits September 27, 2024 10:39
Co-authored-by: Floris Bruynooghe <flub@n0.computer>
Co-authored-by: Floris Bruynooghe <flub@n0.computer>
Co-authored-by: Floris Bruynooghe <flub@n0.computer>
Co-authored-by: Floris Bruynooghe <flub@n0.computer>
Copy link
Contributor

@divagant-martian divagant-martian left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

@divagant-martian divagant-martian added this pull request to the merge queue Sep 27, 2024
Merged via the queue into main with commit 06c0844 Sep 27, 2024
26 of 27 checks passed
@divagant-martian divagant-martian deleted the discovery_subscribe branch September 27, 2024 17:40
matheus23 pushed a commit that referenced this pull request Nov 14, 2024
## Description

Adds a `subscribe` method to the `Discovery` trait that returns an
`Option<BoxStream>`. The `subscribe` method will send `DiscoveryItems`
each time the discovery service discovers a remote node.

The magicsock is now subscribed to the discovery service and updates the
internal address book each time it receives a `DiscoveryItem`. The
source is marked as `Source::Discovery{ service: String }` and the
`Instant` that the magicsock received the information.

Users can now filter their list of `RemoteInfo`s for sources.

## Breaking Changes

- struct `RemoteInfo` now has field `sources`, which is a `Vec` of
`(iroh::net::endpoint::Source, Duration)`. The `Source` is how we heard
about the remote, and the `Duration` is how long ago we heard about it.
The `sources` field is ordered from the first time we heard about the
remote node to the most recent time we learned about the remote node, in
this session.

## 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.
- [x] Tests if relevant.
- [x] All breaking changes documented.

---------

Co-authored-by: Kasey Huizinga <ramfox@Kaseys-MBP.lan>
Co-authored-by: Divma <26765164+divagant-martian@users.noreply.github.com>
Co-authored-by: Floris Bruynooghe <flub@n0.computer>
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.

7 participants