From 1b6c1b425f78f4ec3eb275f21a792776e50cbf93 Mon Sep 17 00:00:00 2001 From: Aria Date: Fri, 13 Oct 2023 01:33:38 +0100 Subject: start using async --- common/src/msg_id.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 common/src/msg_id.rs (limited to 'common/src/msg_id.rs') diff --git a/common/src/msg_id.rs b/common/src/msg_id.rs new file mode 100644 index 0000000..e953f08 --- /dev/null +++ b/common/src/msg_id.rs @@ -0,0 +1,16 @@ +use std::time::{SystemTime, UNIX_EPOCH}; + +use rand::{thread_rng, Rng}; + +pub type MessageID = u64; + +pub fn gen_msg_id() -> MessageID { + // Time since UNIX epoch in milliseconds, (48 bits) + let now = SystemTime::now(); + let time_millis: u128 = now.duration_since(UNIX_EPOCH).unwrap().as_millis(); + + // 16 bits of randomness + let rand: u16 = thread_rng().gen(); + + ((time_millis as u64) << 16) | (rand as u64) +} -- cgit v1.2.3