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!: improve reexport structure #3023

Merged
merged 15 commits into from
Dec 12, 2024
Merged

Conversation

dignifiedquire
Copy link
Contributor

@dignifiedquire dignifiedquire commented Dec 9, 2024

Description

Restructures both iroh_base and iroh reexports and type placements, to simplify and clarify the overall structures.

Breaking Changes

  • iroh-base

    • key -> iroh_base::NodeId etc
    • hash -> iroh_base::Hash etc
    • node_addr -> iroh_base::NodeAddr
    • relay_url -> iroh_base::RelayUrl
    • relay_map -> use iroh_relay::relay_map
  • iroh

    • hash -> iroh_base
    • ticket -> iroh_base::ticket)
    • relay -> removed, use iroh_relay directly if needed
    • key -> NodeId, etc top level now
    • endpoint::Bytes removed use bytes::Bytes
    • endpoint::NodeAddr, use iroh::NodeAddr

Notes & open questions

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 Dec 9, 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: 27d8291

@dignifiedquire dignifiedquire added this to the v0.30.0 milestone Dec 9, 2024
@dignifiedquire
Copy link
Contributor Author

Screenshot 2024-12-09 at 20 45 53

I updated iroh-base to look like the above, would love some feedback on this

QuicConfig as RelayQuicConfig, RelayMap, RelayNode, DEFAULT_RELAY_QUIC_PORT, DEFAULT_STUN_PORT,
};
#[cfg(any(feature = "relay", feature = "key"))]
#[cfg_attr(iroh_docsrs, doc(cfg(any(feature = "relay", feature = "key"))))]
Copy link
Contributor

Choose a reason for hiding this comment

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

You should try this out, but I think if you reexport something from a module that has the #[cfg_attr(iroh_docsrs, doc(cfg(any(feature = "relay", feature = "key"))))] thing, all reexports will also have the proper tags in the docs.

So you could simplify this by just having this statement on the (non-pub) module.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, never mind. This is just iroh-base...

Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need a const for the size of an ed key in the first place?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why do we need a const for the size of an ed key in the first place?

we can drop that probably, need to check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why do we need a const for the size of an ed key in the first place?

it is used in a few places, sorry

Copy link
Contributor

Choose a reason for hiding this comment

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

Just write 32 or have a const per crate. It is not going to change.

#[cfg(feature = "relay")]
#[cfg_attr(iroh_docsrs, doc(cfg(feature = "relay")))]
pub use self::relay_map::{
QuicConfig as RelayQuicConfig, RelayMap, RelayNode, DEFAULT_RELAY_QUIC_PORT, DEFAULT_STUN_PORT,
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I like having these constants at top level. It is probably very rare that somebody needs them, so having them hidden away in some public mod is not that bad.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't find a better way, this is only for iroh-base though, in iroh it is much cleaner now

#[cfg(feature = "relay")]
#[cfg_attr(iroh_docsrs, doc(cfg(feature = "relay")))]
pub use self::relay_map::{
QuicConfig as RelayQuicConfig, RelayMap, RelayNode, DEFAULT_RELAY_QUIC_PORT, DEFAULT_STUN_PORT,
Copy link
Contributor

Choose a reason for hiding this comment

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

I really don't like renames because the compiler will now give users confusing errors. Can you just rename the relay_map::QuicConfig to relay_map::RelayQuicConfig for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

iroh-base/src/lib.rs Show resolved Hide resolved
@@ -1,7 +1,7 @@
use std::str::FromStr;

use clap::Parser;
use iroh::NodeId;
use iroh::key::NodeId;
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, not sure I like this no longer bing on the top level.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

iroh/src/lib.rs Outdated
};
pub use iroh_relay as relay;
pub use endpoint::{Endpoint, RelayMode};
pub use iroh_base::{hash, key, node_addr, relay_map, ticket};
Copy link
Contributor

Choose a reason for hiding this comment

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

  • do we need hash?
  • I'd like to keep NodeId at least at the toplevel.
  • If we're removing RelayUrl from here then why keep RelayMode? Yes it's used in the builder but if you want anything else then disabled or default you'll need a whole bunch more relay types anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because RelayMode is defined in iroh, not in base

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • I'd like to keep NodeId at least at the toplevel.

that's fair

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • do we need hash?

interesting question, we actually don't

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hash is gone now

@dignifiedquire dignifiedquire self-assigned this Dec 11, 2024
@dignifiedquire dignifiedquire force-pushed the refactor-normalize-reexports branch from 504f711 to 4de6e89 Compare December 11, 2024 18:27
@dignifiedquire dignifiedquire changed the title [WIP] refactor(iroh): improve reexport structure refactor(iroh): improve reexport structure Dec 11, 2024
@dignifiedquire dignifiedquire marked this pull request as ready for review December 11, 2024 19:03
Copy link

github-actions bot commented Dec 11, 2024

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

Last updated: 2024-12-12T10:34:00Z

@dignifiedquire dignifiedquire changed the title refactor(iroh): improve reexport structure refactor(iroh)!: improve reexport structure Dec 11, 2024
@dignifiedquire dignifiedquire force-pushed the refactor-normalize-reexports branch from 6ae64b8 to d034234 Compare December 11, 2024 20:42
@dignifiedquire dignifiedquire force-pushed the refactor-normalize-reexports branch from 49faded to 24cddc7 Compare December 12, 2024 10:17
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.

seems like a decent improvement

@@ -6,7 +6,7 @@ use std::{
time::{Duration, Instant},
};

use iroh_base::key::NodeId;
use iroh_base::NodeId;
Copy link
Contributor

Choose a reason for hiding this comment

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

I find it a little odd that the imports don't come from crate::NodeId... but I don't think this is a problem. Probably rust-analzyer will keep inserting this anyway.

@dignifiedquire dignifiedquire added this pull request to the merge queue Dec 12, 2024
@dignifiedquire dignifiedquire changed the title refactor(iroh)!: improve reexport structure refactor!: improve reexport structure Dec 12, 2024
Merged via the queue into main with commit d9fb470 Dec 12, 2024
29 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

3 participants