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

v1: get node_id automatically #740

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

shivdhar
Copy link

v1: Create node_id automatically from the MAC address of the machine, with fallback, according to the rules laid out by RFC 4122.

Advantage:

The user can now call now_v1_auto() and get a V1 UUID without needing to figure out how to manually retrieve/create the node_id.

Performance: Comparable

=> cargo +nightly bench --features=v1_auto -- bench_v1
running 2 tests
test bench_v1      ... bench:          65 ns/iter (+/- 15)
test bench_v1_auto ... bench:          66 ns/iter (+/- 6)

@shivdhar
Copy link
Author

Some prettification/tests/docs is remaining, but the bulk of the work is done. Feedback from maintainers would be appreciated, thanks!

@shivdhar shivdhar marked this pull request as ready for review February 25, 2024 18:45
@KodrAus
Copy link
Member

KodrAus commented Mar 3, 2024

Hi @shivdhar! Thanks for the PR. I'm not sure this is something we should add to uuid itself, but if you'd like to convert this into an example in the examples repository for producing v1 UUIDs from MAC addresses. I think that would be a great way to help users discover how to do it.

@shivdhar
Copy link
Author

shivdhar commented Mar 5, 2024

Hi @KodrAus ! I actually was surprised when I tried to use the crate and, instead of just calling now_v1, had to figure out how it worked, read the RFC, make sure the MAC address was big-endian, etc. etc. As a user, I'd just like to get the v1 UUID without worrying about how it works, wouldn't you agree?

Also I took a look at the history of the feature in this repo, and the only reason it seems it wasn't included since the beginning is this issue:

Also "Node ID" is a vague notion, usually the mac address, but I assume we'd just want to let someone pass in 16 bytes for that.

However, node ID is quite well defined in the RFC (along with fallback) so I don't see any reason why we shouldn't have a conformant implementation.

Another blocker -- way back in 2016 -- seems to have been this:

I don't think we're really poised to fully provide V1 UUID generation because we don't have a robust method of figuring out what the local MAC address is?
#59 (comment)

This seems to have been solved by the mac_address crate though fairly well; it supports most common platforms and seems to be fairly popular and good at its job (over 2.4M downloads), so we're probably in a better place to provide this in 2024.

Most other languages let us get a v1 UUID automatically without a mandatory node_id argument too, it was very surprising as a user when I couldn't do so with this, the "official" crate for Rust.

Let me know what you think!

@KodrAus
Copy link
Member

KodrAus commented Mar 18, 2024

I think discoverability is definitely an issue, but I also think that's solved by adding an example. My specific concerns with direct support are:

  1. Adding another dependency to the library that's called under-the-hood. It hides from the user how we get that address, which currently is the first non-loopback adapter, but that isn't guaranteed to be what someone wants. It also requires background initialization using OnceLocks, which we'd need to bump our MSRV or pull in another dependency for. We'd need to communicate what the lifetime of that address is, and what platforms it does and doesn't support.
  2. UUID V1 with actual MAC addresses is more of a niche nowadays (in my opinion), so I'm reluctant to add more infrastructure in the form of APIs and crate features to support them that need to be maintained.

At least I'd like to start with an example, and consider revisiting this in the future if it becomes widely desirable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants