Merge branch 'main' into hf/start-from-commandline

This commit is contained in:
hosted-fornet 2023-11-08 13:50:30 -08:00
commit 90898177b5
29 changed files with 32 additions and 1462 deletions

1
Cargo.lock generated
View File

@ -5145,6 +5145,7 @@ dependencies = [
[[package]]
name = "uqbar_process_lib"
version = "0.2.0"
source = "git+https://github.com/uqbar-dao/process_lib?rev=e53c124#e53c124ec95ef99c06d201d4d08dada8ec691d29"
dependencies = [
"anyhow",
"bincode",

View File

@ -64,7 +64,7 @@ thiserror = "1.0.43"
tokio = { version = "1.28", features = ["fs", "macros", "rt-multi-thread", "sync"] }
tokio-tungstenite = "*"
url = "*"
uqbar_process_lib = { path = "process_lib" }
uqbar_process_lib = { git = "https://github.com/uqbar-dao/process_lib", rev = "e53c124" }
uuid = { version = "1.1.2", features = ["serde", "v4"] }
warp = "0.3.5"
wasmtime = "14.0.4"

View File

@ -325,6 +325,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]]
name = "uqbar_process_lib"
version = "0.2.0"
source = "git+https://github.com/uqbar-dao/process_lib?rev=e53c124#e53c124ec95ef99c06d201d4d08dada8ec691d29"
dependencies = [
"anyhow",
"bincode",

View File

@ -17,8 +17,8 @@ rand = "0.8"
serde = {version = "1.0", features = ["derive"] }
serde_json = "1.0"
sha2 = "0.10.8"
uqbar_process_lib = { git = "https://github.com/uqbar-dao/process_lib", rev = "e53c124" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "5390bab780733f1660d14c254ec985df2816bf1d" }
uqbar_process_lib = { path = "../../../process_lib" }
[lib]
crate-type = ["cdylib"]

View File

@ -326,6 +326,10 @@ fn handle_local_request(
process: ProcessId::from_str("vfs:sys:uqbar")?,
};
let Some(mut payload) = get_payload() else {
return Err(anyhow::anyhow!("no payload"));
};
Request::new()
.target(vfs_address.clone())?
.ipc_bytes(serde_json::to_vec(&kt::VfsRequest {
@ -334,9 +338,6 @@ fn handle_local_request(
})?)
.send_and_await_response(5)??;
let Some(mut payload) = get_payload() else {
return Err(anyhow::anyhow!("no payload"));
};
// produce the version hash for this new package
let mut hasher = sha2::Sha256::new();
hasher.update(&payload.bytes);

View File

@ -259,6 +259,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]]
name = "uqbar_process_lib"
version = "0.2.0"
source = "git+https://github.com/uqbar-dao/process_lib?rev=e53c124#e53c124ec95ef99c06d201d4d08dada8ec691d29"
dependencies = [
"anyhow",
"bincode",

View File

@ -16,8 +16,8 @@ bincode = "1.3.3"
rand = "0.8"
serde = {version = "1.0", features = ["derive"] }
serde_json = "1.0"
uqbar_process_lib = { git = "https://github.com/uqbar-dao/process_lib", rev = "e53c124" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "5390bab780733f1660d14c254ec985df2816bf1d" }
uqbar_process_lib = { path = "../../../process_lib" }
[lib]
crate-type = ["cdylib"]

View File

@ -533,6 +533,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]]
name = "uqbar_process_lib"
version = "0.2.0"
source = "git+https://github.com/uqbar-dao/process_lib?rev=e53c124#e53c124ec95ef99c06d201d4d08dada8ec691d29"
dependencies = [
"anyhow",
"bincode",

View File

@ -17,8 +17,8 @@ bincode = "1.3.3"
pleco = "0.5"
serde = {version = "1.0", features = ["derive"] }
serde_json = "1.0"
uqbar_process_lib = { git = "https://github.com/uqbar-dao/process_lib", rev = "e53c124" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "5390bab780733f1660d14c254ec985df2816bf1d" }
uqbar_process_lib = { path = "../../process_lib" }
[lib]
crate-type = ["cdylib"]

View File

@ -258,6 +258,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]]
name = "uqbar_process_lib"
version = "0.2.0"
source = "git+https://github.com/uqbar-dao/process_lib?rev=e53c124#e53c124ec95ef99c06d201d4d08dada8ec691d29"
dependencies = [
"anyhow",
"bincode",

View File

@ -15,8 +15,8 @@ anyhow = "1.0"
bincode = "1.3.3"
serde = {version = "1.0", features = ["derive"] }
serde_json = "1.0"
uqbar_process_lib = { git = "https://github.com/uqbar-dao/process_lib", rev = "e53c124" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "5390bab780733f1660d14c254ec985df2816bf1d" }
uqbar_process_lib = { path = "../../process_lib" }
[lib]
crate-type = ["cdylib"]

View File

@ -258,6 +258,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]]
name = "uqbar_process_lib"
version = "0.2.0"
source = "git+https://github.com/uqbar-dao/process_lib?rev=e53c124#e53c124ec95ef99c06d201d4d08dada8ec691d29"
dependencies = [
"anyhow",
"bincode",

View File

@ -15,8 +15,8 @@ anyhow = "1.0"
bincode = "1.3.3"
serde = {version = "1.0", features = ["derive"] }
serde_json = "1.0"
uqbar_process_lib = { git = "https://github.com/uqbar-dao/process_lib", rev = "e53c124" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "5390bab780733f1660d14c254ec985df2816bf1d" }
uqbar_process_lib = { path = "../../process_lib" }
[lib]
crate-type = ["cdylib"]

View File

@ -279,6 +279,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]]
name = "uqbar_process_lib"
version = "0.2.0"
source = "git+https://github.com/uqbar-dao/process_lib?rev=e53c124#e53c124ec95ef99c06d201d4d08dada8ec691d29"
dependencies = [
"anyhow",
"bincode",

View File

@ -16,14 +16,14 @@ bincode = "1.3.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "1.0"
uqbar_process_lib = { path = "../../../process_lib" }
uqbar_process_lib = { git = "https://github.com/uqbar-dao/process_lib", rev = "e53c124" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "5390bab780733f1660d14c254ec985df2816bf1d" }
[lib]
crate-type = ["cdylib"]
[package.metadata.component]
package = "component:uq-process"
package = "uqbar:process"
[package.metadata.component.target]
path = "wit"

View File

@ -419,6 +419,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]]
name = "uqbar_process_lib"
version = "0.2.0"
source = "git+https://github.com/uqbar-dao/process_lib?rev=e53c124#e53c124ec95ef99c06d201d4d08dada8ec691d29"
dependencies = [
"anyhow",
"bincode",

View File

@ -17,14 +17,14 @@ 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 = { path = "../../../process_lib" }
uqbar_process_lib = { git = "https://github.com/uqbar-dao/process_lib", rev = "e53c124" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "5390bab780733f1660d14c254ec985df2816bf1d" }
[lib]
crate-type = ["cdylib"]
[package.metadata.component]
package = "component:uq-process"
package = "uqbar:process"
[package.metadata.component.target]
path = "wit"

View File

@ -671,6 +671,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]]
name = "uqbar_process_lib"
version = "0.2.0"
source = "git+https://github.com/uqbar-dao/process_lib?rev=e53c124#e53c124ec95ef99c06d201d4d08dada8ec691d29"
dependencies = [
"anyhow",
"bincode",

View File

@ -19,8 +19,8 @@ hex = "0.4.3"
rmp-serde = "1.1.2"
serde = {version = "1.0", features = ["derive"] }
serde_json = "1.0"
uqbar_process_lib = { git = "https://github.com/uqbar-dao/process_lib", rev = "e53c124" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "5390bab780733f1660d14c254ec985df2816bf1d" }
uqbar_process_lib = { path = "../../process_lib" }
[lib]
crate-type = ["cdylib"]

View File

@ -329,6 +329,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]]
name = "uqbar_process_lib"
version = "0.2.0"
source = "git+https://github.com/uqbar-dao/process_lib?rev=e53c124#e53c124ec95ef99c06d201d4d08dada8ec691d29"
dependencies = [
"anyhow",
"bincode",

View File

@ -17,14 +17,14 @@ rmp-serde = "1.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "1.0"
uqbar_process_lib = { path = "../../../process_lib" }
uqbar_process_lib = { git = "https://github.com/uqbar-dao/process_lib", rev = "e53c124" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "5390bab780733f1660d14c254ec985df2816bf1d" }
[lib]
crate-type = ["cdylib"]
[package.metadata.component]
package = "component:uq-process"
package = "uqbar:process"
[package.metadata.component.target]
path = "wit"

View File

@ -416,6 +416,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]]
name = "uqbar_process_lib"
version = "0.2.0"
source = "git+https://github.com/uqbar-dao/process_lib?rev=e53c124#e53c124ec95ef99c06d201d4d08dada8ec691d29"
dependencies = [
"anyhow",
"bincode",

View File

@ -18,14 +18,14 @@ rusqlite = { git = "https://github.com/uqbar-dao/rusqlite", rev = "fa6ed84", fea
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "1.0"
uqbar_process_lib = { path = "../../../process_lib" }
uqbar_process_lib = { git = "https://github.com/uqbar-dao/process_lib", rev = "e53c124" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "5390bab780733f1660d14c254ec985df2816bf1d" }
[lib]
crate-type = ["cdylib"]
[package.metadata.component]
package = "component:uq-process"
package = "uqbar:process"
[package.metadata.component.target]
path = "wit"

View File

@ -258,6 +258,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]]
name = "uqbar_process_lib"
version = "0.2.0"
source = "git+https://github.com/uqbar-dao/process_lib?rev=e53c124#e53c124ec95ef99c06d201d4d08dada8ec691d29"
dependencies = [
"anyhow",
"bincode",

View File

@ -15,8 +15,8 @@ anyhow = "1.0"
bincode = "1.3.3"
serde = {version = "1.0", features = ["derive"] }
serde_json = "1.0"
uqbar_process_lib = { git = "https://github.com/uqbar-dao/process_lib", rev = "e53c124" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "5390bab780733f1660d14c254ec985df2816bf1d" }
uqbar_process_lib = { path = "../../process_lib" }
[lib]
crate-type = ["cdylib"]

312
process_lib/Cargo.lock generated
View File

@ -1,312 +0,0 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "anyhow"
version = "1.0.75"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
[[package]]
name = "bincode"
version = "1.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
dependencies = [
"serde",
]
[[package]]
name = "bitflags"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
[[package]]
name = "equivalent"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "hashbrown"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156"
[[package]]
name = "heck"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
dependencies = [
"unicode-segmentation",
]
[[package]]
name = "id-arena"
version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005"
[[package]]
name = "indexmap"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f"
dependencies = [
"equivalent",
"hashbrown",
"serde",
]
[[package]]
name = "itoa"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
[[package]]
name = "leb128"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67"
[[package]]
name = "log"
version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
[[package]]
name = "proc-macro2"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
dependencies = [
"proc-macro2",
]
[[package]]
name = "ryu"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
[[package]]
name = "semver"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090"
[[package]]
name = "serde"
version = "1.0.190"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91d3c334ca1ee894a2c6f6ad698fe8c435b76d504b13d436f0685d648d6d96f7"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.190"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67c5609f394e5c2bd7fc51efda478004ea80ef42fee983d5c67a65e34f32c0e3"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "smallvec"
version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a"
[[package]]
name = "spdx"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b19b32ed6d899ab23174302ff105c1577e45a06b08d4fe0a9dd13ce804bbbf71"
dependencies = [
"smallvec",
]
[[package]]
name = "syn"
version = "2.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "unicode-segmentation"
version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36"
[[package]]
name = "unicode-xid"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]]
name = "uqbar_process_lib"
version = "0.2.0"
dependencies = [
"anyhow",
"bincode",
"serde",
"serde_json",
"wit-bindgen",
]
[[package]]
name = "wasm-encoder"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53ae0be20bf87918df4fa831bfbbd0b491d24aee407ed86360eae4c2c5608d38"
dependencies = [
"leb128",
]
[[package]]
name = "wasm-metadata"
version = "0.10.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5621910462c61a8efc3248fdfb1739bf649bb335b0df935c27b340418105f9d8"
dependencies = [
"anyhow",
"indexmap",
"serde",
"serde_derive",
"serde_json",
"spdx",
"wasm-encoder",
"wasmparser",
]
[[package]]
name = "wasmparser"
version = "0.116.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53290b1276c5c2d47d694fb1a920538c01f51690e7e261acbe1d10c5fc306ea1"
dependencies = [
"indexmap",
"semver",
]
[[package]]
name = "wit-bindgen"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"bitflags",
"wit-bindgen-rust-macro",
]
[[package]]
name = "wit-bindgen-core"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"anyhow",
"wit-component",
"wit-parser",
]
[[package]]
name = "wit-bindgen-rust"
version = "0.13.2"
source = "git+https://github.com/bytecodealliance/wit-bindgen#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"anyhow",
"heck",
"wasm-metadata",
"wit-bindgen-core",
"wit-component",
]
[[package]]
name = "wit-bindgen-rust-macro"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"anyhow",
"proc-macro2",
"quote",
"syn",
"wit-bindgen-core",
"wit-bindgen-rust",
"wit-component",
]
[[package]]
name = "wit-component"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "480cc1a078b305c1b8510f7c455c76cbd008ee49935f3a6c5fd5e937d8d95b1e"
dependencies = [
"anyhow",
"bitflags",
"indexmap",
"log",
"serde",
"serde_derive",
"serde_json",
"wasm-encoder",
"wasm-metadata",
"wasmparser",
"wit-parser",
]
[[package]]
name = "wit-parser"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43771ee863a16ec4ecf9da0fc65c3bbd4a1235c8e3da5f094b562894843dfa76"
dependencies = [
"anyhow",
"id-arena",
"indexmap",
"log",
"semver",
"serde",
"serde_derive",
"serde_json",
"unicode-xid",
]

