From 2ca7c60c7bc1218d80e859e58acc570aa7c414e2 Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Fri, 15 Dec 2023 16:21:06 -0500 Subject: [PATCH] update to wit 0.5.0 --- .gitignore | 1 + Cargo.lock | 26 ++++- Cargo.toml | 1 + build.rs | 11 ++ modules/app_store/app_store/Cargo.lock | 2 +- modules/app_store/app_store/Cargo.toml | 2 +- modules/app_store/app_store/src/lib.rs | 2 +- modules/app_store/ft_worker/Cargo.lock | 2 +- modules/app_store/ft_worker/Cargo.toml | 2 +- .../app_store/ft_worker/src/ft_worker_lib.rs | 4 +- modules/app_store/ft_worker/src/lib.rs | 7 +- modules/app_store/pkg/manifest.json | 2 +- modules/chess/Cargo.lock | 2 +- modules/chess/Cargo.toml | 2 +- modules/chess/pkg/manifest.json | 2 +- modules/homepage/Cargo.lock | 2 +- modules/homepage/Cargo.toml | 2 +- modules/homepage/pkg/manifest.json | 2 +- modules/key_value/key_value/Cargo.lock | 2 +- modules/key_value/key_value/Cargo.toml | 2 +- modules/key_value/key_value/src/lib.rs | 6 +- modules/key_value/key_value_worker/Cargo.lock | 2 +- modules/key_value/key_value_worker/Cargo.toml | 2 +- modules/key_value/pkg/manifest.json | 2 +- modules/qns_indexer/Cargo.lock | 2 +- modules/qns_indexer/Cargo.toml | 2 +- modules/qns_indexer/pkg/manifest.json | 2 +- modules/sqlite/pkg/manifest.json | 2 +- modules/sqlite/sqlite/Cargo.lock | 2 +- modules/sqlite/sqlite/Cargo.toml | 2 +- modules/sqlite/sqlite/src/lib.rs | 101 +++++++++--------- modules/terminal/Cargo.lock | 2 +- modules/terminal/Cargo.toml | 2 +- modules/terminal/pkg/manifest.json | 2 +- modules/tester/pkg/manifest.json | 2 +- modules/tester/test_runner/Cargo.lock | 2 +- modules/tester/test_runner/Cargo.toml | 2 +- modules/tester/test_runner/src/lib.rs | 64 ++++++----- modules/tester/tester/Cargo.lock | 2 +- modules/tester/tester/Cargo.toml | 2 +- modules/tester/tester/src/lib.rs | 60 ++++++----- src/filesystem/mod.rs | 8 +- src/kernel/mod.rs | 10 +- src/kernel/process.rs | 12 +-- src/kernel/standard_host.rs | 12 ++- src/types.rs | 71 +++++++----- wit/uqbar.wit | 13 +-- 47 files changed, 274 insertions(+), 195 deletions(-) diff --git a/.gitignore b/.gitignore index 219e3943..c1d2267b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ target/ +wit/ uqbar .vscode .app-signing diff --git a/Cargo.lock b/Cargo.lock index bf4c8482..f690e286 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3727,9 +3727,9 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "reqwest" -version = "0.11.20" +version = "0.11.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e9ad3fe7488d7e34558a2033d45a0c90b72d97b4f80705666fea71472e2e6a1" +checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b" dependencies = [ "base64 0.21.4", "bytes", @@ -3755,6 +3755,7 @@ dependencies = [ "serde", "serde_json", "serde_urlencoded", + "system-configuration", "tokio", "tokio-native-tls", "tokio-rustls", @@ -4603,6 +4604,27 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "system-configuration" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "system-interface" version = "0.26.0" diff --git a/Cargo.toml b/Cargo.toml index e6377d6f..16b1f1ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ repository = "https://github.com/uqbar-dao/uqbar" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [build-dependencies] +reqwest = { version = "0.11.22", features = ["blocking"] } sha2 = "0.10" walkdir = "2.4" zip = "0.6" diff --git a/build.rs b/build.rs index e0efecd0..61b4310e 100644 --- a/build.rs +++ b/build.rs @@ -135,6 +135,17 @@ fn main() { let pwd = std::env::current_dir().unwrap(); + // Pull wit from git repo + let wit_dir = pwd.join("wit"); + fs::create_dir_all(&wit_dir).unwrap(); + let wit_file = wit_dir.join("uqbar.wit"); + if !wit_file.exists() { + let mut wit_file = std::fs::File::create(&wit_file).unwrap(); + let uqbar_wit_url = "https://raw.githubusercontent.com/uqbar-dao/uqwit/dr/0.5.0/uqbar.wit"; + let mut response = reqwest::blocking::get(uqbar_wit_url).unwrap(); + io::copy(&mut response, &mut wit_file).unwrap(); + } + // Create target.wasm (compiled .wit) & world run_command(Command::new("wasm-tools").args([ "component", diff --git a/modules/app_store/app_store/Cargo.lock b/modules/app_store/app_store/Cargo.lock index 5f47f51b..36c26a1d 100644 --- a/modules/app_store/app_store/Cargo.lock +++ b/modules/app_store/app_store/Cargo.lock @@ -423,7 +423,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "uqbar_process_lib" version = "0.4.0" -source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=3ea3a23#3ea3a23de46cda8ebe1ea8f3b9f764b57e7feada" +source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=c23c423#c23c4236e1054632fc1b159b959789ce8d1250d9" dependencies = [ "anyhow", "bincode", diff --git a/modules/app_store/app_store/Cargo.toml b/modules/app_store/app_store/Cargo.toml index 6dc0f059..04ba2af5 100644 --- a/modules/app_store/app_store/Cargo.toml +++ b/modules/app_store/app_store/Cargo.toml @@ -17,7 +17,7 @@ rand = "0.8" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" sha2 = "0.10.8" -uqbar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "3ea3a23" } +uqbar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "c23c423" } wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" } [lib] diff --git a/modules/app_store/app_store/src/lib.rs b/modules/app_store/app_store/src/lib.rs index c41268e1..241a906f 100644 --- a/modules/app_store/app_store/src/lib.rs +++ b/modules/app_store/app_store/src/lib.rs @@ -508,7 +508,7 @@ fn handle_local_request( .ipc(serde_json::to_vec(&kt::KernelCommand::InitializeProcess { id: parsed_new_process_id, wasm_bytes_handle: hash, - on_panic: entry.on_panic.clone(), + on_exit: entry.on_exit.clone(), initial_capabilities, public: entry.public, })?) diff --git a/modules/app_store/ft_worker/Cargo.lock b/modules/app_store/ft_worker/Cargo.lock index b446fae6..a5f32f19 100644 --- a/modules/app_store/ft_worker/Cargo.lock +++ b/modules/app_store/ft_worker/Cargo.lock @@ -357,7 +357,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "uqbar_process_lib" version = "0.4.0" -source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=3ea3a23#3ea3a23de46cda8ebe1ea8f3b9f764b57e7feada" +source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=c23c423#c23c4236e1054632fc1b159b959789ce8d1250d9" dependencies = [ "anyhow", "bincode", diff --git a/modules/app_store/ft_worker/Cargo.toml b/modules/app_store/ft_worker/Cargo.toml index 4a46888b..98d4a592 100644 --- a/modules/app_store/ft_worker/Cargo.toml +++ b/modules/app_store/ft_worker/Cargo.toml @@ -16,7 +16,7 @@ bincode = "1.3.3" rand = "0.8" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -uqbar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "3ea3a23" } +uqbar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "c23c423" } wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" } [lib] diff --git a/modules/app_store/ft_worker/src/ft_worker_lib.rs b/modules/app_store/ft_worker/src/ft_worker_lib.rs index 70b9c9e5..4bf6db56 100644 --- a/modules/app_store/ft_worker/src/ft_worker_lib.rs +++ b/modules/app_store/ft_worker/src/ft_worker_lib.rs @@ -55,7 +55,7 @@ pub fn spawn_transfer( let Ok(worker_process_id) = spawn( Some(&transfer_id.to_string()), "/ft_worker.wasm".into(), - &OnPanic::None, // can set message-on-panic here + &OnExit::None, // can set message-on-panic here &Capabilities::All, false, // not public ) else { @@ -106,7 +106,7 @@ pub fn spawn_receive_transfer(our: &Address, ipc: &[u8]) { let Ok(worker_process_id) = spawn( Some(&transfer_id.to_string()), "/ft_worker.wasm".into(), - &OnPanic::None, // can set message-on-panic here + &OnExit::None, // can set message-on-panic here &Capabilities::All, false, // not public ) else { diff --git a/modules/app_store/ft_worker/src/lib.rs b/modules/app_store/ft_worker/src/lib.rs index 5cb1fc79..0c533ed1 100644 --- a/modules/app_store/ft_worker/src/lib.rs +++ b/modules/app_store/ft_worker/src/lib.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; //use uqbar_process_lib::uqbar::process::standard::*; use uqbar_process_lib::uqbar::process::standard::{Message as StdMessage, Request as StdRequest, Response as StdResponse, SendErrorKind}; -use uqbar_process_lib::{await_message, get_payload, print_to_terminal, send_and_await_response, send_request, send_response, Address, Message, Payload, Request}; +use uqbar_process_lib::{await_message, get_payload, print_to_terminal, send_and_await_response, send_request, send_response, Address, Message, Payload}; mod ft_worker_lib; use ft_worker_lib::*; @@ -129,7 +129,7 @@ impl Guest for Component { offset += chunk_size; } // now wait for Finished response - let Ok(Message::Response { source: receiving_worker, ipc, .. }) = await_message() else { + let Ok(Message::Response { ipc, .. }) = await_message() else { respond_to_parent(FTWorkerResult::Err(TransferError::TargetRejected)); return; }; @@ -144,11 +144,10 @@ impl Guest for Component { } } FTWorkerCommand::Receive { - transfer_id, file_name, - file_size, total_chunks, timeout, + .. } => { // send Ready response to counterparty send_response( diff --git a/modules/app_store/pkg/manifest.json b/modules/app_store/pkg/manifest.json index a3d11081..a20bdee9 100644 --- a/modules/app_store/pkg/manifest.json +++ b/modules/app_store/pkg/manifest.json @@ -2,7 +2,7 @@ { "process_name": "main", "process_wasm_path": "/app_store.wasm", - "on_panic": "Restart", + "on_exit": "Restart", "request_networking": true, "request_messaging": [ "terminal:terminal:uqbar", diff --git a/modules/chess/Cargo.lock b/modules/chess/Cargo.lock index e0f2369e..2325afb3 100644 --- a/modules/chess/Cargo.lock +++ b/modules/chess/Cargo.lock @@ -632,7 +632,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "uqbar_process_lib" version = "0.4.0" -source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=c6dd31b#c6dd31bcdc3d83a1d5d4c528e390164d20f373cd" +source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=1ce0d41#1ce0d412169e795c2a99464563b42ae2a2628d77" dependencies = [ "anyhow", "bincode", diff --git a/modules/chess/Cargo.toml b/modules/chess/Cargo.toml index 1ab1202f..b1aece4d 100644 --- a/modules/chess/Cargo.toml +++ b/modules/chess/Cargo.toml @@ -16,7 +16,7 @@ pleco = "0.5" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" url = "*" -uqbar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "c6dd31b" } +uqbar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "1ce0d41" } wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" } [lib] diff --git a/modules/chess/pkg/manifest.json b/modules/chess/pkg/manifest.json index 41d71b7f..c06cffe2 100644 --- a/modules/chess/pkg/manifest.json +++ b/modules/chess/pkg/manifest.json @@ -2,7 +2,7 @@ { "process_name": "chess", "process_wasm_path": "/chess.wasm", - "on_panic": "Restart", + "on_exit": "Restart", "request_networking": true, "request_messaging": [ "net:sys:uqbar" diff --git a/modules/homepage/Cargo.lock b/modules/homepage/Cargo.lock index be3b98e1..17ecc82d 100644 --- a/modules/homepage/Cargo.lock +++ b/modules/homepage/Cargo.lock @@ -356,7 +356,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "uqbar_process_lib" version = "0.4.0" -source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=3ea3a23#3ea3a23de46cda8ebe1ea8f3b9f764b57e7feada" +source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=1ce0d41#1ce0d412169e795c2a99464563b42ae2a2628d77" dependencies = [ "anyhow", "bincode", diff --git a/modules/homepage/Cargo.toml b/modules/homepage/Cargo.toml index b42898dd..e43572de 100644 --- a/modules/homepage/Cargo.toml +++ b/modules/homepage/Cargo.toml @@ -15,7 +15,7 @@ anyhow = "1.0" bincode = "1.3.3" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -uqbar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "3ea3a23" } +uqbar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "1ce0d41" } wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" } [lib] diff --git a/modules/homepage/pkg/manifest.json b/modules/homepage/pkg/manifest.json index 0a9fac58..22317c4d 100644 --- a/modules/homepage/pkg/manifest.json +++ b/modules/homepage/pkg/manifest.json @@ -2,7 +2,7 @@ { "process_name": "homepage", "process_wasm_path": "/homepage.wasm", - "on_panic": "Restart", + "on_exit": "Restart", "request_networking": false, "request_messaging": [ "http_bindings:http_bindings:uqbar", diff --git a/modules/key_value/key_value/Cargo.lock b/modules/key_value/key_value/Cargo.lock index 983a5c5c..5453f891 100644 --- a/modules/key_value/key_value/Cargo.lock +++ b/modules/key_value/key_value/Cargo.lock @@ -357,7 +357,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "uqbar_process_lib" version = "0.4.0" -source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=3ea3a23#3ea3a23de46cda8ebe1ea8f3b9f764b57e7feada" +source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=1ce0d41#1ce0d412169e795c2a99464563b42ae2a2628d77" dependencies = [ "anyhow", "bincode", diff --git a/modules/key_value/key_value/Cargo.toml b/modules/key_value/key_value/Cargo.toml index dfe0b09e..052ee5cb 100644 --- a/modules/key_value/key_value/Cargo.toml +++ b/modules/key_value/key_value/Cargo.toml @@ -16,7 +16,7 @@ bincode = "1.3.3" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "1.0" -uqbar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "3ea3a23" } +uqbar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "1ce0d41" } wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" } [lib] diff --git a/modules/key_value/key_value/src/lib.rs b/modules/key_value/key_value/src/lib.rs index 999b27e2..ace00b78 100644 --- a/modules/key_value/key_value/src/lib.rs +++ b/modules/key_value/key_value/src/lib.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; // use serde::{Deserialize, Serialize}; -use uqbar_process_lib::{Address, ProcessId, Request, Response}; +use uqbar_process_lib::{spawn, OnExit, Address, ProcessId, Request, Response}; use uqbar_process_lib::kernel_types as kt; use uqbar_process_lib::uqbar::process::standard as wit; @@ -116,10 +116,10 @@ fn handle_message(our: &Address, db_to_process: &mut DbToProcess) -> anyhow::Res &source, &"\"messaging\"".into(), ).ok_or(anyhow::anyhow!("New failed: no source 'messaging' capability found"))?; - let spawned_process_id = match wit::spawn( + let spawned_process_id = match spawn( None, "/key_value_worker.wasm", - &wit::OnPanic::None, // TODO: notify us + OnExit::None, // TODO: notify us &wit::Capabilities::Some(vec![vfs_read, vfs_write, messaging]), false, // not public ) { diff --git a/modules/key_value/key_value_worker/Cargo.lock b/modules/key_value/key_value_worker/Cargo.lock index b9dafc97..4dd5793e 100644 --- a/modules/key_value/key_value_worker/Cargo.lock +++ b/modules/key_value/key_value_worker/Cargo.lock @@ -497,7 +497,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "uqbar_process_lib" version = "0.4.0" -source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=3ea3a23#3ea3a23de46cda8ebe1ea8f3b9f764b57e7feada" +source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=1ce0d41#1ce0d412169e795c2a99464563b42ae2a2628d77" dependencies = [ "anyhow", "bincode", diff --git a/modules/key_value/key_value_worker/Cargo.toml b/modules/key_value/key_value_worker/Cargo.toml index 9edeec9f..7e9f2489 100644 --- a/modules/key_value/key_value_worker/Cargo.toml +++ b/modules/key_value/key_value_worker/Cargo.toml @@ -17,7 +17,7 @@ redb = { git = "https://github.com/uqbar-dao/redb", rev = "8e192d9" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "1.0" -uqbar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "3ea3a23" } +uqbar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "1ce0d41" } wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" } [lib] diff --git a/modules/key_value/pkg/manifest.json b/modules/key_value/pkg/manifest.json index a872994b..081824a6 100644 --- a/modules/key_value/pkg/manifest.json +++ b/modules/key_value/pkg/manifest.json @@ -2,7 +2,7 @@ { "process_name": "key_value", "process_wasm_path": "/key_value.wasm", - "on_panic": "Restart", + "on_exit": "Restart", "request_networking": false, "request_messaging": [ "vfs:sys:uqbar" diff --git a/modules/qns_indexer/Cargo.lock b/modules/qns_indexer/Cargo.lock index d25c1b9b..25192556 100644 --- a/modules/qns_indexer/Cargo.lock +++ b/modules/qns_indexer/Cargo.lock @@ -757,7 +757,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "uqbar_process_lib" version = "0.4.0" -source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=3ea3a23#3ea3a23de46cda8ebe1ea8f3b9f764b57e7feada" +source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=1ce0d41#1ce0d412169e795c2a99464563b42ae2a2628d77" dependencies = [ "anyhow", "bincode", diff --git a/modules/qns_indexer/Cargo.toml b/modules/qns_indexer/Cargo.toml index 74a88401..6a04fd14 100644 --- a/modules/qns_indexer/Cargo.toml +++ b/modules/qns_indexer/Cargo.toml @@ -19,7 +19,7 @@ hex = "0.4.3" rmp-serde = "1.1.2" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -uqbar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "3ea3a23" } +uqbar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "1ce0d41" } wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" } [lib] diff --git a/modules/qns_indexer/pkg/manifest.json b/modules/qns_indexer/pkg/manifest.json index 859ebaae..e482a7e2 100644 --- a/modules/qns_indexer/pkg/manifest.json +++ b/modules/qns_indexer/pkg/manifest.json @@ -2,7 +2,7 @@ { "process_name": "qns_indexer", "process_wasm_path": "/qns_indexer.wasm", - "on_panic": "Restart", + "on_exit": "Restart", "request_networking": true, "request_messaging": [ "net:sys:uqbar", diff --git a/modules/sqlite/pkg/manifest.json b/modules/sqlite/pkg/manifest.json index ca3522ad..97ced767 100644 --- a/modules/sqlite/pkg/manifest.json +++ b/modules/sqlite/pkg/manifest.json @@ -2,7 +2,7 @@ { "process_name": "sqlite", "process_wasm_path": "/sqlite.wasm", - "on_panic": "Restart", + "on_exit": "Restart", "request_networking": false, "request_messaging": [ "vfs:sys:uqbar" diff --git a/modules/sqlite/sqlite/Cargo.lock b/modules/sqlite/sqlite/Cargo.lock index 90a7d1b5..848b09ca 100644 --- a/modules/sqlite/sqlite/Cargo.lock +++ b/modules/sqlite/sqlite/Cargo.lock @@ -357,7 +357,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "uqbar_process_lib" version = "0.4.0" -source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=3ea3a23#3ea3a23de46cda8ebe1ea8f3b9f764b57e7feada" +source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=1ce0d41#1ce0d412169e795c2a99464563b42ae2a2628d77" dependencies = [ "anyhow", "bincode", diff --git a/modules/sqlite/sqlite/Cargo.toml b/modules/sqlite/sqlite/Cargo.toml index d0ef03c0..a091a1bf 100644 --- a/modules/sqlite/sqlite/Cargo.toml +++ b/modules/sqlite/sqlite/Cargo.toml @@ -16,7 +16,7 @@ bincode = "1.3.3" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "1.0" -uqbar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "3ea3a23" } +uqbar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "1ce0d41" } wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" } [lib] diff --git a/modules/sqlite/sqlite/src/lib.rs b/modules/sqlite/sqlite/src/lib.rs index cb7f2747..54ab8e85 100644 --- a/modules/sqlite/sqlite/src/lib.rs +++ b/modules/sqlite/sqlite/src/lib.rs @@ -1,8 +1,8 @@ use std::collections::{HashMap, HashSet}; -use uqbar_process_lib::{Address, ProcessId, Request, Response}; use uqbar_process_lib::kernel_types as kt; use uqbar_process_lib::uqbar::process::standard as wit; +use uqbar_process_lib::{spawn, Address, OnExit, ProcessId, Request, Response}; wit_bindgen::generate!({ path: "../../../wit", @@ -23,14 +23,16 @@ fn make_vfs_cap(kind: &str, drive: &str) -> String { serde_json::to_string(&serde_json::json!({ "kind": kind, "drive": drive, - })).unwrap() + })) + .unwrap() } fn make_db_cap(kind: &str, db: &str) -> String { serde_json::to_string(&serde_json::json!({ "kind": kind, "db": db, - })).unwrap() + })) + .unwrap() } fn forward_if_have_cap( @@ -62,7 +64,7 @@ fn forward_if_have_cap( } } -fn handle_message ( +fn handle_message( our: &Address, db_to_process: &mut DbToProcess, read_keywords: &HashSet, @@ -77,7 +79,7 @@ fn handle_message ( match message { wit::Message::Response(_) => { return Err(sq::SqliteError::UnexpectedResponse.into()); - }, + } wit::Message::Request(wit::Request { ipc, .. }) => { match serde_json::from_slice(&ipc)? { sq::SqliteMessage::New { ref db } => { @@ -103,36 +105,37 @@ fn handle_message ( drive: vfs_drive.clone(), action: kt::VfsAction::New, })?) - .send_and_await_response(15)?.unwrap(); + .send_and_await_response(15)? + .unwrap(); // (2) - let vfs_read = wit::get_capability( - &vfs_address, - &make_vfs_cap("read", &vfs_drive), - ).ok_or(anyhow::anyhow!("New failed: no vfs 'read' capability found"))?; + let vfs_read = + wit::get_capability(&vfs_address, &make_vfs_cap("read", &vfs_drive)) + .ok_or(anyhow::anyhow!( + "New failed: no vfs 'read' capability found" + ))?; - let vfs_write = wit::get_capability( - &vfs_address, - &make_vfs_cap("write", &vfs_drive), - ).ok_or(anyhow::anyhow!("New failed: no vfs 'write' capability found"))?; + let vfs_write = + wit::get_capability(&vfs_address, &make_vfs_cap("write", &vfs_drive)) + .ok_or(anyhow::anyhow!( + "New failed: no vfs 'write' capability found" + ))?; - let msg_cap = wit::get_capability( - &source, - &"\"messaging\"".into(), - ).ok_or(anyhow::anyhow!("New failed: no msg capability passed"))?; + let msg_cap = wit::get_capability(&source, &"\"messaging\"".into()) + .ok_or(anyhow::anyhow!("New failed: no msg capability passed"))?; - let spawned_process_id = match wit::spawn( + let spawned_process_id = match spawn( None, "/sqlite_worker.wasm", - &wit::OnPanic::None, + OnExit::None, &wit::Capabilities::Some(vec![vfs_read, vfs_write, msg_cap]), false, // not public ) { Ok(spawned_process_id) => spawned_process_id, Err(e) => { wit::print_to_terminal(0, &format!("couldn't spawn: {}", e)); - panic!("couldn't spawn"); // TODO - }, + panic!("couldn't spawn"); // TODO + } }; // grant caps wit::create_capability(&source.process, &make_db_cap("read", db)); @@ -148,21 +151,23 @@ fn handle_message ( db_to_process.insert(db.into(), spawned_process_id); - Response::new() - .ipc(ipc) - .send()?; - }, - sq::SqliteMessage::Write { ref db, ref statement, .. } => { + Response::new().ipc(ipc).send()?; + } + sq::SqliteMessage::Write { + ref db, + ref statement, + .. + } => { let first_word = statement .split_whitespace() .next() .map(|word| word.to_uppercase()) .unwrap_or("".to_string()); if !write_keywords.contains(&first_word) { - return Err(sq::SqliteError::NotAWriteKeyword.into()) + return Err(sq::SqliteError::NotAWriteKeyword.into()); } forward_if_have_cap(our, "write", db, ipc, db_to_process)?; - }, + } sq::SqliteMessage::Read { ref db, ref query } => { let first_word = query .split_whitespace() @@ -170,17 +175,17 @@ fn handle_message ( .map(|word| word.to_uppercase()) .unwrap_or("".to_string()); if !read_keywords.contains(&first_word) { - return Err(sq::SqliteError::NotAReadKeyword.into()) + return Err(sq::SqliteError::NotAReadKeyword.into()); } forward_if_have_cap(our, "read", db, ipc, db_to_process)?; - }, + } sq::SqliteMessage::Commit { ref db, .. } => { forward_if_have_cap(our, "write", db, ipc, db_to_process)?; - }, + } } Ok(()) - }, + } } } @@ -194,18 +199,11 @@ impl Guest for Component { let mut db_to_process: DbToProcess = HashMap::new(); let read_keywords: HashSet = [ - "ANALYZE", - "ATTACH", - "BEGIN", - "EXPLAIN", - "PRAGMA", - "SELECT", - "VALUES", - "WITH", + "ANALYZE", "ATTACH", "BEGIN", "EXPLAIN", "PRAGMA", "SELECT", "VALUES", "WITH", ] - .iter() - .map(|x| x.to_string()) - .collect(); + .iter() + .map(|x| x.to_string()) + .collect(); let write_keywords: HashSet = [ "ALTER", "ANALYZE", @@ -225,25 +223,22 @@ impl Guest for Component { "UPDATE", "VACUUM", ] - .iter() - .map(|x| x.to_string()) - .collect(); + .iter() + .map(|x| x.to_string()) + .collect(); loop { match handle_message(&our, &mut db_to_process, &read_keywords, &write_keywords) { - Ok(()) => {}, + Ok(()) => {} Err(e) => { - wit::print_to_terminal(0, format!( - "sqlite: error: {:?}", - e, - ).as_str()); + wit::print_to_terminal(0, format!("sqlite: error: {:?}", e,).as_str()); if let Some(e) = e.downcast_ref::() { Response::new() .ipc(serde_json::to_vec(&e).unwrap()) .send() .unwrap(); } - }, + } }; } } diff --git a/modules/terminal/Cargo.lock b/modules/terminal/Cargo.lock index 7f12a196..43d4e4af 100644 --- a/modules/terminal/Cargo.lock +++ b/modules/terminal/Cargo.lock @@ -356,7 +356,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "uqbar_process_lib" version = "0.4.0" -source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=3ea3a23#3ea3a23de46cda8ebe1ea8f3b9f764b57e7feada" +source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=1ce0d41#1ce0d412169e795c2a99464563b42ae2a2628d77" dependencies = [ "anyhow", "bincode", diff --git a/modules/terminal/Cargo.toml b/modules/terminal/Cargo.toml index 696702ba..955fe4cd 100644 --- a/modules/terminal/Cargo.toml +++ b/modules/terminal/Cargo.toml @@ -15,7 +15,7 @@ anyhow = "1.0" bincode = "1.3.3" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -uqbar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "3ea3a23" } +uqbar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "1ce0d41" } wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" } [lib] diff --git a/modules/terminal/pkg/manifest.json b/modules/terminal/pkg/manifest.json index 18164233..84617638 100644 --- a/modules/terminal/pkg/manifest.json +++ b/modules/terminal/pkg/manifest.json @@ -2,7 +2,7 @@ { "process_name": "terminal", "process_wasm_path": "/terminal.wasm", - "on_panic": "Restart", + "on_exit": "Restart", "request_networking": true, "request_messaging": [ "net:sys:uqbar", diff --git a/modules/tester/pkg/manifest.json b/modules/tester/pkg/manifest.json index 52add7ce..99b02e43 100644 --- a/modules/tester/pkg/manifest.json +++ b/modules/tester/pkg/manifest.json @@ -2,7 +2,7 @@ { "process_name": "tester", "process_wasm_path": "/tester.wasm", - "on_panic": "Restart", + "on_exit": "Restart", "request_networking": true, "request_messaging": [ "net:sys:uqbar" diff --git a/modules/tester/test_runner/Cargo.lock b/modules/tester/test_runner/Cargo.lock index ccc5093c..e930bf41 100644 --- a/modules/tester/test_runner/Cargo.lock +++ b/modules/tester/test_runner/Cargo.lock @@ -357,7 +357,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "uqbar_process_lib" version = "0.4.0" -source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=3ea3a23#3ea3a23de46cda8ebe1ea8f3b9f764b57e7feada" +source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=1ce0d41#1ce0d412169e795c2a99464563b42ae2a2628d77" dependencies = [ "anyhow", "bincode", diff --git a/modules/tester/test_runner/Cargo.toml b/modules/tester/test_runner/Cargo.toml index 8a00026d..5515a8f5 100644 --- a/modules/tester/test_runner/Cargo.toml +++ b/modules/tester/test_runner/Cargo.toml @@ -16,7 +16,7 @@ bincode = "1.3.3" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "1.0" -uqbar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "3ea3a23" } +uqbar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "1ce0d41" } wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" } [lib] diff --git a/modules/tester/test_runner/src/lib.rs b/modules/tester/test_runner/src/lib.rs index 1665e079..18f091d9 100644 --- a/modules/tester/test_runner/src/lib.rs +++ b/modules/tester/test_runner/src/lib.rs @@ -1,9 +1,9 @@ -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::collections::{HashMap, HashSet}; -use uqbar_process_lib::{Address, Message, ProcessId, Request, Response}; use uqbar_process_lib::kernel_types as kt; use uqbar_process_lib::uqbar::process::standard as wit; +use uqbar_process_lib::{spawn, Address, Message, OnExit, ProcessId, Request, Response}; mod tester_types; use tester_types as tt; @@ -33,7 +33,7 @@ fn handle_message(our: &Address) -> anyhow::Result<()> { match message { wit::Message::Response(_) => { return Err(tt::TesterError::UnexpectedResponse.into()); - }, + } wit::Message::Request(wit::Request { ref ipc, .. }) => { match serde_json::from_slice(ipc)? { tt::TesterRequest::Run { test_timeout, .. } => { @@ -45,11 +45,17 @@ fn handle_message(our: &Address) -> anyhow::Result<()> { drive: "tester:uqbar".into(), action: kt::VfsAction::GetEntry("/".into()), })?) - .send_and_await_response(test_timeout)?.unwrap(); + .send_and_await_response(test_timeout)? + .unwrap(); - let Message::Response { ipc: vfs_ipc, .. } = response else { panic!("") }; + let Message::Response { ipc: vfs_ipc, .. } = response else { + panic!("") + }; let kt::VfsResponse::GetEntry { children, .. } = - serde_json::from_slice(&vfs_ipc)? else { panic!("") }; + serde_json::from_slice(&vfs_ipc)? + else { + panic!("") + }; let mut children: HashSet<_> = children.into_iter().collect(); children.remove("/manifest.json"); children.remove("/metadata.json"); @@ -59,16 +65,19 @@ fn handle_message(our: &Address) -> anyhow::Result<()> { wit::print_to_terminal(0, &format!("test_runner: running {:?}...", children)); for child in &children { - let child_process_id = match wit::spawn( + let child_process_id = match spawn( None, child, - &wit::OnPanic::None, // TODO: notify us + OnExit::None, // TODO: notify us &wit::Capabilities::All, false, // not public ) { Ok(child_process_id) => child_process_id, Err(e) => { - wit::print_to_terminal(0, &format!("couldn't spawn {}: {}", child, e)); + wit::print_to_terminal( + 0, + &format!("couldn't spawn {}: {}", child, e), + ); panic!("couldn't spawn"); // TODO } }; @@ -79,15 +88,23 @@ fn handle_message(our: &Address) -> anyhow::Result<()> { process: child_process_id, }) .ipc(ipc.clone()) - .send_and_await_response(test_timeout)?.unwrap(); + .send_and_await_response(test_timeout)? + .unwrap(); - let Message::Response { ipc, .. } = response else { panic!("") }; + let Message::Response { ipc, .. } = response else { + panic!("") + }; match serde_json::from_slice(&ipc)? { - tt::TesterResponse::Pass => {}, - tt::TesterResponse::GetFullMessage(_) => {}, - tt::TesterResponse::Fail { test, file, line, column } => { + tt::TesterResponse::Pass => {} + tt::TesterResponse::GetFullMessage(_) => {} + tt::TesterResponse::Fail { + test, + file, + line, + column, + } => { fail!(test, file, line, column); - }, + } } } @@ -97,11 +114,13 @@ fn handle_message(our: &Address) -> anyhow::Result<()> { .ipc(serde_json::to_vec(&tt::TesterResponse::Pass).unwrap()) .send() .unwrap(); - }, - tt::TesterRequest::KernelMessage(_) | tt::TesterRequest::GetFullMessage(_) => { unimplemented!() }, + } + tt::TesterRequest::KernelMessage(_) | tt::TesterRequest::GetFullMessage(_) => { + unimplemented!() + } } Ok(()) - }, + } } } @@ -119,14 +138,11 @@ impl Guest for Component { loop { match handle_message(&our) { - Ok(()) => {}, + Ok(()) => {} Err(e) => { - wit::print_to_terminal(0, format!( - "test_runner: error: {:?}", - e, - ).as_str()); + wit::print_to_terminal(0, format!("test_runner: error: {:?}", e,).as_str()); fail!("test_runner"); - }, + } }; } } diff --git a/modules/tester/tester/Cargo.lock b/modules/tester/tester/Cargo.lock index b34b3e3c..7c8a0ed1 100644 --- a/modules/tester/tester/Cargo.lock +++ b/modules/tester/tester/Cargo.lock @@ -358,7 +358,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "uqbar_process_lib" version = "0.4.0" -source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=3ea3a23#3ea3a23de46cda8ebe1ea8f3b9f764b57e7feada" +source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=1ce0d41#1ce0d412169e795c2a99464563b42ae2a2628d77" dependencies = [ "anyhow", "bincode", diff --git a/modules/tester/tester/Cargo.toml b/modules/tester/tester/Cargo.toml index 9c121bb9..39cd8198 100644 --- a/modules/tester/tester/Cargo.toml +++ b/modules/tester/tester/Cargo.toml @@ -17,7 +17,7 @@ indexmap = "2.1" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "1.0" -uqbar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "3ea3a23" } +uqbar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "1ce0d41" } wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" } [lib] diff --git a/modules/tester/tester/src/lib.rs b/modules/tester/tester/src/lib.rs index 2fecb26a..481c7202 100644 --- a/modules/tester/tester/src/lib.rs +++ b/modules/tester/tester/src/lib.rs @@ -1,8 +1,8 @@ use indexmap::map::IndexMap; -use uqbar_process_lib::{Address, ProcessId, Request, Response}; use uqbar_process_lib::kernel_types as kt; use uqbar_process_lib::uqbar::process::standard as wit; +use uqbar_process_lib::{spawn, Address, OnExit, ProcessId, Request, Response}; mod tester_types; use tester_types as tt; @@ -36,21 +36,24 @@ fn handle_message( match serde_json::from_slice(&ipc)? { tt::TesterResponse::Pass | tt::TesterResponse::Fail { .. } => { if (source.process.package_name != "tester") - | (source.process.publisher_node != "uqbar") { + | (source.process.publisher_node != "uqbar") + { return Err(tt::TesterError::UnexpectedResponse.into()); } - Response::new() - .ipc(ipc) - .send() - .unwrap(); - }, - tt::TesterResponse::GetFullMessage(_) => { unimplemented!() } + Response::new().ipc(ipc).send().unwrap(); + } + tt::TesterResponse::GetFullMessage(_) => { + unimplemented!() + } } Ok(()) - }, + } wit::Message::Request(wit::Request { ipc, .. }) => { match serde_json::from_slice(&ipc)? { - tt::TesterRequest::Run { input_node_names, test_timeout } => { + tt::TesterRequest::Run { + input_node_names, + test_timeout, + } => { wit::print_to_terminal(0, "tester: got Run"); assert!(input_node_names.len() >= 1); @@ -64,16 +67,19 @@ fn handle_message( } else { // we are master node let child = "/test_runner.wasm"; - let child_process_id = match wit::spawn( + let child_process_id = match spawn( None, child, - &wit::OnPanic::None, // TODO: notify us + OnExit::None, // TODO: notify us &wit::Capabilities::All, false, // not public ) { Ok(child_process_id) => child_process_id, Err(e) => { - wit::print_to_terminal(0, &format!("couldn't spawn {}: {}", child, e)); + wit::print_to_terminal( + 0, + &format!("couldn't spawn {}: {}", child, e), + ); panic!("couldn't spawn"); // TODO } }; @@ -86,11 +92,13 @@ fn handle_message( .expects_response(test_timeout) .send()?; } - }, - tt::TesterRequest::KernelMessage(_) | tt::TesterRequest::GetFullMessage(_) => { unimplemented!() }, + } + tt::TesterRequest::KernelMessage(_) | tt::TesterRequest::GetFullMessage(_) => { + unimplemented!() + } } Ok(()) - }, + } } } @@ -110,20 +118,22 @@ impl Guest for Component { &serde_json::to_string(&serde_json::json!({ "kind": "write", "drive": "tester:uqbar", - })).unwrap() - ).unwrap(); - wit::share_capability(&ProcessId::from_str("http_server:sys:uqbar").unwrap(), &drive_cap); + })) + .unwrap(), + ) + .unwrap(); + wit::share_capability( + &ProcessId::from_str("http_server:sys:uqbar").unwrap(), + &drive_cap, + ); loop { match handle_message(&our, &mut messages, &mut node_names) { - Ok(()) => {}, + Ok(()) => {} Err(e) => { - wit::print_to_terminal(0, format!( - "tester: error: {:?}", - e, - ).as_str()); + wit::print_to_terminal(0, format!("tester: error: {:?}", e,).as_str()); fail!("tester"); - }, + } }; } } diff --git a/src/filesystem/mod.rs b/src/filesystem/mod.rs index d32c2643..490bfd9c 100644 --- a/src/filesystem/mod.rs +++ b/src/filesystem/mod.rs @@ -146,7 +146,7 @@ async fn bootstrap( .entry(ProcessId::from_str("kernel:sys:uqbar").unwrap()) .or_insert(PersistedProcess { wasm_bytes_handle: 0, - on_panic: OnPanic::Restart, + on_exit: OnExit::Restart, capabilities: runtime_caps.clone(), public: false, }); @@ -154,7 +154,7 @@ async fn bootstrap( .entry(ProcessId::from_str("net:sys:uqbar").unwrap()) .or_insert(PersistedProcess { wasm_bytes_handle: 0, - on_panic: OnPanic::Restart, + on_exit: OnExit::Restart, capabilities: runtime_caps.clone(), public: false, }); @@ -163,7 +163,7 @@ async fn bootstrap( .entry(runtime_module.0) .or_insert(PersistedProcess { wasm_bytes_handle: 0, - on_panic: OnPanic::Restart, + on_exit: OnExit::Restart, capabilities: runtime_caps.clone(), public: runtime_module.2, }); @@ -380,7 +380,7 @@ async fn bootstrap( ProcessId::new(Some(&entry.process_name), package_name, package_publisher), PersistedProcess { wasm_bytes_handle, - on_panic: entry.on_panic, + on_exit: entry.on_exit, capabilities: requested_caps, public: public_process, }, diff --git a/src/kernel/mod.rs b/src/kernel/mod.rs index 25029848..5de3ad28 100644 --- a/src/kernel/mod.rs +++ b/src/kernel/mod.rs @@ -142,7 +142,7 @@ async fn handle_kernel_request( t::KernelCommand::InitializeProcess { id, wasm_bytes_handle, - on_panic, + on_exit, initial_capabilities, public, } => { @@ -248,7 +248,7 @@ async fn handle_kernel_request( process_id: id, persisted: t::PersistedProcess { wasm_bytes_handle, - on_panic, + on_exit, capabilities: valid_capabilities, public, }, @@ -572,7 +572,7 @@ async fn start_process( process: id.clone(), }, wasm_bytes_handle: process_metadata.persisted.wasm_bytes_handle, - on_panic: process_metadata.persisted.on_panic.clone(), + on_exit: process_metadata.persisted.on_exit.clone(), public: process_metadata.persisted.public, }; process_handles.insert( @@ -659,7 +659,7 @@ pub async fn kernel( for (process_id, persisted) in &process_map { // runtime extensions will have a bytes_handle of 0, because they have no // WASM code saved in filesystem. - if persisted.on_panic.is_restart() && persisted.wasm_bytes_handle != 0 { + if persisted.on_exit.is_restart() && persisted.wasm_bytes_handle != 0 { send_to_loop .send(t::KernelMessage { id: rand::random(), @@ -696,7 +696,7 @@ pub async fn kernel( .await .expect("event loop: fatal: sender died"); } - if let t::OnPanic::Requests(requests) = &persisted.on_panic { + if let t::OnExit::Requests(requests) = &persisted.on_exit { // if a persisted process had on-death-requests, we should perform them now // even in death, a process can only message processes it has capabilities for for (address, request, payload) in requests { diff --git a/src/kernel/process.rs b/src/kernel/process.rs index 1bbe1520..2f47fe32 100644 --- a/src/kernel/process.rs +++ b/src/kernel/process.rs @@ -534,11 +534,11 @@ pub async fn make_process_loop( .await .expect("event loop: fatal: sender died"); - // fulfill the designated OnPanic behavior - match metadata.on_panic { - t::OnPanic::None => {} + // fulfill the designated OnExit behavior + match metadata.on_exit { + t::OnExit::None => {} // if restart, tell ourselves to init the app again, with same capabilities - t::OnPanic::Restart => { + t::OnExit::Restart => { send_to_loop .send(t::KernelMessage { id: rand::random(), @@ -551,7 +551,7 @@ pub async fn make_process_loop( ipc: serde_json::to_vec(&t::KernelCommand::InitializeProcess { id: metadata.our.process.clone(), wasm_bytes_handle: metadata.wasm_bytes_handle, - on_panic: metadata.on_panic, + on_exit: metadata.on_exit, initial_capabilities, public: metadata.public, }) @@ -569,7 +569,7 @@ pub async fn make_process_loop( } // if requests, fire them // even in death, a process can only message processes it has capabilities for - t::OnPanic::Requests(requests) => { + t::OnExit::Requests(requests) => { for (address, mut request, payload) in requests { request.expects_response = None; let (tx, rx) = tokio::sync::oneshot::channel(); diff --git a/src/kernel/standard_host.rs b/src/kernel/standard_host.rs index c08884e0..a34f7965 100644 --- a/src/kernel/standard_host.rs +++ b/src/kernel/standard_host.rs @@ -40,11 +40,15 @@ impl StandardHost for process::ProcessWasi { // /// TODO critical: move to kernel logic to enable persistence of choice made here - async fn set_on_panic(&mut self, on_panic: wit::OnPanic) -> Result<()> { - self.process.metadata.on_panic = t::de_wit_on_panic(on_panic); + async fn set_on_exit(&mut self, on_exit: wit::OnExit) -> Result<()> { + self.process.metadata.on_exit = t::OnExit::de_wit(on_exit); Ok(()) } + async fn get_on_exit(&mut self) -> Result { + Ok(self.process.metadata.on_exit.en_wit()) + } + /// create a message from the *kernel* to the filesystem, /// asking it to fetch the current state saved under this process async fn get_state(&mut self) -> Result>> { @@ -171,7 +175,7 @@ impl StandardHost for process::ProcessWasi { &mut self, name: Option, wasm_path: String, // must be located within package's drive - on_panic: wit::OnPanic, + on_exit: wit::OnExit, capabilities: wit::Capabilities, public: bool, ) -> Result> { @@ -272,7 +276,7 @@ impl StandardHost for process::ProcessWasi { ipc: serde_json::to_vec(&t::KernelCommand::InitializeProcess { id: new_process_id.clone(), wasm_bytes_handle: hash, - on_panic: t::de_wit_on_panic(on_panic), + on_exit: t::OnExit::de_wit(on_exit), initial_capabilities: match capabilities { wit::Capabilities::None => HashSet::new(), wit::Capabilities::All => { diff --git a/src/types.rs b/src/types.rs index aed13560..7ded9cc4 100644 --- a/src/types.rs +++ b/src/types.rs @@ -428,18 +428,54 @@ pub enum SendErrorKind { } #[derive(Clone, Debug, Serialize, Deserialize)] -pub enum OnPanic { +pub enum OnExit { None, Restart, Requests(Vec<(Address, Request, Option)>), } -impl OnPanic { +impl OnExit { pub fn is_restart(&self) -> bool { match self { - OnPanic::None => false, - OnPanic::Restart => true, - OnPanic::Requests(_) => false, + OnExit::None => false, + OnExit::Restart => true, + OnExit::Requests(_) => false, + } + } + + pub fn en_wit(&self) -> wit::OnExit { + match self { + OnExit::None => wit::OnExit::None, + OnExit::Restart => wit::OnExit::Restart, + OnExit::Requests(reqs) => wit::OnExit::Requests( + reqs.iter() + .map(|(address, request, payload)| { + ( + address.en_wit(), + en_wit_request(request.clone()), + en_wit_payload(payload.clone()), + ) + }) + .collect(), + ), + } + } + + pub fn de_wit(wit: wit::OnExit) -> Self { + match wit { + wit::OnExit::None => OnExit::None, + wit::OnExit::Restart => OnExit::Restart, + wit::OnExit::Requests(reqs) => OnExit::Requests( + reqs.into_iter() + .map(|(address, request, payload)| { + ( + Address::de_wit(address), + de_wit_request(request), + de_wit_payload(payload), + ) + }) + .collect(), + ), } } } @@ -585,23 +621,6 @@ pub fn en_wit_send_error_kind(kind: SendErrorKind) -> wit::SendErrorKind { } } -pub fn de_wit_on_panic(wit: wit::OnPanic) -> OnPanic { - match wit { - wit::OnPanic::None => OnPanic::None, - wit::OnPanic::Restart => OnPanic::Restart, - wit::OnPanic::Requests(reqs) => OnPanic::Requests( - reqs.into_iter() - .map(|(address, request, payload)| { - ( - Address::de_wit(address), - de_wit_request(request), - de_wit_payload(payload), - ) - }) - .collect(), - ), - } -} // // END SYNC WITH process_lib // @@ -716,7 +735,7 @@ pub struct IdentityTransaction { pub struct ProcessMetadata { pub our: Address, pub wasm_bytes_handle: u128, - pub on_panic: OnPanic, + pub on_exit: OnExit, pub public: bool, } @@ -792,7 +811,7 @@ pub enum KernelCommand { InitializeProcess { id: ProcessId, wasm_bytes_handle: u128, - on_panic: OnPanic, + on_exit: OnExit, initial_capabilities: HashSet, public: bool, }, @@ -849,7 +868,7 @@ pub struct PersistedProcess { pub wasm_bytes_handle: u128, // pub drive: String, // pub full_path: String, - pub on_panic: OnPanic, + pub on_exit: OnExit, pub capabilities: HashSet, pub public: bool, // marks if a process allows messages from any process } @@ -879,7 +898,7 @@ pub struct PackageMetadata { pub struct PackageManifestEntry { pub process_name: String, pub process_wasm_path: String, - pub on_panic: OnPanic, + pub on_exit: OnExit, pub request_networking: bool, pub request_messaging: Option>, pub grant_messaging: Option>, diff --git a/wit/uqbar.wit b/wit/uqbar.wit index 1ed0a1f1..e0ecb3fc 100644 --- a/wit/uqbar.wit +++ b/wit/uqbar.wit @@ -1,4 +1,4 @@ -package uqbar:process@0.4.0; +package uqbar:process@0.5.0; interface standard { // JSON is passed over WASM boundary as a string. @@ -18,7 +18,6 @@ interface standard { publisher-node: node-id, } - // TODO better name for this record address { node: node-id, process: process-id, @@ -69,9 +68,9 @@ interface standard { signature: list, } - // on-panic is a setting that determines what happens when a process panics. + // on-exit is a setting that determines what happens when a process panics, completes, or otherwise "ends" // NOTE: requests should have expects-response set to false, will always be set to that by kernel - variant on-panic { + variant on-exit { none, restart, requests(list>>), @@ -109,7 +108,9 @@ interface standard { // process management: - set-on-panic: func(on-panic: on-panic); + set-on-exit: func(on-exit: on-exit); + + get-on-exit: func() -> on-exit; get-state: func() -> option>; @@ -120,7 +121,7 @@ interface standard { spawn: func( name: option, wasm-path: string, // must be located within package's drive - on-panic: on-panic, + on-exit: on-exit, capabilities: capabilities, public: bool ) -> result;