wip: make the payloads for objects random

This commit is contained in:
Jeremy Wall 2025-04-01 21:34:58 -04:00
parent e4a53e9f92
commit be288dfcd6
4 changed files with 116 additions and 7 deletions

104
Cargo.lock generated
View File

@ -86,6 +86,12 @@ dependencies = [
"windows-targets", "windows-targets",
] ]
[[package]]
name = "bitflags"
version = "2.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd"
[[package]] [[package]]
name = "bytes" name = "bytes"
version = "1.10.1" version = "1.10.1"
@ -146,6 +152,18 @@ dependencies = [
"pin-utils", "pin-utils",
] ]
[[package]]
name = "getrandom"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0"
dependencies = [
"cfg-if",
"libc",
"r-efi",
"wasi 0.14.2+wasi-0.2.4",
]
[[package]] [[package]]
name = "gimli" name = "gimli"
version = "0.31.1" version = "0.31.1"
@ -285,7 +303,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd"
dependencies = [ dependencies = [
"libc", "libc",
"wasi", "wasi 0.11.0+wasi-snapshot-preview1",
"windows-sys", "windows-sys",
] ]
@ -303,6 +321,7 @@ name = "offline-web"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"axum", "axum",
"rand",
"serde", "serde",
"tokio", "tokio",
] ]
@ -331,6 +350,15 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "ppv-lite86"
version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
dependencies = [
"zerocopy",
]
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.94" version = "1.0.94"
@ -349,6 +377,42 @@ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]]
name = "r-efi"
version = "5.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5"
[[package]]
name = "rand"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94"
dependencies = [
"rand_chacha",
"rand_core",
"zerocopy",
]
[[package]]
name = "rand_chacha"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
dependencies = [
"getrandom",
]
[[package]] [[package]]
name = "rustc-demangle" name = "rustc-demangle"
version = "0.1.24" version = "0.1.24"
@ -540,6 +604,15 @@ version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasi"
version = "0.14.2+wasi-0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3"
dependencies = [
"wit-bindgen-rt",
]
[[package]] [[package]]
name = "windows-sys" name = "windows-sys"
version = "0.52.0" version = "0.52.0"
@ -612,3 +685,32 @@ name = "windows_x86_64_msvc"
version = "0.52.6" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "wit-bindgen-rt"
version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"
dependencies = [
"bitflags",
]
[[package]]
name = "zerocopy"
version = "0.8.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2586fea28e186957ef732a5f8b3be2da217d65c5969d4b1e17f973ebbe876879"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.8.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a996a8f63c5c4448cd959ac1bab0aaa3306ccfd060472f85943ee0750f0169be"
dependencies = [
"proc-macro2",
"quote",
"syn",
]

View File

@ -12,5 +12,6 @@ path = "src/main.rs"
[dependencies] [dependencies]
axum = "0.8.3" axum = "0.8.3"
rand = "0.9.0"
serde = { version = "1.0.219", features = ["derive", "rc"] } serde = { version = "1.0.219", features = ["derive", "rc"] }
tokio = "1.44.1" tokio = "1.44.1"

View File

@ -1,6 +1,6 @@
use std::rc::Rc; use std::rc::Rc;
use axum::{extract::Path, http::{self, Response}, response::{AppendHeaders, Html, IntoResponse}, routing::get, Json, Router}; use axum::{extract::Path, http, response::{Html, IntoResponse}, routing::get, Json, Router};
use datamodel::Reference; use datamodel::Reference;
mod datamodel; mod datamodel;
@ -60,7 +60,13 @@ async fn dummy_subitem_ref(Path(i): Path<usize>, Path(j): Path<usize>) -> Json<R
} }
async fn dummy_object(Path(addr): Path<String>) -> String { async fn dummy_object(Path(addr): Path<String>) -> String {
format!("I am object {}", addr) use rand::Rng;
let mut rng = rand::rng();
let random_size = rng.random_range(50..=4096);
let random_string: String = (0..random_size)
.map(|_| rng.sample(rand::distr::Alphanumeric) as char)
.collect();
format!("I am object {} -- {}", addr, random_string)
} }
async fn get_client_js() -> impl IntoResponse { async fn get_client_js() -> impl IntoResponse {

View File

@ -99,7 +99,7 @@ async function load_objects_and_store(db, references, storeName) {
if (!response.ok) { if (!response.ok) {
throw new Error("Network response was not ok: " + response.statusText); throw new Error("Network response was not ok: " + response.statusText);
} }
let object = await response.text(); const object = await response.text();
objects.push({ id: ref.content_address, content: object }); objects.push({ id: ref.content_address, content: object });
} }
const objectTrxAndStore = await getStoreAndTransaction(db, storeName); const objectTrxAndStore = await getStoreAndTransaction(db, storeName);
@ -130,7 +130,7 @@ async function bootstrap() {
const objectStoreName = "objects"; const objectStoreName = "objects";
const databaseName = "MerkleStore"; const databaseName = "MerkleStore";
const start = new Date().getTime(); const start = new Date().getTime();
let root = await load_bootstrap(); const root = await load_bootstrap();
const db = await openDatabase(databaseName, [refStoreName, objectStoreName]); const db = await openDatabase(databaseName, [refStoreName, objectStoreName]);
const refTrxAndStore = await getStoreAndTransaction(db, refStoreName); const refTrxAndStore = await getStoreAndTransaction(db, refStoreName);
@ -140,13 +140,13 @@ async function bootstrap() {
refTrxAndStore.trx.onerror = (event) => reject(event.target.error); refTrxAndStore.trx.onerror = (event) => reject(event.target.error);
}); });
let refs = await load_reference_paths(refTrxAndStore.store, root); const refs = await load_reference_paths(refTrxAndStore.store, root);
// Wait for the transaction to complete // Wait for the transaction to complete
await transactionComplete; await transactionComplete;
await load_objects_and_store(db, refs, objectStoreName); await load_objects_and_store(db, refs, objectStoreName);
var end = new Date().getTime(); const end = new Date().getTime();
return end - start; return end - start;
} }