View File

@ -1,11 +0,0 @@
[package]
name = "uqbar_process_lib"
version = "0.2.0"
edition = "2021"
[dependencies]
anyhow = "1.0"
bincode = "1.3.3"
serde = {version = "1.0", features = ["derive"] }
rand = "0.8"
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "5390bab780733f1660d14c254ec985df2816bf1d" }

View File

@ -1,509 +0,0 @@
use crate::uqbar::process::standard as wit;
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
//
// process-facing kernel types, used for process
// management and message-passing
// matches types in uqbar.wit
//
pub type Context = Vec<u8>;
pub type NodeId = String; // QNS domain name
/// process ID is a formatted unique identifier that contains
/// the publishing node's ID, the package name, and finally the process name.
/// the process name can be a random number, or a name chosen by the user.
/// the formatting is as follows:
/// `[process name]:[package name]:[node ID]`
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct ProcessId {
process_name: String,
package_name: String,
publisher_node: NodeId,
}
#[allow(dead_code)]
impl ProcessId {
/// generates a random u64 number if process_name is not declared
pub fn new(process_name: Option<&str>, package_name: &str, publisher_node: &str) -> Self {
ProcessId {
process_name: process_name
.unwrap_or(&rand::random::<u64>().to_string())
.into(),
package_name: package_name.into(),
publisher_node: publisher_node.into(),
}
}
pub fn from_str(input: &str) -> Result<Self, ProcessIdParseError> {
// split string on colons into 3 segments
let mut segments = input.split(':');
let process_name = segments
.next()
.ok_or(ProcessIdParseError::MissingField)?
.to_string();
let package_name = segments
.next()
.ok_or(ProcessIdParseError::MissingField)?
.to_string();
let publisher_node = segments
.next()
.ok_or(ProcessIdParseError::MissingField)?
.to_string();
if segments.next().is_some() {
return Err(ProcessIdParseError::TooManyColons);
}
Ok(ProcessId {
process_name,
package_name,
publisher_node,
})
}
pub fn to_string(&self) -> String {
[
self.process_name.as_str(),
self.package_name.as_str(),
self.publisher_node.as_str(),
]
.join(":")
}
pub fn process(&self) -> &str {
&self.process_name
}
pub fn package(&self) -> &str {
&self.package_name
}
pub fn publisher_node(&self) -> &str {
&self.publisher_node
}
pub fn en_wit(&self) -> wit::ProcessId {
wit::ProcessId {
process_name: self.process_name.clone(),
package_name: self.package_name.clone(),
publisher_node: self.publisher_node.clone(),
}
}
pub fn de_wit(wit: wit::ProcessId) -> ProcessId {
ProcessId {
process_name: wit.process_name,
package_name: wit.package_name,
publisher_node: wit.publisher_node,
}
}
}
#[derive(Debug)]
pub enum ProcessIdParseError {
TooManyColons,
MissingField,
}
#[derive(Clone, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
pub struct Address {
pub node: NodeId,
pub process: ProcessId,
}
impl Address {
pub fn en_wit(&self) -> wit::Address {
wit::Address {
node: self.node.clone(),
process: self.process.en_wit(),
}
}
pub fn de_wit(wit: wit::Address) -> Address {
Address {
node: wit.node,
process: ProcessId {
process_name: wit.process.process_name,
package_name: wit.process.package_name,
publisher_node: wit.process.publisher_node,
},
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Payload {
pub mime: Option<String>, // MIME type
pub bytes: Vec<u8>,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Request {
pub inherit: bool,
pub expects_response: Option<u64>, // number of seconds until timeout
pub ipc: Vec<u8>,
pub metadata: Option<String>, // JSON-string
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Response {
pub inherit: bool,
pub ipc: Vec<u8>,
pub metadata: Option<String>, // JSON-string
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum Message {
Request(Request),
Response((Response, Option<Context>)),
}
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct Capability {
pub issuer: Address,
pub params: String, // JSON-string
}
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct SignedCapability {
pub issuer: Address,
pub params: String, // JSON-string
pub signature: Vec<u8>, // signed by the kernel, so we can verify that the kernel issued it
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct SendError {
pub kind: SendErrorKind,
pub target: Address,
pub message: Message,
pub payload: Option<Payload>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum SendErrorKind {
Offline,
Timeout,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum OnPanic {
None,
Restart,
Requests(Vec<(Address, Request, Option<Payload>)>),
}
impl OnPanic {
pub fn is_restart(&self) -> bool {
match self {
OnPanic::None => false,
OnPanic::Restart => true,
OnPanic::Requests(_) => false,
}
}
}
#[derive(Debug, Serialize, Deserialize)]
pub enum KernelCommand {
StartProcess {
id: ProcessId,
wasm_bytes_handle: u128,
on_panic: OnPanic,
initial_capabilities: HashSet<SignedCapability>,
public: bool,
},
KillProcess(ProcessId), // this is extrajudicial killing: we might lose messages!
// kernel only
RebootProcess {
process_id: ProcessId,
persisted: PersistedProcess,
},
Shutdown,
}
#[derive(Debug, Serialize, Deserialize)]
pub enum KernelResponse {
StartedProcess,
StartProcessError,
KilledProcess(ProcessId),
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct PersistedProcess {
pub wasm_bytes_handle: u128,
// pub drive: String,
// pub full_path: String,
pub on_panic: OnPanic,
pub capabilities: HashSet<Capability>,
pub public: bool, // marks if a process allows messages from any process
}
#[derive(Debug, Serialize, Deserialize)]
pub struct VfsRequest {
pub drive: String,
pub action: VfsAction,
}
#[derive(Debug, Serialize, Deserialize)]
pub enum VfsAction {
New,
Add {
full_path: String,
entry_type: AddEntryType,
},
Rename {
full_path: String,
new_full_path: String,
},
Delete(String),
WriteOffset {
full_path: String,
offset: u64,
},
SetSize {
full_path: String,
size: u64,
},
GetPath(u128),
GetHash(String),
GetEntry(String),
GetFileChunk {
full_path: String,
offset: u64,
length: u64,
},
GetEntryLength(String),
}
#[derive(Debug, Serialize, Deserialize)]
pub enum AddEntryType {
Dir,
NewFile, // add a new file to fs and add name in vfs
ExistingFile { hash: u128 }, // link an existing file in fs to a new name in vfs
ZipArchive,
}
#[derive(Debug, Serialize, Deserialize)]
pub enum GetEntryType {
Dir,
File,
}
#[derive(Debug, Serialize, Deserialize)]
pub enum VfsResponse {
Ok,
Err(VfsError),
GetPath(Option<String>),
GetHash(Option<u128>),
GetEntry {
// file bytes in payload, if entry was a file
is_file: bool,
children: Vec<String>,
},
GetFileChunk, // chunk in payload
GetEntryLength(u64),
}
#[derive(Debug, Serialize, Deserialize)]
pub enum VfsError {
BadDriveName,
BadDescriptor,
NoCap,
EntryNotFound,
}
#[allow(dead_code)]
impl VfsError {
pub fn kind(&self) -> &str {
match *self {
VfsError::BadDriveName => "BadDriveName",
VfsError::BadDescriptor => "BadDescriptor",
VfsError::NoCap => "NoCap",
VfsError::EntryNotFound => "EntryNotFound",
}
}
}
//
// package types
//
pub type PackageVersion = (u32, u32, u32);
/// the type that gets deserialized from `metadata.json` in a package
#[derive(Debug, Serialize, Deserialize)]
pub struct PackageMetadata {
pub package: String,
pub publisher: String,
pub version: PackageVersion,
pub description: Option<String>,
pub website: Option<String>,
}
/// the type that gets deserialized from each entry in the array in `manifest.json`
#[derive(Debug, Serialize, Deserialize)]
pub struct PackageManifestEntry {
pub process_name: String,
pub process_wasm_path: String,
pub on_panic: OnPanic,
pub request_networking: bool,
pub request_messaging: Vec<String>,
pub public: bool,
}
//
// display impls
//
impl std::fmt::Display for ProcessId {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.to_string())
}
}
impl std::fmt::Display for Address {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}@{}", self.node, self.process.to_string(),)
}
}
impl std::fmt::Display for Message {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Message::Request(request) => write!(
f,
"Request(\n inherit: {},\n expects_response: {:?},\n ipc: {} bytes,\n metadata: {}\n )",
request.inherit,
request.expects_response,
request.ipc.len(),
&request.metadata.as_ref().unwrap_or(&"None".into()),
),
Message::Response((response, context)) => write!(
f,
"Response(\n inherit: {},\n ipc: {} bytes,\n metadata: {},\n context: {} bytes\n )",
response.inherit,
response.ipc.len(),
&response.metadata.as_ref().unwrap_or(&"None".into()),
if context.is_none() {
0
} else {
context.as_ref().unwrap().len()
},
),
}
}
}
//
// conversions between wit types and kernel types (annoying!)
//
pub fn de_wit_request(wit: wit::Request) -> Request {
Request {
inherit: wit.inherit,
expects_response: wit.expects_response,
ipc: wit.ipc,
metadata: wit.metadata,
}
}
pub fn en_wit_request(request: Request) -> wit::Request {
wit::Request {
inherit: request.inherit,
expects_response: request.expects_response,
ipc: request.ipc,
metadata: request.metadata,
}
}
pub fn de_wit_response(wit: wit::Response) -> Response {
Response {
inherit: wit.inherit,
ipc: wit.ipc,
metadata: wit.metadata,
}
}
pub fn en_wit_response(response: Response) -> wit::Response {
wit::Response {
inherit: response.inherit,
ipc: response.ipc,
metadata: response.metadata,
}
}
pub fn de_wit_payload(wit: Option<wit::Payload>) -> Option<Payload> {
match wit {
None => None,
Some(wit) => Some(Payload {
mime: wit.mime,
bytes: wit.bytes,
}),
}
}
pub fn en_wit_payload(load: Option<Payload>) -> Option<wit::Payload> {
match load {
None => None,
Some(load) => Some(wit::Payload {
mime: load.mime,
bytes: load.bytes,
}),
}
}
pub fn de_wit_signed_capability(wit: wit::SignedCapability) -> SignedCapability {
SignedCapability {
issuer: Address {
node: wit.issuer.node,
process: ProcessId {
process_name: wit.issuer.process.process_name,
package_name: wit.issuer.process.package_name,
publisher_node: wit.issuer.process.publisher_node,
},
},
params: wit.params,
signature: wit.signature,
}
}
pub fn en_wit_signed_capability(cap: SignedCapability) -> wit::SignedCapability {
wit::SignedCapability {
issuer: cap.issuer.en_wit(),
params: cap.params,
signature: cap.signature,
}
}
pub fn en_wit_message(message: Message) -> wit::Message {
match message {
Message::Request(request) => wit::Message::Request(en_wit_request(request)),
Message::Response((response, context)) => {
wit::Message::Response((en_wit_response(response), context))
}
}
}
pub fn en_wit_send_error(error: SendError) -> wit::SendError {
wit::SendError {
kind: en_wit_send_error_kind(error.kind),
message: en_wit_message(error.message),
payload: en_wit_payload(error.payload),
}
}
pub fn en_wit_send_error_kind(kind: SendErrorKind) -> wit::SendErrorKind {
match kind {
SendErrorKind::Offline => wit::SendErrorKind::Offline,
SendErrorKind::Timeout => wit::SendErrorKind::Timeout,
}
}
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(),
),
}
}

View File

@ -1,611 +0,0 @@
use crate::uqbar::process::standard as wit;
pub use crate::uqbar::process::standard::*;
/// Uqbar process standard library for Rust compiled to WASM
/// Must be used in context of bindings generated by uqbar.wit
use serde::{Deserialize, Serialize};
wit_bindgen::generate!({
path: "../wit",
world: "lib",
});
pub mod kernel_types;
/// Override the println! macro to print to the terminal
#[macro_export]
macro_rules! println {
() => {
$crate::print_to_terminal(0, "\n");
};
($($arg:tt)*) => {{
$crate::print_to_terminal(0, &format!($($arg)*));
}};
}
/// PackageId is like a ProcessId, but for a package. Only contains the name
/// of the package and the name of the publisher.
#[derive(Hash, Eq, PartialEq, Debug, Clone, Serialize, Deserialize)]
pub struct PackageId {
package_name: String,
publisher_node: String,
}
impl PackageId {
pub fn new(package_name: &str, publisher_node: &str) -> Self {
PackageId {
package_name: package_name.into(),
publisher_node: publisher_node.into(),
}
}
pub fn from_str(input: &str) -> Result<Self, ProcessIdParseError> {
// split string on colons into 2 segments
let mut segments = input.split(':');
let package_name = segments
.next()
.ok_or(ProcessIdParseError::MissingField)?
.to_string();
let publisher_node = segments
.next()
.ok_or(ProcessIdParseError::MissingField)?
.to_string();
if segments.next().is_some() {
return Err(ProcessIdParseError::TooManyColons);
}
Ok(PackageId {
package_name,
publisher_node,
})
}
pub fn to_string(&self) -> String {
[self.package_name.as_str(), self.publisher_node.as_str()].join(":")
}
pub fn package(&self) -> &str {
&self.package_name
}
pub fn publisher_node(&self) -> &str {
&self.publisher_node
}
}
/// ProcessId is defined in the wit bindings, but constructors and methods
/// are defined here.
impl ProcessId {
/// generates a random u64 number if process_name is not declared
pub fn new(process_name: &str, package_name: &str, publisher_node: &str) -> Self {
ProcessId {
process_name: process_name.into(),
package_name: package_name.into(),
publisher_node: publisher_node.into(),
}
}
pub fn from_str(input: &str) -> Result<Self, ProcessIdParseError> {
// split string on colons into 3 segments
let mut segments = input.split(':');
let process_name = segments
.next()
.ok_or(ProcessIdParseError::MissingField)?
.to_string();
let package_name = segments
.next()
.ok_or(ProcessIdParseError::MissingField)?
.to_string();
let publisher_node = segments
.next()
.ok_or(ProcessIdParseError::MissingField)?
.to_string();
if segments.next().is_some() {
return Err(ProcessIdParseError::TooManyColons);
}
Ok(ProcessId {
process_name,
package_name,
publisher_node,
})
}
pub fn to_string(&self) -> String {
[
self.process_name.as_str(),
self.package_name.as_str(),
self.publisher_node.as_str(),
]
.join(":")
}
pub fn process(&self) -> &str {
&self.process_name
}
pub fn package(&self) -> &str {
&self.package_name
}
pub fn publisher_node(&self) -> &str {
&self.publisher_node
}
}
pub trait IntoProcessId {
fn into_process_id(self) -> Result<ProcessId, ProcessIdParseError>;
}
impl IntoProcessId for ProcessId {
fn into_process_id(self) -> Result<ProcessId, ProcessIdParseError> {
Ok(self)
}
}
impl IntoProcessId for &str {
fn into_process_id(self) -> Result<ProcessId, ProcessIdParseError> {
ProcessId::from_str(self)
}
}
impl std::fmt::Display for ProcessId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}:{}:{}",
self.process_name, self.package_name, self.publisher_node
)
}
}
impl PartialEq for ProcessId {
fn eq(&self, other: &Self) -> bool {
self.process_name == other.process_name
&& self.package_name == other.package_name
&& self.publisher_node == other.publisher_node
}
}
impl PartialEq<&str> for ProcessId {
fn eq(&self, other: &&str) -> bool {
&self.to_string() == other
}
}
impl PartialEq<ProcessId> for &str {
fn eq(&self, other: &ProcessId) -> bool {
self == &other.to_string()
}
}
#[derive(Debug)]
pub enum ProcessIdParseError {
TooManyColons,
MissingField,
}
impl std::fmt::Display for ProcessIdParseError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
ProcessIdParseError::TooManyColons => "Too many colons in ProcessId string",
ProcessIdParseError::MissingField => "Missing field in ProcessId string",
}
)
}
}
impl std::error::Error for ProcessIdParseError {
fn description(&self) -> &str {
match self {
ProcessIdParseError::TooManyColons => "Too many colons in ProcessId string",
ProcessIdParseError::MissingField => "Missing field in ProcessId string",
}
}
}
/// Address is defined in the wit bindings, but constructors and methods here.
impl Address {
pub fn new<T: IntoProcessId>(node: &str, process: T) -> Result<Address, ProcessIdParseError> {
Ok(Address {
node: node.to_string(),
process: process.into_process_id()?,
})
}
pub fn from_str(input: &str) -> Result<Self, AddressParseError> {
// split string on colons into 4 segments,
// first one with @, next 3 with :
let mut name_rest = input.split('@');
let node = name_rest
.next()
.ok_or(AddressParseError::MissingField)?
.to_string();
let mut segments = name_rest
.next()
.ok_or(AddressParseError::MissingNodeId)?
.split(':');
let process_name = segments
.next()
.ok_or(AddressParseError::MissingField)?
.to_string();
let package_name = segments
.next()
.ok_or(AddressParseError::MissingField)?
.to_string();
let publisher_node = segments
.next()
.ok_or(AddressParseError::MissingField)?
.to_string();
if segments.next().is_some() {
return Err(AddressParseError::TooManyColons);
}
Ok(Address {
node,
process: ProcessId {
process_name,
package_name,
publisher_node,
},
})
}
pub fn to_string(&self) -> String {
[self.node.as_str(), &self.process.to_string()].join("@")
}
}
pub trait IntoAddress {
fn into_address(self) -> Result<Address, AddressParseError>;
}
impl IntoAddress for Address {
fn into_address(self) -> Result<Address, AddressParseError> {
Ok(self)
}
}
impl IntoAddress for &str {
fn into_address(self) -> Result<Address, AddressParseError> {
Address::from_str(self)
}
}
#[derive(Debug)]
pub enum AddressParseError {
TooManyColons,
MissingNodeId,
MissingField,
}
impl std::fmt::Display for AddressParseError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
AddressParseError::TooManyColons => "Too many colons in ProcessId string",
AddressParseError::MissingNodeId => "Node ID missing",
AddressParseError::MissingField => "Missing field in ProcessId string",
}
)
}
}
impl std::error::Error for AddressParseError {
fn description(&self) -> &str {
match self {
AddressParseError::TooManyColons => "Too many colons in ProcessId string",
AddressParseError::MissingNodeId => "Node ID missing",
AddressParseError::MissingField => "Missing field in ProcessId string",
}
}
}
///
/// Here, we define wrappers over the wit bindings to make them easier to use.
/// This library prescribes the use of IPC and metadata types serialized and
/// deserialized to JSON, which is far from optimal for performance, but useful
/// for applications that want to maximize composability and introspectability.
/// For payloads, we use bincode to serialize and deserialize to bytes.
///
pub struct Request {
target: Option<Address>,
inherit: bool,
timeout: Option<u64>,
ipc: Option<Vec<u8>>,
metadata: Option<String>,
payload: Option<Payload>,
context: Option<Vec<u8>>,
}
impl Request {
pub fn new() -> Self {
Request {
target: None,
inherit: false,
timeout: None,
ipc: None,
metadata: None,
payload: None,
context: None,
}
}
pub fn target<T: IntoAddress>(mut self, target: T) -> Result<Self, AddressParseError> {
self.target = Some(target.into_address()?);
Ok(self)
}
pub fn inherit(mut self, inherit: bool) -> Self {
self.inherit = inherit;
self
}
pub fn expects_response(mut self, timeout: u64) -> Self {
self.timeout = Some(timeout);
self
}
pub fn ipc_bytes(mut self, ipc: Vec<u8>) -> Self {
self.ipc = Some(ipc);
self
}
pub fn ipc<T, F>(mut self, ipc: &T, serializer: F) -> anyhow::Result<Self>
where
F: Fn(&T) -> anyhow::Result<Vec<u8>>,
{
self.ipc = Some(serializer(ipc)?);
Ok(self)
}
pub fn metadata(mut self, metadata: String) -> Self {
self.metadata = Some(metadata);
self
}
pub fn payload(mut self, payload: Payload) -> Self {
self.payload = Some(payload);
self
}
pub fn payload_mime(mut self, mime: String) -> Self {
if self.payload.is_none() {
self.payload = Some(Payload {
mime: Some(mime),
bytes: vec![],
});
self
} else {
self.payload = Some(Payload {
mime: Some(mime),
bytes: self.payload.unwrap().bytes,
});
self
}
}
pub fn payload_bytes(mut self, bytes: Vec<u8>) -> Self {
if self.payload.is_none() {
self.payload = Some(Payload { mime: None, bytes });
self
} else {
self.payload = Some(Payload {
mime: self.payload.unwrap().mime,
bytes,
});
self
}
}
pub fn context_bytes(mut self, context: Vec<u8>) -> Self {
self.context = Some(context);
self
}
pub fn context<T, F>(mut self, context: &T, serializer: F) -> anyhow::Result<Self>
where
F: Fn(&T) -> anyhow::Result<Vec<u8>>,
{
self.context = Some(serializer(context)?);
Ok(self)
}
pub fn send(self) -> anyhow::Result<()> {
if let (Some(target), Some(ipc)) = (self.target, self.ipc) {
crate::send_request(
&target,
&wit::Request {
inherit: self.inherit,
expects_response: self.timeout,
ipc,
metadata: self.metadata,
},
self.context.as_ref(),
self.payload.as_ref(),
);
Ok(())
} else {
Err(anyhow::anyhow!("missing fields"))
}
}
pub fn send_and_await_response(self, timeout: u64) -> anyhow::Result<Result<(Address, Message), SendError>> {
if let (Some(target), Some(ipc)) = (self.target, self.ipc) {
Ok(crate::send_and_await_response(
&target,
&wit::Request {
inherit: self.inherit,
expects_response: Some(timeout),
ipc,
metadata: self.metadata,
},
self.payload.as_ref(),
))
} else {
Err(anyhow::anyhow!("missing fields"))
}
}
}
pub struct Response {
inherit: bool,
ipc: Option<Vec<u8>>,
metadata: Option<String>,
payload: Option<Payload>,
}
impl Response {
pub fn new() -> Self {
Response {
inherit: false,
ipc: None,
metadata: None,
payload: None,
}
}
pub fn inherit(mut self, inherit: bool) -> Self {
self.inherit = inherit;
self
}
pub fn ipc_bytes(mut self, ipc: Vec<u8>) -> Self {
self.ipc = Some(ipc);
self
}
pub fn ipc<T, F>(mut self, ipc: &T, serializer: F) -> anyhow::Result<Self>
where
F: Fn(&T) -> anyhow::Result<Vec<u8>>,
{
self.ipc = Some(serializer(ipc)?);
Ok(self)
}
pub fn metadata(mut self, metadata: Option<String>) -> Self {
self.metadata = metadata;
self
}
pub fn payload(mut self, payload: Payload) -> Self {
self.payload = Some(payload);
self
}
pub fn payload_mime(mut self, mime: String) -> Self {
if self.payload.is_none() {
self.payload = Some(Payload {
mime: Some(mime),
bytes: vec![],
});
self
} else {
self.payload = Some(Payload {
mime: Some(mime),
bytes: self.payload.unwrap().bytes,
});
self
}
}
pub fn payload_bytes(mut self, bytes: Vec<u8>) -> Self {
if self.payload.is_none() {
self.payload = Some(Payload { mime: None, bytes });
self
} else {
self.payload = Some(Payload {
mime: self.payload.unwrap().mime,
bytes,
});
self
}
}
pub fn send(self) -> anyhow::Result<()> {
if let Some(ipc) = self.ipc {
crate::send_response(
&wit::Response {
inherit: self.inherit,
ipc,
metadata: self.metadata,
},
self.payload.as_ref(),
);
Ok(())
} else {
Err(anyhow::anyhow!("missing IPC"))
}
}
}
pub fn make_payload<T, F>(payload: &T, serializer: F) -> anyhow::Result<Payload>
where
F: Fn(&T) -> anyhow::Result<Vec<u8>>,
{
Ok(Payload {
mime: None,
bytes: serializer(payload)?,
})
}
pub fn get_typed_payload<T, F>(deserializer: F) -> Option<T>
where
F: Fn(&[u8]) -> anyhow::Result<T>,
{
match crate::get_payload() {
Some(payload) => match deserializer(&payload.bytes) {
Ok(thing) => Some(thing),
Err(_) => None,
},
None => None,
}
}
pub fn get_typed_state<T, F>(deserializer: F) -> Option<T>
where
F: Fn(&[u8]) -> anyhow::Result<T>,
{
match crate::get_state() {
Some(bytes) => match deserializer(&bytes) {
Ok(thing) => Some(thing),
Err(_) => None,
},
None => None,
}
}
pub fn grant_messaging(our: &Address, grant_to: &Vec<ProcessId>) -> anyhow::Result<()> {
let Some(our_messaging_cap) = crate::get_capability(our, &"\"messaging\"".into()) else {
// the kernel will always give us this capability, so this should never happen
return Err(anyhow::anyhow!(
"failed to get our own messaging capability!"
));
};
for process in grant_to {
crate::share_capability(&process, &our_messaging_cap);
}
Ok(())
}
pub fn can_message(address: &Address) -> bool {
crate::get_capability(address, &"\"messaging\"".into()).is_some()
}
///
/// Here, we define types used by various Uqbar runtime components. Use these
/// to interface directly with the kernel, filesystem, virtual filesystem,
/// and other components -- if you have the capability to do so.
///
#[derive(Serialize, Deserialize, Debug)]
pub enum FsAction {
Write,
Replace(u128),
Append(Option<u128>),
Read(u128),
ReadChunk(ReadChunkRequest),
Delete(u128),
Length(u128),
// process state management
GetState,
SetState,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct ReadChunkRequest {
pub file_uuid: u128,
pub start: u64,
pub length: u64,
}