diff --git a/server/Cargo.lock b/server/Cargo.lock index d4e6dcf..a6512ef 100644 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -1256,7 +1256,6 @@ dependencies = [ "tempfile", "tokio", "tracing", - "ulid", "url", "uuid", ] @@ -1272,6 +1271,7 @@ dependencies = [ "byteorder", "bytes", "cursive", + "data-encoding", "flate2", "futures", "h264-reader", @@ -1314,7 +1314,6 @@ dependencies = [ "tracing-log", "tracing-subscriber", "tracing-test", - "ulid", "url", "uuid", "walkdir", @@ -2547,16 +2546,6 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" -[[package]] -name = "ulid" -version = "1.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f294bff79170ed1c5633812aff1e565c35d993a36e757f9bc0accf5eec4e6045" -dependencies = [ - "rand", - "web-time", -] - [[package]] name = "unicode-ident" version = "1.0.15" @@ -2618,6 +2607,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3758f5e68192bb96cc8f9b7e2c2cfdabb435499a28499a42f8f984092adad4b" dependencies = [ "getrandom", + "rand", "serde", ] @@ -2745,16 +2735,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "web-time" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - [[package]] name = "which" version = "4.4.2" diff --git a/server/Cargo.toml b/server/Cargo.toml index ea1cea7..1240745 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -36,6 +36,7 @@ tracing-core = "0.1.30" tracing-futures = { version = "0.2.5", features = ["futures-03", "std-future"] } tracing-log = "0.2" tracing-subscriber = { version = "0.3.16" } +uuid = { version = "1.1.2", features = ["serde", "std", "v7", "fast-rng"] } [dependencies] base = { package = "moonfire-base", path = "base" } @@ -45,6 +46,7 @@ bpaf = { version = "0.9.15", features = ["autocomplete", "bright-color", "derive bytes = "1" byteorder = "1.0" cursive = { version = "0.21.1", default-features = false, features = ["termion-backend"] } +data-encoding = "2.7.0" db = { package = "moonfire-db", path = "db" } futures = "0.3" h264-reader = { workspace = true } @@ -76,9 +78,8 @@ tracing-subscriber = { version = "0.3.16", features = ["env-filter", "json"] } tracing-core = "0.1.30" tracing-futures = { version = "0.2.5", features = ["futures-03", "std-future"] } tracing-log = { workspace = true } -ulid = "1.0.0" url = "2.1.1" -uuid = { version = "1.1.2", features = ["serde", "std", "v4"] } +uuid = { workspace = true } flate2 = "1.0.26" hyper-util = { version = "0.1.7", features = ["server-graceful", "tokio"] } http-body = "1.0.1" diff --git a/server/db/Cargo.toml b/server/db/Cargo.toml index 28fc6ea..67e3663 100644 --- a/server/db/Cargo.toml +++ b/server/db/Cargo.toml @@ -39,9 +39,8 @@ smallvec = "1.0" tempfile = "3.2.0" tokio = { version = "1.24", features = ["macros", "rt-multi-thread", "sync"] } tracing = { workspace = true } -ulid = "1.0.0" url = { version = "2.1.1", features = ["serde"] } -uuid = { version = "1.1.2", features = ["serde", "std", "v4"] } +uuid = { workspace = true } [build-dependencies] protobuf-codegen = "3.0" diff --git a/server/db/db.rs b/server/db/db.rs index c5acbc7..3c7929f 100644 --- a/server/db/db.rs +++ b/server/db/db.rs @@ -1797,7 +1797,7 @@ impl LockedDatabase { pub fn add_sample_file_dir(&mut self, path: PathBuf) -> Result { let mut meta = schema::DirMeta::default(); - let uuid = Uuid::new_v4(); + let uuid = Uuid::now_v7(); let uuid_bytes = &uuid.as_bytes()[..]; let o = self .open @@ -1906,7 +1906,7 @@ impl LockedDatabase { /// Adds a camera. pub fn add_camera(&mut self, mut camera: CameraChange) -> Result { - let uuid = Uuid::new_v4(); + let uuid = Uuid::now_v7(); let uuid_bytes = &uuid.as_bytes()[..]; let tx = self.conn.transaction()?; let streams; @@ -2227,7 +2227,7 @@ pub fn init(conn: &mut rusqlite::Connection) -> Result<(), Error> { tx.execute_batch(include_str!("schema.sql")) .map_err(|e| err!(e, msg("unable to create database schema")))?; { - let uuid = ::uuid::Uuid::new_v4(); + let uuid = ::uuid::Uuid::now_v7(); let uuid_bytes = &uuid.as_bytes()[..]; tx.execute("insert into meta (uuid) values (?)", params![uuid_bytes])?; } @@ -2353,7 +2353,7 @@ impl Database { let real = recording::Time::from(clocks.realtime()); let mut stmt = conn .prepare(" insert into open (uuid, start_time_90k, boot_uuid) values (?, ?, ?)")?; - let open_uuid = SqlUuid(Uuid::new_v4()); + let open_uuid = SqlUuid(Uuid::now_v7()); let boot_uuid = match get_boot_uuid() { Err(e) => { warn!(err = %e.chain(), "unable to get boot uuid"); diff --git a/server/db/upgrade/v1_to_v2.rs b/server/db/upgrade/v1_to_v2.rs index 6d484fb..c082fa3 100644 --- a/server/db/upgrade/v1_to_v2.rs +++ b/server/db/upgrade/v1_to_v2.rs @@ -80,17 +80,17 @@ pub fn run(args: &super::Args, tx: &rusqlite::Transaction) -> Result<(), Error> create index user_session_uid on user_session (user_id); "#, )?; - let db_uuid = ::uuid::Uuid::new_v4(); + let db_uuid = ::uuid::Uuid::now_v7(); let db_uuid_bytes = &db_uuid.as_bytes()[..]; tx.execute("insert into meta (uuid) values (?)", params![db_uuid_bytes])?; - let open_uuid = ::uuid::Uuid::new_v4(); + let open_uuid = ::uuid::Uuid::now_v7(); let open_uuid_bytes = &open_uuid.as_bytes()[..]; tx.execute( "insert into open (uuid) values (?)", params![open_uuid_bytes], )?; let open_id = tx.last_insert_rowid() as u32; - let dir_uuid = ::uuid::Uuid::new_v4(); + let dir_uuid = ::uuid::Uuid::now_v7(); let dir_uuid_bytes = &dir_uuid.as_bytes()[..]; // Write matching metadata to the directory. diff --git a/server/src/web/mod.rs b/server/src/web/mod.rs index a36695b..733db88 100644 --- a/server/src/web/mod.rs +++ b/server/src/web/mod.rs @@ -319,7 +319,7 @@ impl Service { req: Request<::hyper::body::Incoming>, conn_data: ConnData, ) -> Result, std::convert::Infallible> { - let request_id = ulid::Ulid::new(); + let request_id = uuid::Uuid::now_v7(); let authreq = auth::Request { when_sec: Some(self.db.clocks().realtime().as_secs()), addr: if self.trust_forward_hdrs { @@ -340,7 +340,7 @@ impl Service { // https://opentelemetry.io/docs/reference/specification/trace/semantic_conventions/http/ let span = tracing::info_span!( "request", - %request_id, + request_id = %data_encoding::BASE32_NOPAD.encode_display(request_id.as_bytes()), net.sock.peer.uid = conn_data.client_unix_uid.map(tracing::field::display), http.client_ip = authreq.addr.map(tracing::field::display), http.method = %req.method(),