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

refactor(iroh-router)!: change accept to take an AsRef<[u8]> #2963

Merged
merged 3 commits into from
Nov 26, 2024

Conversation

rklaehn
Copy link
Contributor

@rklaehn rklaehn commented Nov 25, 2024

Description

Change RouterBuilder::accept to take an AsRef<[u8]> instead of a Vec. Also change iroh node accept.

Breaking Changes

  • RouterBuilder::accept takes impl AsRef<[u8]>. Existing code should still work!
  • Node::accept takes impl AsRef<[u8]>. Existing code should still work!

Notes & open questions

Question: since we are making the API more pleasant at the expense of a bit of inefficiency, should we also change the second parameter to take a &Arc instead of an Arc?

So

fn accept(alpn: impl AsRef<[u8]>, proto: &Arc<dyn ProtocolHandler>)

In the various examples I found that you very frequently need the protocol handler again after accept-ing it. So this saves one .clone() in many cases, at the expense of an arc clone, which we basically treat as free anyway.

Change checklist

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

Copy link

github-actions bot commented Nov 25, 2024

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

Last updated: 2024-11-26T09:50:05Z

Copy link

github-actions bot commented Nov 25, 2024

Netsim report & logs for this PR have been generated and is available at: LOGS
This report will remain available for 3 days.

Last updated for commit: ee87dc1

@dignifiedquire dignifiedquire added this to the v0.29.0 milestone Nov 25, 2024
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.

Nice, I like this.

@flub
Copy link
Contributor

flub commented Nov 25, 2024

Question: since we are making the API more pleasant at the expense of a bit of inefficiency, should we also change the second parameter to take a &Arc instead of an Arc?

So

fn accept(alpn: impl AsRef<[u8]>, proto: &Arc<dyn ProtocolHandler>)

In the various examples I found that you very frequently need the protocol handler again after accept-ing it. So this saves one .clone() in many cases, at the expense of an arc clone, which we basically treat as free anyway.

I find &Arc<dyn ProtocolHandler> a very weird signature though. That's purely an emotional response and not a technical one though.

@rklaehn
Copy link
Contributor Author

rklaehn commented Nov 26, 2024

Question: since we are making the API more pleasant at the expense of a bit of inefficiency, should we also change the second parameter to take a &Arc instead of an Arc?
So

fn accept(alpn: impl AsRef<[u8]>, proto: &Arc<dyn ProtocolHandler>)

In the various examples I found that you very frequently need the protocol handler again after accept-ing it. So this saves one .clone() in many cases, at the expense of an arc clone, which we basically treat as free anyway.

I find &Arc<dyn ProtocolHandler> a very weird signature though. That's purely an emotional response and not a technical one though.

Yeah, I share it. On the other hand compared to some atrocities involving Pin it looks almost simple. Possibly a type alias or even a newtype might be the way to go.

# Conflicts:
#	iroh/examples/custom-protocol.rs
#	iroh/src/node/builder.rs
@rklaehn rklaehn marked this pull request as ready for review November 26, 2024 09:47
@dignifiedquire dignifiedquire added this pull request to the merge queue Nov 26, 2024
Merged via the queue into main with commit 4e3b431 Nov 26, 2024
25 of 26 checks passed
@rklaehn rklaehn deleted the router-accept-asref branch December 6, 2024 08:55
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