mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-11-25 07:07:06 +03:00
update to wit 0.5.0
This commit is contained in:
parent
08dc7dfa69
commit
2ca7c60c7b
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
target/
|
||||
wit/
|
||||
uqbar
|
||||
.vscode
|
||||
.app-signing
|
||||
|
26
Cargo.lock
generated
26
Cargo.lock
generated
@ -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"
|
||||
|
@ -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"
|
||||
|
11
build.rs
11
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",
|
||||
|
2
modules/app_store/app_store/Cargo.lock
generated
2
modules/app_store/app_store/Cargo.lock
generated
@ -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",
|
||||
|
@ -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]
|
||||
|
@ -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,
|
||||
})?)
|
||||
|
2
modules/app_store/ft_worker/Cargo.lock
generated
2
modules/app_store/ft_worker/Cargo.lock
generated
@ -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",
|
||||
|
@ -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]
|
||||
|
@ -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 {
|
||||
|
@ -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(
|
||||
|
@ -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",
|
||||
|
2
modules/chess/Cargo.lock
generated
2
modules/chess/Cargo.lock
generated
@ -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",
|
||||
|
@ -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]
|
||||
|
@ -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"
|
||||
|
2
modules/homepage/Cargo.lock
generated
2
modules/homepage/Cargo.lock
generated
@ -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",
|
||||
|
@ -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]
|
||||
|
@ -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",
|
||||
|
2
modules/key_value/key_value/Cargo.lock
generated
2
modules/key_value/key_value/Cargo.lock
generated
@ -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",
|
||||
|
@ -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]
|
||||
|
@ -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
|
||||
) {
|
||||
|
2
modules/key_value/key_value_worker/Cargo.lock
generated
2
modules/key_value/key_value_worker/Cargo.lock
generated
@ -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",
|
||||
|
@ -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]
|
||||
|
@ -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"
|
||||
|
2
modules/qns_indexer/Cargo.lock
generated
2
modules/qns_indexer/Cargo.lock
generated
@ -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",
|
||||
|
@ -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]
|
||||
|
@ -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",
|
||||
|
@ -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"
|
||||
|
2
modules/sqlite/sqlite/Cargo.lock
generated
2
modules/sqlite/sqlite/Cargo.lock
generated
@ -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",
|
||||
|
@ -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]
|
||||
|
@ -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<String>,
|
||||
@ -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<String> = [
|
||||
"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<String> = [
|
||||
"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::<sq::SqliteError>() {
|
||||
Response::new()
|
||||
.ipc(serde_json::to_vec(&e).unwrap())
|
||||
.send()
|
||||
.unwrap();
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
2
modules/terminal/Cargo.lock
generated
2
modules/terminal/Cargo.lock
generated
@ -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",
|
||||
|
@ -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]
|
||||
|
@ -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",
|
||||
|
@ -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"
|
||||
|
2
modules/tester/test_runner/Cargo.lock
generated
2
modules/tester/test_runner/Cargo.lock
generated
@ -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",
|
||||
|
@ -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]
|
||||
|
@ -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");
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
2
modules/tester/tester/Cargo.lock
generated
2
modules/tester/tester/Cargo.lock
generated
@ -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",
|
||||
|
@ -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]
|
||||
|
@ -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");
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
},
|
||||
|
@ -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 {
|
||||
|
@ -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();
|
||||
|
@ -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<wit::OnExit> {
|
||||
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<Option<Vec<u8>>> {
|
||||
@ -171,7 +175,7 @@ impl StandardHost for process::ProcessWasi {
|
||||
&mut self,
|
||||
name: Option<String>,
|
||||
wasm_path: String, // must be located within package's drive
|
||||
on_panic: wit::OnPanic,
|
||||
on_exit: wit::OnExit,
|
||||
capabilities: wit::Capabilities,
|
||||
public: bool,
|
||||
) -> Result<Result<wit::ProcessId, wit::SpawnError>> {
|
||||
@ -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 => {
|
||||
|
71
src/types.rs
71
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<Payload>)>),
|
||||
}
|
||||
|
||||
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<SignedCapability>,
|
||||
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<Capability>,
|
||||
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<Vec<String>>,
|
||||
pub grant_messaging: Option<Vec<String>>,
|
||||
|
@ -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<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
|
||||
variant on-panic {
|
||||
variant on-exit {
|
||||
none,
|
||||
restart,
|
||||
requests(list<tuple<address, request, option<payload>>>),
|
||||
@ -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<list<u8>>;
|
||||
|
||||
@ -120,7 +121,7 @@ interface standard {
|
||||
spawn: func(
|
||||
name: option<string>,
|
||||
wasm-path: string, // must be located within package's drive
|
||||
on-panic: on-panic,
|
||||
on-exit: on-exit,
|
||||
capabilities: capabilities,
|
||||
public: bool
|
||||
) -> result<process-id, spawn-error>;
|
||||
|
Loading…
Reference in New Issue
Block a user