Conversation
rimi0108
commented
Jul 26, 2022
- Add _uuid module
- Add _uuid function generate_time_safe()
- uuid v1 = generate_time_safe
- Return mac address to node_id if you have mac address or return random generated bytes to node_id if you do not have mac address
| num_enum = "0.5.7" | ||
| ascii = "1.0.0" | ||
| once_cell = "1.13.0" | ||
| mac_address = "1.1.3" |
There was a problem hiding this comment.
Adding this line instead of dependencies.uuid section
will be more easy to read
uuid = { version = "1.1.2", features = ["v1", "fast-rng", "macro-diagnostics"] }
There was a problem hiding this comment.
mac_address needs more cfg guard for more OS.
See mmap case. By referring CI failure, we (at least) need to exclude iOS and android.
stdlib/src/lib.rs
Outdated
| mod ssl; | ||
| #[cfg(all(unix, not(target_os = "redox")))] | ||
| mod termios; | ||
| #[cfg(target_os = "macos")] |
There was a problem hiding this comment.
what's the blocker for linux and windows?
stdlib/src/uuid.rs
Outdated
|
|
||
| #[pymodule] | ||
| mod _uuid { | ||
|
|
| match get_mac_address() { | ||
| Ok(Some(_ma)) => { | ||
| let node_id = NODE_ID.get_or_init(|| get_mac_address().unwrap().unwrap().bytes()); | ||
| node_id | ||
| } | ||
| Ok(None) => { | ||
| let node_id = NODE_ID.get_or_init(|| rand::thread_rng().gen::<[u8; 6]>()); | ||
| node_id | ||
| } | ||
| Err(_e) => { | ||
| let node_id = NODE_ID.get_or_init(|| rand::thread_rng().gen::<[u8; 6]>()); | ||
| node_id | ||
| } | ||
| } |
There was a problem hiding this comment.
this is checking get_mac_address every time. That probably is not expectation for node id. NODE_ID.get_or_init must be the outmost wrapper of this function
|
|
stdlib/src/uuid.rs
Outdated
| Ok(None) => { | ||
| let node_id = rand::thread_rng().gen::<[u8; 6]>(); | ||
| node_id | ||
| } | ||
| Err(_e) => { | ||
| let node_id = rand::thread_rng().gen::<[u8; 6]>(); | ||
| node_id | ||
| } |
There was a problem hiding this comment.
| Ok(None) => { | |
| let node_id = rand::thread_rng().gen::<[u8; 6]>(); | |
| node_id | |
| } | |
| Err(_e) => { | |
| let node_id = rand::thread_rng().gen::<[u8; 6]>(); | |
| node_id | |
| } | |
| _ => { | |
| let node_id = rand::thread_rng().gen::<[u8; 6]>(); | |
| node_id | |
| } |
stdlib/src/uuid.rs
Outdated
| let now = now_unix_duration(); | ||
| static CONTEXT: Context = Context::new(0); |
There was a problem hiding this comment.
| let now = now_unix_duration(); | |
| static CONTEXT: Context = Context::new(0); | |
| static CONTEXT: Context = Context::new(0); | |
| let now = now_unix_duration(); |
technically this is ok but I feel uncomfortable to have static below without a good reason
stdlib/src/uuid.rs
Outdated
| static CONTEXT: Context = Context::new(0); | ||
| let ts = Timestamp::from_unix(&CONTEXT, now.as_secs(), now.subsec_nanos()); | ||
|
|
||
| let node_id = get_node_id(); |
There was a problem hiding this comment.
If we will not use the value from second call, why do we call this function every time?
You can move this line in get_or_init().
stdlib/src/uuid.rs
Outdated
| } | ||
|
|
||
| #[pyfunction] | ||
| fn generate_time_safe(_vm: &VirtualMachine) -> (Vec<u8>, PyNone) { |
There was a problem hiding this comment.
| fn generate_time_safe(_vm: &VirtualMachine) -> (Vec<u8>, PyNone) { | |
| fn generate_time_safe() -> (Vec<u8>, PyNone) { |
stdlib/src/uuid.rs
Outdated
| } | ||
|
|
||
| #[pyattr] | ||
| fn has_uuid_generate_time_safe(_vm: &VirtualMachine) -> PyInt { |
There was a problem hiding this comment.
| fn has_uuid_generate_time_safe(_vm: &VirtualMachine) -> PyInt { | |
| fn has_uuid_generate_time_safe() -> u32 { |
stdlib/src/uuid.rs
Outdated
|
|
||
| #[pyattr] | ||
| fn has_uuid_generate_time_safe(_vm: &VirtualMachine) -> PyInt { | ||
| PyInt::from(0) |
There was a problem hiding this comment.
This is interesting. What this value is meaning? 🤔
There was a problem hiding this comment.
I wrote the code like that because it was printed below the cpython
>>> _uuid.has_uuid_generate_time_safe
0
youknowone
left a comment
There was a problem hiding this comment.
You seem didn't set git email correctly. Check git log and if it matches your actual email (and github email)
| num_enum = "0.5.7" | ||
| ascii = "1.0.0" | ||
| once_cell = "1.13.0" | ||
| mac_address = "1.1.3" |
There was a problem hiding this comment.
mac_address needs more cfg guard for more OS.
See mmap case. By referring CI failure, we (at least) need to exclude iOS and android.
youknowone
left a comment
There was a problem hiding this comment.
looks good, thank you for long time effort