update to wit 0.5.0

This commit is contained in:
dr-frmr 2023-12-15 16:21:06 -05:00
parent 08dc7dfa69
commit 2ca7c60c7b
No known key found for this signature in database
47 changed files with 274 additions and 195 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
target/ target/
wit/
uqbar uqbar
.vscode .vscode
.app-signing .app-signing

26
Cargo.lock generated
View File

@ -3727,9 +3727,9 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
[[package]] [[package]]
name = "reqwest" name = "reqwest"
version = "0.11.20" version = "0.11.22"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e9ad3fe7488d7e34558a2033d45a0c90b72d97b4f80705666fea71472e2e6a1" checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b"
dependencies = [ dependencies = [
"base64 0.21.4", "base64 0.21.4",
"bytes", "bytes",
@ -3755,6 +3755,7 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"serde_urlencoded", "serde_urlencoded",
"system-configuration",
"tokio", "tokio",
"tokio-native-tls", "tokio-native-tls",
"tokio-rustls", "tokio-rustls",
@ -4603,6 +4604,27 @@ dependencies = [
"unicode-ident", "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]] [[package]]
name = "system-interface" name = "system-interface"
version = "0.26.0" version = "0.26.0"

View File

@ -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 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build-dependencies] [build-dependencies]
reqwest = { version = "0.11.22", features = ["blocking"] }
sha2 = "0.10" sha2 = "0.10"
walkdir = "2.4" walkdir = "2.4"
zip = "0.6" zip = "0.6"

View File

@ -135,6 +135,17 @@ fn main() {
let pwd = std::env::current_dir().unwrap(); 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 // Create target.wasm (compiled .wit) & world
run_command(Command::new("wasm-tools").args([ run_command(Command::new("wasm-tools").args([
"component", "component",

View File

@ -423,7 +423,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]] [[package]]
name = "uqbar_process_lib" name = "uqbar_process_lib"
version = "0.4.0" 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 = [ dependencies = [
"anyhow", "anyhow",
"bincode", "bincode",

View File

@ -17,7 +17,7 @@ rand = "0.8"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
sha2 = "0.10.8" 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" } wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" }
[lib] [lib]

View File

@ -508,7 +508,7 @@ fn handle_local_request(
.ipc(serde_json::to_vec(&kt::KernelCommand::InitializeProcess { .ipc(serde_json::to_vec(&kt::KernelCommand::InitializeProcess {
id: parsed_new_process_id, id: parsed_new_process_id,
wasm_bytes_handle: hash, wasm_bytes_handle: hash,
on_panic: entry.on_panic.clone(), on_exit: entry.on_exit.clone(),
initial_capabilities, initial_capabilities,
public: entry.public, public: entry.public,
})?) })?)

View File

@ -357,7 +357,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]] [[package]]
name = "uqbar_process_lib" name = "uqbar_process_lib"
version = "0.4.0" 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 = [ dependencies = [
"anyhow", "anyhow",
"bincode", "bincode",

View File

@ -16,7 +16,7 @@ bincode = "1.3.3"
rand = "0.8" rand = "0.8"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" 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" } wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" }
[lib] [lib]

View File

@ -55,7 +55,7 @@ pub fn spawn_transfer(
let Ok(worker_process_id) = spawn( let Ok(worker_process_id) = spawn(
Some(&transfer_id.to_string()), Some(&transfer_id.to_string()),
"/ft_worker.wasm".into(), "/ft_worker.wasm".into(),
&OnPanic::None, // can set message-on-panic here &OnExit::None, // can set message-on-panic here
&Capabilities::All, &Capabilities::All,
false, // not public false, // not public
) else { ) else {
@ -106,7 +106,7 @@ pub fn spawn_receive_transfer(our: &Address, ipc: &[u8]) {
let Ok(worker_process_id) = spawn( let Ok(worker_process_id) = spawn(
Some(&transfer_id.to_string()), Some(&transfer_id.to_string()),
"/ft_worker.wasm".into(), "/ft_worker.wasm".into(),
&OnPanic::None, // can set message-on-panic here &OnExit::None, // can set message-on-panic here
&Capabilities::All, &Capabilities::All,
false, // not public false, // not public
) else { ) else {

View File

@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
//use uqbar_process_lib::uqbar::process::standard::*; //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::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; mod ft_worker_lib;
use ft_worker_lib::*; use ft_worker_lib::*;
@ -129,7 +129,7 @@ impl Guest for Component {
offset += chunk_size; offset += chunk_size;
} }
// now wait for Finished response // 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)); respond_to_parent(FTWorkerResult::Err(TransferError::TargetRejected));
return; return;
}; };
@ -144,11 +144,10 @@ impl Guest for Component {
} }
} }
FTWorkerCommand::Receive { FTWorkerCommand::Receive {
transfer_id,
file_name, file_name,
file_size,
total_chunks, total_chunks,
timeout, timeout,
..
} => { } => {
// send Ready response to counterparty // send Ready response to counterparty
send_response( send_response(

View File

@ -2,7 +2,7 @@
{ {
"process_name": "main", "process_name": "main",
"process_wasm_path": "/app_store.wasm", "process_wasm_path": "/app_store.wasm",
"on_panic": "Restart", "on_exit": "Restart",
"request_networking": true, "request_networking": true,
"request_messaging": [ "request_messaging": [
"terminal:terminal:uqbar", "terminal:terminal:uqbar",

View File

@ -632,7 +632,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]] [[package]]
name = "uqbar_process_lib" name = "uqbar_process_lib"
version = "0.4.0" 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 = [ dependencies = [
"anyhow", "anyhow",
"bincode", "bincode",

View File

@ -16,7 +16,7 @@ pleco = "0.5"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
url = "*" 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" } wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" }
[lib] [lib]

View File

@ -2,7 +2,7 @@
{ {
"process_name": "chess", "process_name": "chess",
"process_wasm_path": "/chess.wasm", "process_wasm_path": "/chess.wasm",
"on_panic": "Restart", "on_exit": "Restart",
"request_networking": true, "request_networking": true,
"request_messaging": [ "request_messaging": [
"net:sys:uqbar" "net:sys:uqbar"

View File

@ -356,7 +356,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]] [[package]]
name = "uqbar_process_lib" name = "uqbar_process_lib"
version = "0.4.0" 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 = [ dependencies = [
"anyhow", "anyhow",
"bincode", "bincode",

View File

@ -15,7 +15,7 @@ anyhow = "1.0"
bincode = "1.3.3" bincode = "1.3.3"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" 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" } wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" }
[lib] [lib]

View File

@ -2,7 +2,7 @@
{ {
"process_name": "homepage", "process_name": "homepage",
"process_wasm_path": "/homepage.wasm", "process_wasm_path": "/homepage.wasm",
"on_panic": "Restart", "on_exit": "Restart",
"request_networking": false, "request_networking": false,
"request_messaging": [ "request_messaging": [
"http_bindings:http_bindings:uqbar", "http_bindings:http_bindings:uqbar",

View File

@ -357,7 +357,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]] [[package]]
name = "uqbar_process_lib" name = "uqbar_process_lib"
version = "0.4.0" 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 = [ dependencies = [
"anyhow", "anyhow",
"bincode", "bincode",

View File

@ -16,7 +16,7 @@ bincode = "1.3.3"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
thiserror = "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" } wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" }
[lib] [lib]

View File

@ -2,7 +2,7 @@ use std::collections::HashMap;
// use serde::{Deserialize, Serialize}; // 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::kernel_types as kt;
use uqbar_process_lib::uqbar::process::standard as wit; 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, &source,
&"\"messaging\"".into(), &"\"messaging\"".into(),
).ok_or(anyhow::anyhow!("New failed: no source 'messaging' capability found"))?; ).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, None,
"/key_value_worker.wasm", "/key_value_worker.wasm",
&wit::OnPanic::None, // TODO: notify us OnExit::None, // TODO: notify us
&wit::Capabilities::Some(vec![vfs_read, vfs_write, messaging]), &wit::Capabilities::Some(vec![vfs_read, vfs_write, messaging]),
false, // not public false, // not public
) { ) {

View File

@ -497,7 +497,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]] [[package]]
name = "uqbar_process_lib" name = "uqbar_process_lib"
version = "0.4.0" 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 = [ dependencies = [
"anyhow", "anyhow",
"bincode", "bincode",

View File

@ -17,7 +17,7 @@ redb = { git = "https://github.com/uqbar-dao/redb", rev = "8e192d9" }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
thiserror = "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" } wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" }
[lib] [lib]

View File

@ -2,7 +2,7 @@
{ {
"process_name": "key_value", "process_name": "key_value",
"process_wasm_path": "/key_value.wasm", "process_wasm_path": "/key_value.wasm",
"on_panic": "Restart", "on_exit": "Restart",
"request_networking": false, "request_networking": false,
"request_messaging": [ "request_messaging": [
"vfs:sys:uqbar" "vfs:sys:uqbar"

View File

@ -757,7 +757,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]] [[package]]
name = "uqbar_process_lib" name = "uqbar_process_lib"
version = "0.4.0" 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 = [ dependencies = [
"anyhow", "anyhow",
"bincode", "bincode",

View File

@ -19,7 +19,7 @@ hex = "0.4.3"
rmp-serde = "1.1.2" rmp-serde = "1.1.2"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" 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" } wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" }
[lib] [lib]

View File

@ -2,7 +2,7 @@
{ {
"process_name": "qns_indexer", "process_name": "qns_indexer",
"process_wasm_path": "/qns_indexer.wasm", "process_wasm_path": "/qns_indexer.wasm",
"on_panic": "Restart", "on_exit": "Restart",
"request_networking": true, "request_networking": true,
"request_messaging": [ "request_messaging": [
"net:sys:uqbar", "net:sys:uqbar",

View File

@ -2,7 +2,7 @@
{ {
"process_name": "sqlite", "process_name": "sqlite",
"process_wasm_path": "/sqlite.wasm", "process_wasm_path": "/sqlite.wasm",
"on_panic": "Restart", "on_exit": "Restart",
"request_networking": false, "request_networking": false,
"request_messaging": [ "request_messaging": [
"vfs:sys:uqbar" "vfs:sys:uqbar"

View File

@ -357,7 +357,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]] [[package]]
name = "uqbar_process_lib" name = "uqbar_process_lib"
version = "0.4.0" 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 = [ dependencies = [
"anyhow", "anyhow",
"bincode", "bincode",

View File

@ -16,7 +16,7 @@ bincode = "1.3.3"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
thiserror = "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" } wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" }
[lib] [lib]

View File

@ -1,8 +1,8 @@
use std::collections::{HashMap, HashSet}; 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::kernel_types as kt;
use uqbar_process_lib::uqbar::process::standard as wit; use uqbar_process_lib::uqbar::process::standard as wit;
use uqbar_process_lib::{spawn, Address, OnExit, ProcessId, Request, Response};
wit_bindgen::generate!({ wit_bindgen::generate!({
path: "../../../wit", path: "../../../wit",
@ -23,14 +23,16 @@ fn make_vfs_cap(kind: &str, drive: &str) -> String {
serde_json::to_string(&serde_json::json!({ serde_json::to_string(&serde_json::json!({
"kind": kind, "kind": kind,
"drive": drive, "drive": drive,
})).unwrap() }))
.unwrap()
} }
fn make_db_cap(kind: &str, db: &str) -> String { fn make_db_cap(kind: &str, db: &str) -> String {
serde_json::to_string(&serde_json::json!({ serde_json::to_string(&serde_json::json!({
"kind": kind, "kind": kind,
"db": db, "db": db,
})).unwrap() }))
.unwrap()
} }
fn forward_if_have_cap( fn forward_if_have_cap(
@ -62,7 +64,7 @@ fn forward_if_have_cap(
} }
} }
fn handle_message ( fn handle_message(
our: &Address, our: &Address,
db_to_process: &mut DbToProcess, db_to_process: &mut DbToProcess,
read_keywords: &HashSet<String>, read_keywords: &HashSet<String>,
@ -77,7 +79,7 @@ fn handle_message (
match message { match message {
wit::Message::Response(_) => { wit::Message::Response(_) => {
return Err(sq::SqliteError::UnexpectedResponse.into()); return Err(sq::SqliteError::UnexpectedResponse.into());
}, }
wit::Message::Request(wit::Request { ipc, .. }) => { wit::Message::Request(wit::Request { ipc, .. }) => {
match serde_json::from_slice(&ipc)? { match serde_json::from_slice(&ipc)? {
sq::SqliteMessage::New { ref db } => { sq::SqliteMessage::New { ref db } => {
@ -103,28 +105,29 @@ fn handle_message (
drive: vfs_drive.clone(), drive: vfs_drive.clone(),
action: kt::VfsAction::New, action: kt::VfsAction::New,
})?) })?)
.send_and_await_response(15)?.unwrap(); .send_and_await_response(15)?
.unwrap();
// (2) // (2)
let vfs_read = wit::get_capability( let vfs_read =
&vfs_address, wit::get_capability(&vfs_address, &make_vfs_cap("read", &vfs_drive))
&make_vfs_cap("read", &vfs_drive), .ok_or(anyhow::anyhow!(
).ok_or(anyhow::anyhow!("New failed: no vfs 'read' capability found"))?; "New failed: no vfs 'read' capability found"
))?;
let vfs_write = wit::get_capability( let vfs_write =
&vfs_address, wit::get_capability(&vfs_address, &make_vfs_cap("write", &vfs_drive))
&make_vfs_cap("write", &vfs_drive), .ok_or(anyhow::anyhow!(
).ok_or(anyhow::anyhow!("New failed: no vfs 'write' capability found"))?; "New failed: no vfs 'write' capability found"
))?;
let msg_cap = wit::get_capability( let msg_cap = wit::get_capability(&source, &"\"messaging\"".into())
&source, .ok_or(anyhow::anyhow!("New failed: no msg capability passed"))?;
&"\"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, None,
"/sqlite_worker.wasm", "/sqlite_worker.wasm",
&wit::OnPanic::None, OnExit::None,
&wit::Capabilities::Some(vec![vfs_read, vfs_write, msg_cap]), &wit::Capabilities::Some(vec![vfs_read, vfs_write, msg_cap]),
false, // not public false, // not public
) { ) {
@ -132,7 +135,7 @@ fn handle_message (
Err(e) => { Err(e) => {
wit::print_to_terminal(0, &format!("couldn't spawn: {}", e)); wit::print_to_terminal(0, &format!("couldn't spawn: {}", e));
panic!("couldn't spawn"); // TODO panic!("couldn't spawn"); // TODO
}, }
}; };
// grant caps // grant caps
wit::create_capability(&source.process, &make_db_cap("read", db)); 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); db_to_process.insert(db.into(), spawned_process_id);
Response::new() Response::new().ipc(ipc).send()?;
.ipc(ipc) }
.send()?; sq::SqliteMessage::Write {
}, ref db,
sq::SqliteMessage::Write { ref db, ref statement, .. } => { ref statement,
..
} => {
let first_word = statement let first_word = statement
.split_whitespace() .split_whitespace()
.next() .next()
.map(|word| word.to_uppercase()) .map(|word| word.to_uppercase())
.unwrap_or("".to_string()); .unwrap_or("".to_string());
if !write_keywords.contains(&first_word) { 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)?; forward_if_have_cap(our, "write", db, ipc, db_to_process)?;
}, }
sq::SqliteMessage::Read { ref db, ref query } => { sq::SqliteMessage::Read { ref db, ref query } => {
let first_word = query let first_word = query
.split_whitespace() .split_whitespace()
@ -170,17 +175,17 @@ fn handle_message (
.map(|word| word.to_uppercase()) .map(|word| word.to_uppercase())
.unwrap_or("".to_string()); .unwrap_or("".to_string());
if !read_keywords.contains(&first_word) { 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)?; forward_if_have_cap(our, "read", db, ipc, db_to_process)?;
}, }
sq::SqliteMessage::Commit { ref db, .. } => { sq::SqliteMessage::Commit { ref db, .. } => {
forward_if_have_cap(our, "write", db, ipc, db_to_process)?; forward_if_have_cap(our, "write", db, ipc, db_to_process)?;
}, }
} }
Ok(()) Ok(())
}, }
} }
} }
@ -194,14 +199,7 @@ impl Guest for Component {
let mut db_to_process: DbToProcess = HashMap::new(); let mut db_to_process: DbToProcess = HashMap::new();
let read_keywords: HashSet<String> = [ let read_keywords: HashSet<String> = [
"ANALYZE", "ANALYZE", "ATTACH", "BEGIN", "EXPLAIN", "PRAGMA", "SELECT", "VALUES", "WITH",
"ATTACH",
"BEGIN",
"EXPLAIN",
"PRAGMA",
"SELECT",
"VALUES",
"WITH",
] ]
.iter() .iter()
.map(|x| x.to_string()) .map(|x| x.to_string())
@ -231,19 +229,16 @@ impl Guest for Component {
loop { loop {
match handle_message(&our, &mut db_to_process, &read_keywords, &write_keywords) { match handle_message(&our, &mut db_to_process, &read_keywords, &write_keywords) {
Ok(()) => {}, Ok(()) => {}
Err(e) => { Err(e) => {
wit::print_to_terminal(0, format!( wit::print_to_terminal(0, format!("sqlite: error: {:?}", e,).as_str());
"sqlite: error: {:?}",
e,
).as_str());
if let Some(e) = e.downcast_ref::<sq::SqliteError>() { if let Some(e) = e.downcast_ref::<sq::SqliteError>() {
Response::new() Response::new()
.ipc(serde_json::to_vec(&e).unwrap()) .ipc(serde_json::to_vec(&e).unwrap())
.send() .send()
.unwrap(); .unwrap();
} }
}, }
}; };
} }
} }

View File

@ -356,7 +356,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]] [[package]]
name = "uqbar_process_lib" name = "uqbar_process_lib"
version = "0.4.0" 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 = [ dependencies = [
"anyhow", "anyhow",
"bincode", "bincode",

View File

@ -15,7 +15,7 @@ anyhow = "1.0"
bincode = "1.3.3" bincode = "1.3.3"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" 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" } wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" }
[lib] [lib]

View File

@ -2,7 +2,7 @@
{ {
"process_name": "terminal", "process_name": "terminal",
"process_wasm_path": "/terminal.wasm", "process_wasm_path": "/terminal.wasm",
"on_panic": "Restart", "on_exit": "Restart",
"request_networking": true, "request_networking": true,
"request_messaging": [ "request_messaging": [
"net:sys:uqbar", "net:sys:uqbar",

View File

@ -2,7 +2,7 @@
{ {
"process_name": "tester", "process_name": "tester",
"process_wasm_path": "/tester.wasm", "process_wasm_path": "/tester.wasm",
"on_panic": "Restart", "on_exit": "Restart",
"request_networking": true, "request_networking": true,
"request_messaging": [ "request_messaging": [
"net:sys:uqbar" "net:sys:uqbar"

View File

@ -357,7 +357,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]] [[package]]
name = "uqbar_process_lib" name = "uqbar_process_lib"
version = "0.4.0" 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 = [ dependencies = [
"anyhow", "anyhow",
"bincode", "bincode",

View File

@ -16,7 +16,7 @@ bincode = "1.3.3"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
thiserror = "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" } wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" }
[lib] [lib]

View File

@ -1,9 +1,9 @@
use serde::{Serialize, Deserialize}; use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet}; 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::kernel_types as kt;
use uqbar_process_lib::uqbar::process::standard as wit; use uqbar_process_lib::uqbar::process::standard as wit;
use uqbar_process_lib::{spawn, Address, Message, OnExit, ProcessId, Request, Response};
mod tester_types; mod tester_types;
use tester_types as tt; use tester_types as tt;
@ -33,7 +33,7 @@ fn handle_message(our: &Address) -> anyhow::Result<()> {
match message { match message {
wit::Message::Response(_) => { wit::Message::Response(_) => {
return Err(tt::TesterError::UnexpectedResponse.into()); return Err(tt::TesterError::UnexpectedResponse.into());
}, }
wit::Message::Request(wit::Request { ref ipc, .. }) => { wit::Message::Request(wit::Request { ref ipc, .. }) => {
match serde_json::from_slice(ipc)? { match serde_json::from_slice(ipc)? {
tt::TesterRequest::Run { test_timeout, .. } => { tt::TesterRequest::Run { test_timeout, .. } => {
@ -45,11 +45,17 @@ fn handle_message(our: &Address) -> anyhow::Result<()> {
drive: "tester:uqbar".into(), drive: "tester:uqbar".into(),
action: kt::VfsAction::GetEntry("/".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, .. } = 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(); let mut children: HashSet<_> = children.into_iter().collect();
children.remove("/manifest.json"); children.remove("/manifest.json");
children.remove("/metadata.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)); wit::print_to_terminal(0, &format!("test_runner: running {:?}...", children));
for child in &children { for child in &children {
let child_process_id = match wit::spawn( let child_process_id = match spawn(
None, None,
child, child,
&wit::OnPanic::None, // TODO: notify us OnExit::None, // TODO: notify us
&wit::Capabilities::All, &wit::Capabilities::All,
false, // not public false, // not public
) { ) {
Ok(child_process_id) => child_process_id, Ok(child_process_id) => child_process_id,
Err(e) => { 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 panic!("couldn't spawn"); // TODO
} }
}; };
@ -79,15 +88,23 @@ fn handle_message(our: &Address) -> anyhow::Result<()> {
process: child_process_id, process: child_process_id,
}) })
.ipc(ipc.clone()) .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)? { match serde_json::from_slice(&ipc)? {
tt::TesterResponse::Pass => {}, tt::TesterResponse::Pass => {}
tt::TesterResponse::GetFullMessage(_) => {}, tt::TesterResponse::GetFullMessage(_) => {}
tt::TesterResponse::Fail { test, file, line, column } => { tt::TesterResponse::Fail {
test,
file,
line,
column,
} => {
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()) .ipc(serde_json::to_vec(&tt::TesterResponse::Pass).unwrap())
.send() .send()
.unwrap(); .unwrap();
}, }
tt::TesterRequest::KernelMessage(_) | tt::TesterRequest::GetFullMessage(_) => { unimplemented!() }, tt::TesterRequest::KernelMessage(_) | tt::TesterRequest::GetFullMessage(_) => {
unimplemented!()
}
} }
Ok(()) Ok(())
}, }
} }
} }
@ -119,14 +138,11 @@ impl Guest for Component {
loop { loop {
match handle_message(&our) { match handle_message(&our) {
Ok(()) => {}, Ok(()) => {}
Err(e) => { Err(e) => {
wit::print_to_terminal(0, format!( wit::print_to_terminal(0, format!("test_runner: error: {:?}", e,).as_str());
"test_runner: error: {:?}",
e,
).as_str());
fail!("test_runner"); fail!("test_runner");
}, }
}; };
} }
} }

View File

@ -358,7 +358,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]] [[package]]
name = "uqbar_process_lib" name = "uqbar_process_lib"
version = "0.4.0" 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 = [ dependencies = [
"anyhow", "anyhow",
"bincode", "bincode",

View File

@ -17,7 +17,7 @@ indexmap = "2.1"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
thiserror = "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" } wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" }
[lib] [lib]

View File

@ -1,8 +1,8 @@
use indexmap::map::IndexMap; use indexmap::map::IndexMap;
use uqbar_process_lib::{Address, ProcessId, Request, Response};
use uqbar_process_lib::kernel_types as kt; use uqbar_process_lib::kernel_types as kt;
use uqbar_process_lib::uqbar::process::standard as wit; use uqbar_process_lib::uqbar::process::standard as wit;
use uqbar_process_lib::{spawn, Address, OnExit, ProcessId, Request, Response};
mod tester_types; mod tester_types;
use tester_types as tt; use tester_types as tt;
@ -36,21 +36,24 @@ fn handle_message(
match serde_json::from_slice(&ipc)? { match serde_json::from_slice(&ipc)? {
tt::TesterResponse::Pass | tt::TesterResponse::Fail { .. } => { tt::TesterResponse::Pass | tt::TesterResponse::Fail { .. } => {
if (source.process.package_name != "tester") if (source.process.package_name != "tester")
| (source.process.publisher_node != "uqbar") { | (source.process.publisher_node != "uqbar")
{
return Err(tt::TesterError::UnexpectedResponse.into()); return Err(tt::TesterError::UnexpectedResponse.into());
} }
Response::new() Response::new().ipc(ipc).send().unwrap();
.ipc(ipc) }
.send() tt::TesterResponse::GetFullMessage(_) => {
.unwrap(); unimplemented!()
}, }
tt::TesterResponse::GetFullMessage(_) => { unimplemented!() }
} }
Ok(()) Ok(())
}, }
wit::Message::Request(wit::Request { ipc, .. }) => { wit::Message::Request(wit::Request { ipc, .. }) => {
match serde_json::from_slice(&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"); wit::print_to_terminal(0, "tester: got Run");
assert!(input_node_names.len() >= 1); assert!(input_node_names.len() >= 1);
@ -64,16 +67,19 @@ fn handle_message(
} else { } else {
// we are master node // we are master node
let child = "/test_runner.wasm"; let child = "/test_runner.wasm";
let child_process_id = match wit::spawn( let child_process_id = match spawn(
None, None,
child, child,
&wit::OnPanic::None, // TODO: notify us OnExit::None, // TODO: notify us
&wit::Capabilities::All, &wit::Capabilities::All,
false, // not public false, // not public
) { ) {
Ok(child_process_id) => child_process_id, Ok(child_process_id) => child_process_id,
Err(e) => { 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 panic!("couldn't spawn"); // TODO
} }
}; };
@ -86,11 +92,13 @@ fn handle_message(
.expects_response(test_timeout) .expects_response(test_timeout)
.send()?; .send()?;
} }
}, }
tt::TesterRequest::KernelMessage(_) | tt::TesterRequest::GetFullMessage(_) => { unimplemented!() }, tt::TesterRequest::KernelMessage(_) | tt::TesterRequest::GetFullMessage(_) => {
unimplemented!()
}
} }
Ok(()) Ok(())
}, }
} }
} }
@ -110,20 +118,22 @@ impl Guest for Component {
&serde_json::to_string(&serde_json::json!({ &serde_json::to_string(&serde_json::json!({
"kind": "write", "kind": "write",
"drive": "tester:uqbar", "drive": "tester:uqbar",
})).unwrap() }))
).unwrap(); .unwrap(),
wit::share_capability(&ProcessId::from_str("http_server:sys:uqbar").unwrap(), &drive_cap); )
.unwrap();
wit::share_capability(
&ProcessId::from_str("http_server:sys:uqbar").unwrap(),
&drive_cap,
);
loop { loop {
match handle_message(&our, &mut messages, &mut node_names) { match handle_message(&our, &mut messages, &mut node_names) {
Ok(()) => {}, Ok(()) => {}
Err(e) => { Err(e) => {
wit::print_to_terminal(0, format!( wit::print_to_terminal(0, format!("tester: error: {:?}", e,).as_str());
"tester: error: {:?}",
e,
).as_str());
fail!("tester"); fail!("tester");
}, }
}; };
} }
} }

View File

@ -146,7 +146,7 @@ async fn bootstrap(
.entry(ProcessId::from_str("kernel:sys:uqbar").unwrap()) .entry(ProcessId::from_str("kernel:sys:uqbar").unwrap())
.or_insert(PersistedProcess { .or_insert(PersistedProcess {
wasm_bytes_handle: 0, wasm_bytes_handle: 0,
on_panic: OnPanic::Restart, on_exit: OnExit::Restart,
capabilities: runtime_caps.clone(), capabilities: runtime_caps.clone(),
public: false, public: false,
}); });
@ -154,7 +154,7 @@ async fn bootstrap(
.entry(ProcessId::from_str("net:sys:uqbar").unwrap()) .entry(ProcessId::from_str("net:sys:uqbar").unwrap())
.or_insert(PersistedProcess { .or_insert(PersistedProcess {
wasm_bytes_handle: 0, wasm_bytes_handle: 0,
on_panic: OnPanic::Restart, on_exit: OnExit::Restart,
capabilities: runtime_caps.clone(), capabilities: runtime_caps.clone(),
public: false, public: false,
}); });
@ -163,7 +163,7 @@ async fn bootstrap(
.entry(runtime_module.0) .entry(runtime_module.0)
.or_insert(PersistedProcess { .or_insert(PersistedProcess {
wasm_bytes_handle: 0, wasm_bytes_handle: 0,
on_panic: OnPanic::Restart, on_exit: OnExit::Restart,
capabilities: runtime_caps.clone(), capabilities: runtime_caps.clone(),
public: runtime_module.2, public: runtime_module.2,
}); });
@ -380,7 +380,7 @@ async fn bootstrap(
ProcessId::new(Some(&entry.process_name), package_name, package_publisher), ProcessId::new(Some(&entry.process_name), package_name, package_publisher),
PersistedProcess { PersistedProcess {
wasm_bytes_handle, wasm_bytes_handle,
on_panic: entry.on_panic, on_exit: entry.on_exit,
capabilities: requested_caps, capabilities: requested_caps,
public: public_process, public: public_process,
}, },

View File

@ -142,7 +142,7 @@ async fn handle_kernel_request(
t::KernelCommand::InitializeProcess { t::KernelCommand::InitializeProcess {
id, id,
wasm_bytes_handle, wasm_bytes_handle,
on_panic, on_exit,
initial_capabilities, initial_capabilities,
public, public,
} => { } => {
@ -248,7 +248,7 @@ async fn handle_kernel_request(
process_id: id, process_id: id,
persisted: t::PersistedProcess { persisted: t::PersistedProcess {
wasm_bytes_handle, wasm_bytes_handle,
on_panic, on_exit,
capabilities: valid_capabilities, capabilities: valid_capabilities,
public, public,
}, },
@ -572,7 +572,7 @@ async fn start_process(
process: id.clone(), process: id.clone(),
}, },
wasm_bytes_handle: process_metadata.persisted.wasm_bytes_handle, 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, public: process_metadata.persisted.public,
}; };
process_handles.insert( process_handles.insert(
@ -659,7 +659,7 @@ pub async fn kernel(
for (process_id, persisted) in &process_map { for (process_id, persisted) in &process_map {
// runtime extensions will have a bytes_handle of 0, because they have no // runtime extensions will have a bytes_handle of 0, because they have no
// WASM code saved in filesystem. // 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_to_loop
.send(t::KernelMessage { .send(t::KernelMessage {
id: rand::random(), id: rand::random(),
@ -696,7 +696,7 @@ pub async fn kernel(
.await .await
.expect("event loop: fatal: sender died"); .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 // 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 // even in death, a process can only message processes it has capabilities for
for (address, request, payload) in requests { for (address, request, payload) in requests {

View File

@ -534,11 +534,11 @@ pub async fn make_process_loop(
.await .await
.expect("event loop: fatal: sender died"); .expect("event loop: fatal: sender died");
// fulfill the designated OnPanic behavior // fulfill the designated OnExit behavior
match metadata.on_panic { match metadata.on_exit {
t::OnPanic::None => {} t::OnExit::None => {}
// if restart, tell ourselves to init the app again, with same capabilities // if restart, tell ourselves to init the app again, with same capabilities
t::OnPanic::Restart => { t::OnExit::Restart => {
send_to_loop send_to_loop
.send(t::KernelMessage { .send(t::KernelMessage {
id: rand::random(), id: rand::random(),
@ -551,7 +551,7 @@ pub async fn make_process_loop(
ipc: serde_json::to_vec(&t::KernelCommand::InitializeProcess { ipc: serde_json::to_vec(&t::KernelCommand::InitializeProcess {
id: metadata.our.process.clone(), id: metadata.our.process.clone(),
wasm_bytes_handle: metadata.wasm_bytes_handle, wasm_bytes_handle: metadata.wasm_bytes_handle,
on_panic: metadata.on_panic, on_exit: metadata.on_exit,
initial_capabilities, initial_capabilities,
public: metadata.public, public: metadata.public,
}) })
@ -569,7 +569,7 @@ pub async fn make_process_loop(
} }
// if requests, fire them // if requests, fire them
// even in death, a process can only message processes it has capabilities for // 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 { for (address, mut request, payload) in requests {
request.expects_response = None; request.expects_response = None;
let (tx, rx) = tokio::sync::oneshot::channel(); let (tx, rx) = tokio::sync::oneshot::channel();

View File

@ -40,11 +40,15 @@ impl StandardHost for process::ProcessWasi {
// //
/// TODO critical: move to kernel logic to enable persistence of choice made here /// 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<()> { async fn set_on_exit(&mut self, on_exit: wit::OnExit) -> Result<()> {
self.process.metadata.on_panic = t::de_wit_on_panic(on_panic); self.process.metadata.on_exit = t::OnExit::de_wit(on_exit);
Ok(()) Ok(())
} }
async fn get_on_exit(&mut self) -> Result<wit::OnExit> {
Ok(self.process.metadata.on_exit.en_wit())
}
/// create a message from the *kernel* to the filesystem, /// create a message from the *kernel* to the filesystem,
/// asking it to fetch the current state saved under this process /// asking it to fetch the current state saved under this process
async fn get_state(&mut self) -> Result<Option<Vec<u8>>> { async fn get_state(&mut self) -> Result<Option<Vec<u8>>> {
@ -171,7 +175,7 @@ impl StandardHost for process::ProcessWasi {
&mut self, &mut self,
name: Option<String>, name: Option<String>,
wasm_path: String, // must be located within package's drive wasm_path: String, // must be located within package's drive
on_panic: wit::OnPanic, on_exit: wit::OnExit,
capabilities: wit::Capabilities, capabilities: wit::Capabilities,
public: bool, public: bool,
) -> Result<Result<wit::ProcessId, wit::SpawnError>> { ) -> Result<Result<wit::ProcessId, wit::SpawnError>> {
@ -272,7 +276,7 @@ impl StandardHost for process::ProcessWasi {
ipc: serde_json::to_vec(&t::KernelCommand::InitializeProcess { ipc: serde_json::to_vec(&t::KernelCommand::InitializeProcess {
id: new_process_id.clone(), id: new_process_id.clone(),
wasm_bytes_handle: hash, 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 { initial_capabilities: match capabilities {
wit::Capabilities::None => HashSet::new(), wit::Capabilities::None => HashSet::new(),
wit::Capabilities::All => { wit::Capabilities::All => {

View File

@ -428,18 +428,54 @@ pub enum SendErrorKind {
} }
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub enum OnPanic { pub enum OnExit {
None, None,
Restart, Restart,
Requests(Vec<(Address, Request, Option<Payload>)>), Requests(Vec<(Address, Request, Option<Payload>)>),
} }
impl OnPanic { impl OnExit {
pub fn is_restart(&self) -> bool { pub fn is_restart(&self) -> bool {
match self { match self {
OnPanic::None => false, OnExit::None => false,
OnPanic::Restart => true, OnExit::Restart => true,
OnPanic::Requests(_) => false, 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 // END SYNC WITH process_lib
// //
@ -716,7 +735,7 @@ pub struct IdentityTransaction {
pub struct ProcessMetadata { pub struct ProcessMetadata {
pub our: Address, pub our: Address,
pub wasm_bytes_handle: u128, pub wasm_bytes_handle: u128,
pub on_panic: OnPanic, pub on_exit: OnExit,
pub public: bool, pub public: bool,
} }
@ -792,7 +811,7 @@ pub enum KernelCommand {
InitializeProcess { InitializeProcess {
id: ProcessId, id: ProcessId,
wasm_bytes_handle: u128, wasm_bytes_handle: u128,
on_panic: OnPanic, on_exit: OnExit,
initial_capabilities: HashSet<SignedCapability>, initial_capabilities: HashSet<SignedCapability>,
public: bool, public: bool,
}, },
@ -849,7 +868,7 @@ pub struct PersistedProcess {
pub wasm_bytes_handle: u128, pub wasm_bytes_handle: u128,
// pub drive: String, // pub drive: String,
// pub full_path: String, // pub full_path: String,
pub on_panic: OnPanic, pub on_exit: OnExit,
pub capabilities: HashSet<Capability>, pub capabilities: HashSet<Capability>,
pub public: bool, // marks if a process allows messages from any process pub public: bool, // marks if a process allows messages from any process
} }
@ -879,7 +898,7 @@ pub struct PackageMetadata {
pub struct PackageManifestEntry { pub struct PackageManifestEntry {
pub process_name: String, pub process_name: String,
pub process_wasm_path: String, pub process_wasm_path: String,
pub on_panic: OnPanic, pub on_exit: OnExit,
pub request_networking: bool, pub request_networking: bool,
pub request_messaging: Option<Vec<String>>, pub request_messaging: Option<Vec<String>>,
pub grant_messaging: Option<Vec<String>>, pub grant_messaging: Option<Vec<String>>,

View File

@ -1,4 +1,4 @@
package uqbar:process@0.4.0; package uqbar:process@0.5.0;
interface standard { interface standard {
// JSON is passed over WASM boundary as a string. // JSON is passed over WASM boundary as a string.
@ -18,7 +18,6 @@ interface standard {
publisher-node: node-id, publisher-node: node-id,
} }
// TODO better name for this
record address { record address {
node: node-id, node: node-id,
process: process-id, process: process-id,
@ -69,9 +68,9 @@ interface standard {
signature: list<u8>, signature: list<u8>,
} }
// 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 // NOTE: requests should have expects-response set to false, will always be set to that by kernel
variant on-panic { variant on-exit {
none, none,
restart, restart,
requests(list<tuple<address, request, option<payload>>>), requests(list<tuple<address, request, option<payload>>>),
@ -109,7 +108,9 @@ interface standard {
// process management: // 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<list<u8>>; get-state: func() -> option<list<u8>>;
@ -120,7 +121,7 @@ interface standard {
spawn: func( spawn: func(
name: option<string>, name: option<string>,
wasm-path: string, // must be located within package's drive wasm-path: string, // must be located within package's drive
on-panic: on-panic, on-exit: on-exit,
capabilities: capabilities, capabilities: capabilities,
public: bool public: bool
) -> result<process-id, spawn-error>; ) -> result<process-id, spawn-error>;