mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-12-26 18:14:35 +03:00
get compiling & running
This commit is contained in:
parent
d943eab73a
commit
073b0d2638
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -4836,6 +4836,7 @@ dependencies = [
|
||||
"elliptic-curve",
|
||||
"ethers",
|
||||
"ethers-providers",
|
||||
"flate2",
|
||||
"futures",
|
||||
"generic-array",
|
||||
"getrandom",
|
||||
@ -4869,6 +4870,7 @@ dependencies = [
|
||||
"warp",
|
||||
"wasmtime",
|
||||
"wasmtime-wasi",
|
||||
"zip",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -22,6 +22,7 @@ dotenv = "0.15.0"
|
||||
elliptic-curve = { version = "0.13.5", features = ["ecdh"] }
|
||||
ethers = "2.0"
|
||||
ethers-providers = "2.0.9"
|
||||
flate2 = "1.0"
|
||||
futures = "0.3"
|
||||
generic-array = "0.14"
|
||||
getrandom = "0.2.10"
|
||||
@ -55,3 +56,4 @@ uuid = { version = "1.1.2", features = ["serde", "v4"] }
|
||||
warp = "0.3.5"
|
||||
wasmtime = "12.0.1"
|
||||
wasmtime-wasi = "12.0.1"
|
||||
zip = "0.6"
|
||||
|
3
build.rs
3
build.rs
@ -31,7 +31,8 @@ fn main() {
|
||||
run_command(Command::new("touch").args(&[&format!("{}/world", pwd.display())])).unwrap();
|
||||
|
||||
// Build wasm32-wasi apps.
|
||||
const WASI_APPS: [&str; 8] = [
|
||||
const WASI_APPS: [&str; 9] = [
|
||||
"app_tracker",
|
||||
"apps_home",
|
||||
"chess",
|
||||
"http_bindings",
|
||||
|
3
modules/app_tracker/Cargo-component.lock
Normal file
3
modules/app_tracker/Cargo-component.lock
Normal file
@ -0,0 +1,3 @@
|
||||
# This file is automatically generated by cargo-component.
|
||||
# It is not intended for manual editing.
|
||||
version = 1
|
453
modules/app_tracker/Cargo.lock
generated
Normal file
453
modules/app_tracker/Cargo.lock
generated
Normal file
@ -0,0 +1,453 @@
|
||||
# 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 = "app_tracker"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bincode",
|
||||
"cargo-component-bindings",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"wit-bindgen",
|
||||
]
|
||||
|
||||
[[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 = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
|
||||
|
||||
[[package]]
|
||||
name = "cargo-component-bindings"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/bytecodealliance/cargo-component#6a2996f280dd8671a2a2d3c83cbe09a39225b526"
|
||||
dependencies = [
|
||||
"cargo-component-macro",
|
||||
"wit-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cargo-component-macro"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/bytecodealliance/cargo-component#6a2996f280dd8671a2a2d3c83cbe09a39225b526"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wit-bindgen-core",
|
||||
"wit-bindgen-rust",
|
||||
"wit-bindgen-rust-lib",
|
||||
"wit-component",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
||||
|
||||
[[package]]
|
||||
name = "form_urlencoded"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652"
|
||||
dependencies = [
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
|
||||
|
||||
[[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 = "idna"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c"
|
||||
dependencies = [
|
||||
"unicode-bidi",
|
||||
"unicode-normalization",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d"
|
||||
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 = "memchr"
|
||||
version = "2.6.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c"
|
||||
|
||||
[[package]]
|
||||
name = "percent-encoding"
|
||||
version = "2.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.66"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pulldown-cmark"
|
||||
version = "0.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77a1a2f1f0a7ecff9c31abbe177637be0e97a0aef46cf8738ece09327985d998"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"memchr",
|
||||
"unicase",
|
||||
]
|
||||
|
||||
[[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.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.188"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.188"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.105"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9"
|
||||
|
||||
[[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.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "718fa2415bcb8d8bd775917a1bf12a7931b6dfa890753378538118181e0cb398"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec"
|
||||
version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50"
|
||||
dependencies = [
|
||||
"tinyvec_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec_macros"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||
|
||||
[[package]]
|
||||
name = "unicase"
|
||||
version = "2.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89"
|
||||
dependencies = [
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-bidi"
|
||||
version = "0.3.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-normalization"
|
||||
version = "0.1.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921"
|
||||
dependencies = [
|
||||
"tinyvec",
|
||||
]
|
||||
|
||||
[[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 = "url"
|
||||
version = "2.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5"
|
||||
dependencies = [
|
||||
"form_urlencoded",
|
||||
"idna",
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-encoder"
|
||||
version = "0.32.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1ba64e81215916eaeb48fee292f29401d69235d62d8b8fd92a7b2844ec5ae5f7"
|
||||
dependencies = [
|
||||
"leb128",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-metadata"
|
||||
version = "0.10.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08dc59d1fa569150851542143ca79438ca56845ccb31696c70225c638e063471"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"indexmap",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"spdx",
|
||||
"wasm-encoder",
|
||||
"wasmparser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasmparser"
|
||||
version = "0.112.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e986b010f47fcce49cf8ea5d5f9e5d2737832f12b53ae8ae785bbe895d0877bf"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8a3e8e965dc50e6eb4410d9a11720719fadc6a1713803ea5f3be390b81c8279"
|
||||
dependencies = [
|
||||
"bitflags 2.4.0",
|
||||
"wit-bindgen-rust-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-core"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77255512565dfbd0b61de466e854918041d1da53c7bc049d6188c6e02643dc1e"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"wit-component",
|
||||
"wit-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-rust"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "399c60e6ea8598d1380e792f13d557007834f0fb799fea6503408cbc5debb4ae"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"heck",
|
||||
"wasm-metadata",
|
||||
"wit-bindgen-core",
|
||||
"wit-bindgen-rust-lib",
|
||||
"wit-component",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-rust-lib"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cd9fb7a43c7dc28b0b727d6ae01bf369981229b7539e768fba2b7a4df13feeeb"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"wit-bindgen-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-rust-macro"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "44cea5ed784da06da0e55836a6c160e7502dbe28771c2368a595e8606243bf22"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"proc-macro2",
|
||||
"syn",
|
||||
"wit-bindgen-core",
|
||||
"wit-bindgen-rust",
|
||||
"wit-bindgen-rust-lib",
|
||||
"wit-component",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-component"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "66d9f2d16dd55d1a372dcfd4b7a466ea876682a5a3cb97e71ec9eef04affa876"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bitflags 2.4.0",
|
||||
"indexmap",
|
||||
"log",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"wasm-encoder",
|
||||
"wasm-metadata",
|
||||
"wasmparser",
|
||||
"wit-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-parser"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "61e8b849bea13cc2315426b16efe6eb6813466d78f5fde69b0bb150c9c40e0dc"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"id-arena",
|
||||
"indexmap",
|
||||
"log",
|
||||
"pulldown-cmark",
|
||||
"semver",
|
||||
"unicode-xid",
|
||||
"url",
|
||||
]
|
30
modules/app_tracker/Cargo.toml
Normal file
30
modules/app_tracker/Cargo.toml
Normal file
@ -0,0 +1,30 @@
|
||||
[package]
|
||||
name = "app_tracker"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
opt-level = "s"
|
||||
lto = true
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
bincode = "1.3.3"
|
||||
cargo-component-bindings = { git = "https://github.com/bytecodealliance/cargo-component" }
|
||||
serde = {version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
wit-bindgen = { version = "0.11.0", default_features = false }
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[package.metadata.component]
|
||||
package = "component:uq-process"
|
||||
|
||||
[package.metadata.component.target]
|
||||
path = "wit"
|
||||
|
||||
[package.metadata.component.dependencies]
|
1
modules/app_tracker/src/kernel_types.rs
Symbolic link
1
modules/app_tracker/src/kernel_types.rs
Symbolic link
@ -0,0 +1 @@
|
||||
../../../src/kernel_types.rs
|
228
modules/app_tracker/src/lib.rs
Normal file
228
modules/app_tracker/src/lib.rs
Normal file
@ -0,0 +1,228 @@
|
||||
cargo_component_bindings::generate!();
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use bindings::{component::uq_process::types::*, get_capability, get_payload, Guest, print_to_terminal, receive};
|
||||
|
||||
mod kernel_types;
|
||||
use kernel_types as kt;
|
||||
mod process_lib;
|
||||
|
||||
struct Component;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub enum AppTrackerRequest {
|
||||
New { package: String },
|
||||
Install { package: String },
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct ManifestEntry {
|
||||
name: String,
|
||||
path: String,
|
||||
on_panic: kt::OnPanic,
|
||||
networking: bool,
|
||||
process_caps: Vec<String>,
|
||||
}
|
||||
|
||||
// TODO: error handle
|
||||
fn parse_command(our: &Address, request_string: String) -> anyhow::Result<()>{
|
||||
match serde_json::from_str(&request_string)? {
|
||||
AppTrackerRequest::New { package } => {
|
||||
// TODO: should we check if package already exists before creating?
|
||||
|
||||
let Some(payload) = get_payload() else {
|
||||
panic!("");
|
||||
};
|
||||
|
||||
let vfs_address = Address {
|
||||
node: our.node.clone(),
|
||||
process: ProcessId::Name("vfs".into()),
|
||||
};
|
||||
// make vfs package
|
||||
let _ = process_lib::send_and_await_response(
|
||||
&vfs_address,
|
||||
false,
|
||||
Some(serde_json::to_string(&kt::VfsRequest::New {
|
||||
identifier: package.clone(),
|
||||
}).unwrap()),
|
||||
None,
|
||||
None,
|
||||
5,
|
||||
)?;
|
||||
|
||||
// add zip bytes
|
||||
let _ = process_lib::send_and_await_response(
|
||||
&vfs_address,
|
||||
true,
|
||||
Some(serde_json::to_string(&kt::VfsRequest::Add {
|
||||
identifier: package.clone(),
|
||||
full_path: "".into(), // TODO
|
||||
entry_type: kt::AddEntryType::ZipArchive,
|
||||
}).unwrap()),
|
||||
None,
|
||||
Some(&payload),
|
||||
5,
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
AppTrackerRequest::Install { package } => {
|
||||
let vfs_address = Address {
|
||||
node: our.node.clone(),
|
||||
process: ProcessId::Name("vfs".into()),
|
||||
};
|
||||
// get manifest
|
||||
let _ = process_lib::send_and_await_response(
|
||||
&vfs_address,
|
||||
false,
|
||||
Some(serde_json::to_string(&kt::VfsRequest::GetEntry {
|
||||
identifier: package.clone(),
|
||||
full_path: "/.manifest".into(),
|
||||
}).unwrap()),
|
||||
None,
|
||||
None,
|
||||
5,
|
||||
)?;
|
||||
let Some(payload) = get_payload() else {
|
||||
panic!("");
|
||||
};
|
||||
let manifest = String::from_utf8(payload.bytes)?;
|
||||
let manifest = serde_json::from_str::<Vec<ManifestEntry>>(&manifest).unwrap();
|
||||
|
||||
for entry in manifest {
|
||||
let path =
|
||||
if entry.path.starts_with("/") {
|
||||
entry.path
|
||||
} else {
|
||||
format!("/{}", entry.path)
|
||||
};
|
||||
|
||||
let (_, hash_response) = process_lib::send_and_await_response(
|
||||
&vfs_address,
|
||||
false,
|
||||
Some(serde_json::to_string(&kt::VfsRequest::GetHash {
|
||||
identifier: package.clone(),
|
||||
full_path: path,
|
||||
}).unwrap()),
|
||||
None,
|
||||
None,
|
||||
5,
|
||||
)?;
|
||||
let Message::Response((Response { ipc: Some(ipc), .. }, _)) = hash_response else {
|
||||
panic!("baz");
|
||||
};
|
||||
let kt::VfsResponse::GetHash { hash, .. } = serde_json::from_str(&ipc).unwrap() else {
|
||||
panic!("aaa");
|
||||
};
|
||||
|
||||
// build initial caps
|
||||
let mut initial_capabilities: HashSet<kt::SignedCapability> = HashSet::new();
|
||||
if entry.networking {
|
||||
let Some(networking_cap) = get_capability(
|
||||
&Address {
|
||||
node: our.node.clone(),
|
||||
process: ProcessId::Name("kernel".into()),
|
||||
},
|
||||
&"\"network\"".to_string(),
|
||||
) else {
|
||||
panic!("app_tracker: no net cap");
|
||||
};
|
||||
initial_capabilities.insert(kt::de_wit_signed_capability(networking_cap));
|
||||
}
|
||||
let Some(read_cap) = get_capability(
|
||||
&vfs_address.clone(),
|
||||
&serde_json::to_string(&serde_json::json!({
|
||||
"kind": "read",
|
||||
"identifier": package,
|
||||
})).unwrap(),
|
||||
) else {
|
||||
panic!("app_tracker: no read cap");
|
||||
};
|
||||
initial_capabilities.insert(kt::de_wit_signed_capability(read_cap));
|
||||
let Some(write_cap) = get_capability(
|
||||
&vfs_address.clone(),
|
||||
&serde_json::to_string(&serde_json::json!({
|
||||
"kind": "write",
|
||||
"identifier": package,
|
||||
})).unwrap(),
|
||||
) else {
|
||||
panic!("app_tracker: no write cap");
|
||||
};
|
||||
initial_capabilities.insert(kt::de_wit_signed_capability(write_cap));
|
||||
for process_name in entry.process_caps {
|
||||
let Some(messaging_cap) = get_capability(
|
||||
&Address {
|
||||
node: our.node.clone(),
|
||||
process: ProcessId::Name(process_name.clone()),
|
||||
},
|
||||
&serde_json::to_string(&serde_json::json!({
|
||||
"messaging": kt::ProcessId::Name(process_name.into()),
|
||||
})).unwrap(),
|
||||
) else {
|
||||
panic!("app_tracker: no cap");
|
||||
};
|
||||
initial_capabilities.insert(kt::de_wit_signed_capability(messaging_cap));
|
||||
}
|
||||
|
||||
|
||||
let _ = process_lib::send_and_await_response(
|
||||
&Address {
|
||||
node: our.node.clone(),
|
||||
process: ProcessId::Name("kernel".into()),
|
||||
},
|
||||
false,
|
||||
Some(serde_json::to_string(&kt::KernelCommand::StartProcess {
|
||||
name: Some(entry.name),
|
||||
wasm_bytes_handle: hash,
|
||||
on_panic: entry.on_panic,
|
||||
initial_capabilities,
|
||||
}).unwrap()),
|
||||
None,
|
||||
None,
|
||||
5,
|
||||
)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Guest for Component {
|
||||
fn init(our: Address) {
|
||||
assert_eq!(our.process, ProcessId::Name("app_tracker".into()));
|
||||
print_to_terminal(0, &format!("app_tracker: running"));
|
||||
loop {
|
||||
let message = match receive() {
|
||||
Ok((source, message)) => {
|
||||
if our.node != source.node {
|
||||
continue;
|
||||
}
|
||||
message
|
||||
}
|
||||
Err((error, _context)) => {
|
||||
print_to_terminal(0, &format!("net error: {:?}!", error.kind));
|
||||
continue;
|
||||
}
|
||||
};
|
||||
match message {
|
||||
Message::Request(Request {
|
||||
ipc,
|
||||
..
|
||||
}) => {
|
||||
let Some(command) = ipc else {
|
||||
continue;
|
||||
};
|
||||
match parse_command(&our, command) {
|
||||
Ok(_) => {},
|
||||
Err(e) => {
|
||||
print_to_terminal(0, &format!("app_tracker: got error {}", e));
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
1
modules/app_tracker/src/process_lib.rs
Symbolic link
1
modules/app_tracker/src/process_lib.rs
Symbolic link
@ -0,0 +1 @@
|
||||
../../../src/process_lib.rs
|
@ -82,7 +82,8 @@ fn handle_message (
|
||||
).ok_or(anyhow::anyhow!("New failed: no vfs 'write' capability found"))?;
|
||||
let Some(spawned_process_id) = spawn(
|
||||
&ProcessId::Id(0),
|
||||
"", // TODO
|
||||
"key_value",
|
||||
"/key_value_worker.wasm",
|
||||
&OnPanic::None, // TODO: notify us
|
||||
&Capabilities::Some(vec![vfs_read, vfs_write]),
|
||||
) else {
|
||||
|
@ -195,37 +195,54 @@ impl UqProcessImports for ProcessWasi {
|
||||
async fn spawn(
|
||||
&mut self,
|
||||
id: wit::ProcessId,
|
||||
identifier: String,
|
||||
package: String,
|
||||
full_path: String,
|
||||
on_panic: wit::OnPanic,
|
||||
capabilities: wit::Capabilities,
|
||||
) -> Result<Option<wit::ProcessId>> {
|
||||
let _ = send_and_await_response(
|
||||
let vfs_address = wit::Address {
|
||||
node: self.process.metadata.our.node.clone(),
|
||||
process: wit::ProcessId::Name("vfs".into()),
|
||||
};
|
||||
let (_, hash_response) = send_and_await_response(
|
||||
self,
|
||||
wit::Address {
|
||||
node: self.process.metadata.our.node.clone(),
|
||||
process: wit::ProcessId::Name("vfs".into()),
|
||||
},
|
||||
vfs_address.clone(),
|
||||
wit::Request {
|
||||
inherit: false,
|
||||
expects_response: Some(5),
|
||||
ipc: Some(
|
||||
serde_json::to_string(&t::VfsRequest::GetEntry {
|
||||
identifier: identifier.clone(),
|
||||
full_path: full_path.clone(),
|
||||
})
|
||||
.unwrap(),
|
||||
),
|
||||
ipc: Some(serde_json::to_string(&t::VfsRequest::GetHash {
|
||||
identifier: package.clone(),
|
||||
full_path: full_path.clone(),
|
||||
}).unwrap()),
|
||||
metadata: None,
|
||||
},
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
).await.unwrap().unwrap();
|
||||
let wit::Message::Response((wit::Response { ipc: Some(ipc), .. }, _)) = hash_response else {
|
||||
panic!("baz");
|
||||
};
|
||||
let t::VfsResponse::GetHash { hash, .. } = serde_json::from_str(&ipc).unwrap() else {
|
||||
panic!("aaa");
|
||||
};
|
||||
|
||||
let _ = send_and_await_response(
|
||||
self,
|
||||
vfs_address,
|
||||
wit::Request {
|
||||
inherit: false,
|
||||
expects_response: Some(5),
|
||||
ipc: Some(serde_json::to_string(&t::VfsRequest::GetEntry {
|
||||
identifier: package.clone(),
|
||||
full_path: full_path.clone(),
|
||||
}).unwrap()),
|
||||
metadata: None,
|
||||
},
|
||||
None,
|
||||
).await.unwrap().unwrap();
|
||||
|
||||
// TODO: handle case of response is Error
|
||||
let Some(t::Payload { mime: _, bytes }) = self.process.last_payload else {
|
||||
panic!(""); // TODO
|
||||
let Some(t::Payload { mime: _, ref bytes }) = self.process.last_payload else {
|
||||
panic!(""); // TODO
|
||||
};
|
||||
|
||||
self.process
|
||||
@ -247,8 +264,7 @@ impl UqProcessImports for ProcessWasi {
|
||||
wit::ProcessId::Name(ref name) => Some(name.into()),
|
||||
wit::ProcessId::Id(_id) => None,
|
||||
},
|
||||
identifier,
|
||||
full_path,
|
||||
wasm_bytes_handle: hash,
|
||||
on_panic: de_wit_on_panic(on_panic),
|
||||
// TODO
|
||||
initial_capabilities: match capabilities {
|
||||
@ -259,13 +275,27 @@ impl UqProcessImports for ProcessWasi {
|
||||
on: self.process.metadata.our.process.clone(),
|
||||
responder: tx,
|
||||
});
|
||||
rx.await.unwrap()
|
||||
rx.await
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(|cap| t::SignedCapability {
|
||||
issuer: cap.issuer.clone(),
|
||||
params: cap.params.clone(),
|
||||
signature: self
|
||||
.process
|
||||
.keypair
|
||||
.sign(&bincode::serialize(&cap).unwrap())
|
||||
.as_ref()
|
||||
.to_vec(),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
wit::Capabilities::Some(caps) => caps
|
||||
.into_iter()
|
||||
.map(|cap| t::Capability {
|
||||
.map(|cap| t::SignedCapability {
|
||||
issuer: de_wit_address(cap.issuer),
|
||||
params: cap.params,
|
||||
signature: cap.signature,
|
||||
})
|
||||
.collect(),
|
||||
},
|
||||
@ -274,7 +304,10 @@ impl UqProcessImports for ProcessWasi {
|
||||
),
|
||||
metadata: None,
|
||||
}),
|
||||
payload: Some(t::Payload { mime: None, bytes }),
|
||||
payload: Some(t::Payload {
|
||||
mime: None,
|
||||
bytes: bytes.clone(),
|
||||
}),
|
||||
signed_capabilities: None,
|
||||
})
|
||||
.await?;
|
||||
@ -886,7 +919,7 @@ async fn make_process_loop(
|
||||
last_payload: None,
|
||||
contexts: HashMap::new(),
|
||||
message_queue: VecDeque::new(),
|
||||
caps_oracle,
|
||||
caps_oracle: caps_oracle.clone(),
|
||||
next_message_caps: None,
|
||||
},
|
||||
table,
|
||||
@ -949,6 +982,24 @@ async fn make_process_loop(
|
||||
t::OnPanic::None => {}
|
||||
// if restart, tell ourselves to init the app again, with same capabilities
|
||||
t::OnPanic::Restart => {
|
||||
let (tx, rx) = tokio::sync::oneshot::channel();
|
||||
let _ = caps_oracle.send(t::CapMessage::GetAll {
|
||||
on: our.process.clone(),
|
||||
responder: tx,
|
||||
});
|
||||
let initial_capabilities = rx.await
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(|cap| t::SignedCapability {
|
||||
issuer: cap.issuer.clone(),
|
||||
params: cap.params.clone(),
|
||||
signature: keypair
|
||||
.sign(&bincode::serialize(&cap).unwrap())
|
||||
.as_ref()
|
||||
.to_vec(),
|
||||
})
|
||||
.collect();
|
||||
|
||||
send_to_loop
|
||||
.send(t::KernelMessage {
|
||||
id: rand::random(),
|
||||
@ -1065,8 +1116,7 @@ async fn handle_kernel_request(
|
||||
//
|
||||
t::KernelCommand::StartProcess {
|
||||
name,
|
||||
identifier,
|
||||
full_path,
|
||||
wasm_bytes_handle,
|
||||
on_panic,
|
||||
initial_capabilities,
|
||||
} => {
|
||||
@ -1081,6 +1131,27 @@ async fn handle_kernel_request(
|
||||
return;
|
||||
};
|
||||
|
||||
// check cap sigs & transform valid to unsigned to be plugged into procs
|
||||
let pk = signature::UnparsedPublicKey::new(
|
||||
&signature::ED25519,
|
||||
keypair.public_key(),
|
||||
);
|
||||
let mut valid_capabilities: HashSet<t::Capability> = HashSet::new();
|
||||
for signed_cap in initial_capabilities {
|
||||
let cap = t::Capability {
|
||||
issuer: signed_cap.issuer,
|
||||
params: signed_cap.params,
|
||||
};
|
||||
match pk.verify(&bincode::serialize(&cap).unwrap(), &signed_cap.signature) {
|
||||
Ok(_) => {},
|
||||
Err(e) => {
|
||||
println!("kernel: StartProcess no cap: {}", e);
|
||||
continue;
|
||||
},
|
||||
}
|
||||
valid_capabilities.insert(cap);
|
||||
}
|
||||
|
||||
start_process(
|
||||
our_name,
|
||||
keypair.clone(),
|
||||
@ -1098,10 +1169,9 @@ async fn handle_kernel_request(
|
||||
source: km.source,
|
||||
process_id: name.map(|n| t::ProcessId::Name(n)),
|
||||
persisted: t::PersistedProcess {
|
||||
identifier,
|
||||
full_path,
|
||||
wasm_bytes_handle,
|
||||
on_panic,
|
||||
capabilities: initial_capabilities,
|
||||
capabilities: valid_capabilities,
|
||||
},
|
||||
reboot: false,
|
||||
},
|
||||
@ -1214,9 +1284,11 @@ async fn handle_kernel_request(
|
||||
}
|
||||
}
|
||||
|
||||
/// currently, the kernel only receives 1 class of Response: set-state
|
||||
/// from the filesystem module. it uses this to start a process.
|
||||
// TODO: clean up args
|
||||
/// currently, the kernel only receives 2 classes of responses, file-read and set-state
|
||||
/// responses from the filesystem module. it uses these to get wasm bytes of a process and
|
||||
/// start that process.
|
||||
// TODO: RebootProcess relies on this. If we can get rid of that, we can delete below
|
||||
// `let meta: StartProcessMetadata ... `
|
||||
async fn handle_kernel_response(
|
||||
our_name: String,
|
||||
keypair: Arc<signature::Ed25519KeyPair>,
|
||||
@ -1251,6 +1323,47 @@ async fn handle_kernel_response(
|
||||
// process map upon receiving confirmation that it's been persisted
|
||||
return;
|
||||
};
|
||||
|
||||
let meta: StartProcessMetadata = match serde_json::from_str(&metadata) {
|
||||
Err(_) => {
|
||||
let _ = send_to_terminal
|
||||
.send(t::Printout {
|
||||
verbosity: 1,
|
||||
content: "kernel: got weird metadata from filesystem".into(),
|
||||
})
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
Ok(m) => m,
|
||||
};
|
||||
|
||||
let Some(ref payload) = km.payload else {
|
||||
send_to_terminal
|
||||
.send(t::Printout {
|
||||
verbosity: 0,
|
||||
content: "kernel: process startup requires bytes".into(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
return;
|
||||
};
|
||||
|
||||
start_process(
|
||||
our_name,
|
||||
keypair.clone(),
|
||||
home_directory_path,
|
||||
km.id,
|
||||
&payload.bytes,
|
||||
send_to_loop,
|
||||
send_to_terminal,
|
||||
senders,
|
||||
process_handles,
|
||||
process_map,
|
||||
engine,
|
||||
caps_oracle,
|
||||
meta,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
async fn start_process(
|
||||
@ -1349,8 +1462,7 @@ async fn start_process(
|
||||
process_map.insert(
|
||||
process_id,
|
||||
t::PersistedProcess {
|
||||
identifier: process_metadata.persisted.identifier,
|
||||
full_path: process_metadata.persisted.full_path,
|
||||
wasm_bytes_handle: process_metadata.persisted.wasm_bytes_handle,
|
||||
on_panic: process_metadata.persisted.on_panic,
|
||||
capabilities: process_metadata.persisted.capabilities,
|
||||
},
|
||||
|
@ -82,7 +82,7 @@ pub struct Capability {
|
||||
pub params: String, // JSON-string
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
|
||||
pub struct SignedCapability {
|
||||
pub issuer: Address,
|
||||
pub params: String, // JSON-string
|
||||
@ -116,7 +116,7 @@ pub enum KernelCommand {
|
||||
name: Option<String>,
|
||||
wasm_bytes_handle: u128,
|
||||
on_panic: OnPanic,
|
||||
initial_capabilities: HashSet<Capability>,
|
||||
initial_capabilities: HashSet<SignedCapability>,
|
||||
},
|
||||
KillProcess(ProcessId), // this is extrajudicial killing: we might lose messages!
|
||||
RebootProcess {
|
||||
@ -172,6 +172,10 @@ pub enum VfsRequest {
|
||||
identifier: String,
|
||||
hash: u128,
|
||||
},
|
||||
GetHash {
|
||||
identifier: String,
|
||||
full_path: String,
|
||||
},
|
||||
GetEntry {
|
||||
identifier: String,
|
||||
full_path: String,
|
||||
@ -193,7 +197,7 @@ 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
|
||||
// ... // symlinks?
|
||||
ZipArchive,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
@ -234,6 +238,11 @@ pub enum VfsResponse {
|
||||
hash: u128,
|
||||
full_path: Option<String>,
|
||||
},
|
||||
GetHash {
|
||||
identifier: String,
|
||||
full_path: String,
|
||||
hash: u128,
|
||||
},
|
||||
GetEntry {
|
||||
identifier: String,
|
||||
full_path: String,
|
||||
|
23
src/types.rs
23
src/types.rs
@ -135,7 +135,7 @@ pub struct Capability {
|
||||
pub params: String, // JSON-string
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
|
||||
pub struct SignedCapability {
|
||||
pub issuer: Address,
|
||||
pub params: String, // JSON-string
|
||||
@ -250,10 +250,9 @@ pub enum DebugCommand {
|
||||
pub enum KernelCommand {
|
||||
StartProcess {
|
||||
name: Option<String>,
|
||||
identifier: String,
|
||||
full_path: String,
|
||||
wasm_bytes_handle: u128,
|
||||
on_panic: OnPanic,
|
||||
initial_capabilities: HashSet<Capability>,
|
||||
initial_capabilities: HashSet<SignedCapability>,
|
||||
},
|
||||
KillProcess(ProcessId), // this is extrajudicial killing: we might lose messages!
|
||||
RebootProcess {
|
||||
@ -301,8 +300,9 @@ pub type ProcessMap = HashMap<ProcessId, PersistedProcess>;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct PersistedProcess {
|
||||
pub identifier: String,
|
||||
pub full_path: String,
|
||||
pub wasm_bytes_handle: u128,
|
||||
// pub identifier: String,
|
||||
// pub full_path: String,
|
||||
pub on_panic: OnPanic,
|
||||
pub capabilities: HashSet<Capability>,
|
||||
}
|
||||
@ -572,6 +572,10 @@ pub enum VfsRequest {
|
||||
identifier: String,
|
||||
hash: u128,
|
||||
},
|
||||
GetHash {
|
||||
identifier: String,
|
||||
full_path: String,
|
||||
},
|
||||
GetEntry {
|
||||
identifier: String,
|
||||
full_path: String,
|
||||
@ -593,7 +597,7 @@ 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
|
||||
// ... // symlinks?
|
||||
ZipArchive,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
@ -634,6 +638,11 @@ pub enum VfsResponse {
|
||||
hash: u128,
|
||||
full_path: Option<String>,
|
||||
},
|
||||
GetHash {
|
||||
identifier: String,
|
||||
full_path: String,
|
||||
hash: u128,
|
||||
},
|
||||
GetEntry {
|
||||
identifier: String,
|
||||
full_path: String,
|
||||
|
183
src/vfs.rs
183
src/vfs.rs
@ -1,5 +1,6 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::io::prelude::*;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
@ -345,6 +346,7 @@ pub async fn vfs(
|
||||
VfsRequest::WriteOffset { identifier, .. } => (identifier.clone(), false),
|
||||
VfsRequest::SetSize { identifier, .. } => (identifier.clone(), false),
|
||||
VfsRequest::GetPath { identifier, .. } => (identifier.clone(), false),
|
||||
VfsRequest::GetHash { identifier, .. } => (identifier.clone(), false),
|
||||
VfsRequest::GetEntry { identifier, .. } => (identifier.clone(), false),
|
||||
VfsRequest::GetFileChunk { identifier, .. } => (identifier.clone(), false),
|
||||
VfsRequest::GetEntryLength { identifier, .. } => (identifier.clone(), false),
|
||||
@ -501,6 +503,7 @@ async fn handle_request(
|
||||
}
|
||||
}
|
||||
VfsRequest::GetPath { identifier, .. }
|
||||
| VfsRequest::GetHash { identifier, .. }
|
||||
| VfsRequest::GetEntry { identifier, .. }
|
||||
| VfsRequest::GetFileChunk { identifier, .. }
|
||||
| VfsRequest::GetEntryLength { identifier, .. } => {
|
||||
@ -818,6 +821,168 @@ async fn match_request(
|
||||
vfs.path_to_key.insert(parent_path, parent_key);
|
||||
vfs.path_to_key.insert(full_path.clone(), key.clone());
|
||||
}
|
||||
AddEntryType::ZipArchive => {
|
||||
let Some(payload) = payload else {
|
||||
panic!("");
|
||||
};
|
||||
let Some(mime) = payload.mime else {
|
||||
panic!("");
|
||||
};
|
||||
if "application/zip" != mime {
|
||||
panic!("");
|
||||
}
|
||||
let file = std::io::Cursor::new(&payload.bytes);
|
||||
let mut zip = match zip::ZipArchive::new(file) {
|
||||
Ok(f) => f,
|
||||
Err(e) => panic!("vfs: zip error: {:?}", e),
|
||||
};
|
||||
|
||||
// loop through items in archive; recursively add to root
|
||||
for i in 0..zip.len() {
|
||||
// must destruct the zip file created in zip.by_index()
|
||||
// Before any `.await`s are called since ZipFile is not
|
||||
// Send and so does not play nicely with await
|
||||
let (is_file, is_dir, full_path, file_contents) = {
|
||||
let mut file = zip.by_index(i).unwrap();
|
||||
let is_file = file.is_file();
|
||||
let is_dir = file.is_dir();
|
||||
let full_path = format!("/{}", file.name());
|
||||
let mut file_contents = Vec::new();
|
||||
if is_file {
|
||||
file.read_to_end(&mut file_contents).unwrap();
|
||||
};
|
||||
(is_file, is_dir, full_path, file_contents)
|
||||
};
|
||||
if is_file {
|
||||
let _ = send_to_loop
|
||||
.send(KernelMessage {
|
||||
id,
|
||||
source: Address {
|
||||
node: our_node.clone(),
|
||||
process: ProcessId::Name("vfs".into()),
|
||||
},
|
||||
target: Address {
|
||||
node: our_node.clone(),
|
||||
process: ProcessId::Name("filesystem".into()),
|
||||
},
|
||||
rsvp: None,
|
||||
message: Message::Request(Request {
|
||||
inherit: true,
|
||||
expects_response: Some(5), // TODO evaluate
|
||||
ipc: Some(serde_json::to_string(&FsAction::Write).unwrap()),
|
||||
metadata: None,
|
||||
}),
|
||||
payload: Some(Payload {
|
||||
mime: None,
|
||||
bytes: file_contents,
|
||||
}),
|
||||
signed_capabilities: None,
|
||||
})
|
||||
.await;
|
||||
let write_response = recv_response.recv().await.unwrap();
|
||||
let KernelMessage { message, .. } = write_response;
|
||||
let Message::Response((Response { ipc, metadata: _ }, None)) = message else {
|
||||
panic!("")
|
||||
};
|
||||
let Some(ipc) = ipc else {
|
||||
panic!("");
|
||||
};
|
||||
let FsResponse::Write(hash) = serde_json::from_str(&ipc).unwrap() else {
|
||||
panic!("");
|
||||
};
|
||||
|
||||
let (name, parent_path) = make_file_name(&full_path);
|
||||
let mut vfs = vfs.lock().await;
|
||||
let Some(parent_key) = vfs.path_to_key.remove(&parent_path) else {
|
||||
panic!("");
|
||||
};
|
||||
let key = Key::File { id: hash };
|
||||
vfs.key_to_entry.insert(
|
||||
key.clone(),
|
||||
Entry {
|
||||
name,
|
||||
full_path: full_path.clone(),
|
||||
entry_type: EntryType::File {
|
||||
parent: parent_key.clone(),
|
||||
},
|
||||
},
|
||||
);
|
||||
vfs.path_to_key.insert(parent_path, parent_key);
|
||||
vfs.path_to_key.insert(full_path.clone(), key.clone());
|
||||
} else if is_dir {
|
||||
panic!("vfs: zip dir not yet implemented");
|
||||
} else {
|
||||
panic!("vfs: zip with non-file non-dir");
|
||||
};
|
||||
// if file.is_file() {
|
||||
// println!("Filename: {}", file.name());
|
||||
// let mut out = Vec::new();
|
||||
// file.read_to_end(&mut out).unwrap();
|
||||
// let full_path = format!("/{}", file.name());
|
||||
|
||||
// // TODO: factor out
|
||||
// let _ = send_to_loop
|
||||
// .send(KernelMessage {
|
||||
// id,
|
||||
// source: Address {
|
||||
// node: our_node.clone(),
|
||||
// process: ProcessId::Name("vfs".into()),
|
||||
// },
|
||||
// target: Address {
|
||||
// node: our_node.clone(),
|
||||
// process: ProcessId::Name("filesystem".into()),
|
||||
// },
|
||||
// rsvp: None,
|
||||
// message: Message::Request(Request {
|
||||
// inherit: true,
|
||||
// expects_response: Some(5), // TODO evaluate
|
||||
// ipc: Some(serde_json::to_string(&FsAction::Write).unwrap()),
|
||||
// metadata: None,
|
||||
// }),
|
||||
// payload: Some(Payload {
|
||||
// mime: None,
|
||||
// bytes: out,
|
||||
// }),
|
||||
// signed_capabilities: None,
|
||||
// })
|
||||
// .await;
|
||||
// let write_response = recv_response.recv().await.unwrap();
|
||||
// let KernelMessage { message, .. } = write_response;
|
||||
// let Message::Response((Response { ipc, metadata: _ }, None)) = message else {
|
||||
// panic!("")
|
||||
// };
|
||||
// let Some(ipc) = ipc else {
|
||||
// panic!("");
|
||||
// };
|
||||
// let FsResponse::Write(hash) = serde_json::from_str(&ipc).unwrap() else {
|
||||
// panic!("");
|
||||
// };
|
||||
|
||||
// let (name, parent_path) = make_file_name(&full_path);
|
||||
// let mut vfs = vfs.lock().await;
|
||||
// let Some(parent_key) = vfs.path_to_key.remove(&parent_path) else {
|
||||
// panic!("");
|
||||
// };
|
||||
// let key = Key::File { id: hash };
|
||||
// vfs.key_to_entry.insert(
|
||||
// key.clone(),
|
||||
// Entry {
|
||||
// name,
|
||||
// full_path: full_path.clone(),
|
||||
// entry_type: EntryType::File {
|
||||
// parent: parent_key.clone(),
|
||||
// },
|
||||
// },
|
||||
// );
|
||||
// vfs.path_to_key.insert(parent_path, parent_key);
|
||||
// vfs.path_to_key.insert(full_path.clone(), key.clone());
|
||||
// } else if file.is_dir() {
|
||||
// panic!("todo");
|
||||
// } else {
|
||||
// panic!("wat");
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
send_to_persist.send(true).await.unwrap();
|
||||
(
|
||||
@ -1140,6 +1305,24 @@ async fn match_request(
|
||||
);
|
||||
(ipc, None)
|
||||
}
|
||||
VfsRequest::GetHash { identifier, full_path } => {
|
||||
let mut vfs = vfs.lock().await;
|
||||
let Some(key) = vfs.path_to_key.get(&full_path) else {
|
||||
panic!("todo");
|
||||
};
|
||||
let Key::File { id: hash } = key else {
|
||||
panic!("todo");
|
||||
};
|
||||
let ipc = Some(
|
||||
serde_json::to_string(&VfsResponse::GetHash {
|
||||
identifier,
|
||||
full_path,
|
||||
hash: hash.clone(),
|
||||
})
|
||||
.unwrap(),
|
||||
);
|
||||
(ipc, None)
|
||||
}
|
||||
VfsRequest::GetEntry {
|
||||
identifier,
|
||||
ref full_path,
|
||||
|
@ -125,8 +125,7 @@ world uq-process {
|
||||
|
||||
import set-on-panic: func(on-panic: on-panic)
|
||||
|
||||
// what should bytes_uri be?? need vfs?
|
||||
import spawn: func(id: process-id, identifier: string, full-path: string, on-panic: on-panic, capabilities: capabilities) ->
|
||||
import spawn: func(id: process-id, %package: string, full-path: string, on-panic: on-panic, capabilities: capabilities) ->
|
||||
option<process-id>
|
||||
|
||||
// capabilities management
|
||||
|
Loading…
Reference in New Issue
Block a user