Merge pull request #46 from uqbar-dao/dr/process-std-lib

Build standard library for processes
This commit is contained in:
dr-frmr 2023-11-06 23:07:58 -05:00 committed by GitHub
commit fd1cc73895
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
79 changed files with 4824 additions and 7432 deletions

View File

@ -1,3 +0,0 @@
# This file is automatically generated by cargo-component.
# It is not intended for manual editing.
version = 1

479
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -61,8 +61,9 @@ thiserror = "1.0.43"
tokio = { version = "1.28", features = ["fs", "macros", "rt-multi-thread", "sync"] }
tokio-tungstenite = "*"
url = "*"
uqbar_process_lib = { path = "process_lib" }
uuid = { version = "1.1.2", features = ["serde", "v4"] }
warp = "0.3.5"
wasmtime = "12.0.1"
wasmtime-wasi = "12.0.1"
wasmtime = "14.0.4"
wasmtime-wasi = "14.0.4"
zip = "0.6"

View File

@ -40,18 +40,11 @@ fn build_app(target_path: &str, name: &str, parent_pkg_path: Option<&str>) {
// if and only if module's wit is outdated, re-set-up build environment
if file_outdated(
format!("{}/wit/uqbar.wit", pwd.display()),
format!("{}/wit/uqbar.wit", target_path),
format!("{}/target.wasm", pwd.display()),
format!("{}/target/bindings/{}/target.wasm", target_path, name),
)
.unwrap_or(true)
{
println!("cargo:warning=wit outdated, rebuilding");
run_command(Command::new("cp").args(&[
"-r",
&format!("{}/wit", pwd.display()),
&format!("{}/wit", target_path),
]))
.unwrap();
// create target/bindings directory
fs::create_dir_all(&format!("{}/target/bindings/{}", target_path, name,)).unwrap();
// copy newly-made target.wasm into target/bindings
@ -116,7 +109,7 @@ fn build_app(target_path: &str, name: &str, parent_pkg_path: Option<&str>) {
"embed",
"wit",
"--world",
"uq-process",
"process",
&format!(
"{}/target/wasm32-wasi/release/{}_adapted.wasm",
target_path, name

View File

@ -1,3 +0,0 @@
# This file is automatically generated by cargo-component.
# It is not intended for manual editing.
version = 1

View File

@ -14,12 +14,12 @@ version = "0.1.0"
dependencies = [
"anyhow",
"bincode",
"cargo-component-bindings",
"rand",
"serde",
"serde_json",
"sha2",
"wit-bindgen 0.11.0",
"uqbar_process_lib",
"wit-bindgen",
]
[[package]]
@ -46,29 +46,6 @@ dependencies = [
"generic-array",
]
[[package]]
name = "cargo-component-bindings"
version = "0.3.0"
source = "git+https://github.com/bytecodealliance/cargo-component#5cddf6df7fd5ab5aa9bfd66f4cf2e2f6cc7d72f9"
dependencies = [
"cargo-component-macro",
"wit-bindgen 0.13.0",
]
[[package]]
name = "cargo-component-macro"
version = "0.3.0"
source = "git+https://github.com/bytecodealliance/cargo-component#5cddf6df7fd5ab5aa9bfd66f4cf2e2f6cc7d72f9"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
"wit-bindgen-core",
"wit-bindgen-rust",
"wit-component",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
@ -77,9 +54,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "cpufeatures"
version = "0.2.10"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fbc60abd742b35f2492f808e1abbb83d45f72db402e14c55057edc9c7b1e9e4"
checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0"
dependencies = [
"libc",
]
@ -154,9 +131,9 @@ checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005"
[[package]]
name = "indexmap"
version = "2.0.2"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897"
checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f"
dependencies = [
"equivalent",
"hashbrown",
@ -177,9 +154,9 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67"
[[package]]
name = "libc"
version = "0.2.149"
version = "0.2.150"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b"
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
[[package]]
name = "log"
@ -255,18 +232,18 @@ checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090"
[[package]]
name = "serde"
version = "1.0.189"
version = "1.0.191"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537"
checksum = "a834c4821019838224821468552240d4d95d14e751986442c816572d39a080c9"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.189"
version = "1.0.191"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5"
checksum = "46fa52d5646bce91b680189fe5b1c049d2ea38dabb4e2e7c8d00ca12cfbfbcfd"
dependencies = [
"proc-macro2",
"quote",
@ -275,9 +252,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.107"
version = "1.0.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65"
checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b"
dependencies = [
"itoa",
"ryu",
@ -312,9 +289,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.38"
version = "2.0.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b"
checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a"
dependencies = [
"proc-macro2",
"quote",
@ -345,6 +322,17 @@ 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",
"rand",
"serde",
"wit-bindgen",
]
[[package]]
name = "version_check"
version = "0.9.4"
@ -359,18 +347,18 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-encoder"
version = "0.35.0"
version = "0.36.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ca90ba1b5b0a70d3d49473c5579951f3bddc78d47b59256d2f9d4922b150aca"
checksum = "822b645bf4f2446b949776ffca47e2af60b167209ffb70814ef8779d299cd421"
dependencies = [
"leb128",
]
[[package]]
name = "wasm-metadata"
version = "0.10.9"
version = "0.10.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14abc161bfda5b519aa229758b68f2a52b45a12b993808665c857d1a9a00223c"
checksum = "2167ce53b2faa16a92c6cafd4942cff16c9a4fa0c5a5a0a41131ee4e49fc055f"
dependencies = [
"anyhow",
"indexmap",
@ -384,9 +372,9 @@ dependencies = [
[[package]]
name = "wasmparser"
version = "0.115.0"
version = "0.116.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e06c0641a4add879ba71ccb3a1e4278fd546f76f1eafb21d8f7b07733b547cd5"
checksum = "a58e28b80dd8340cb07b8242ae654756161f6fc8d0038123d679b7b99964fa50"
dependencies = [
"indexmap",
"semver",
@ -394,18 +382,8 @@ dependencies = [
[[package]]
name = "wit-bindgen"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8a3e8e965dc50e6eb4410d9a11720719fadc6a1713803ea5f3be390b81c8279"
dependencies = [
"bitflags",
]
[[package]]
name = "wit-bindgen"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7d92ce0ca6b6074059413a9581a637550c3a740581c854f9847ec293c8aed71"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"bitflags",
"wit-bindgen-rust-macro",
@ -413,9 +391,8 @@ dependencies = [
[[package]]
name = "wit-bindgen-core"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "565b945ae074886071eccf9cdaf8ccd7b959c2b0d624095bea5fe62003e8b3e0"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"anyhow",
"wit-component",
@ -424,9 +401,8 @@ dependencies = [
[[package]]
name = "wit-bindgen-rust"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5695ff4e41873ed9ce56d2787e6b5772bdad9e70e2c1d2d160621d1762257f4f"
version = "0.13.2"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"anyhow",
"heck",
@ -437,9 +413,8 @@ dependencies = [
[[package]]
name = "wit-bindgen-rust-macro"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a91835ea4231da1fe7971679d505ba14be7826e192b6357f08465866ef482e08"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"anyhow",
"proc-macro2",
@ -452,9 +427,9 @@ dependencies = [
[[package]]
name = "wit-component"
version = "0.16.0"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e87488b57a08e2cbbd076b325acbe7f8666965af174d69d5929cd373bd54547f"
checksum = "480cc1a078b305c1b8510f7c455c76cbd008ee49935f3a6c5fd5e937d8d95b1e"
dependencies = [
"anyhow",
"bitflags",
@ -471,9 +446,9 @@ dependencies = [
[[package]]
name = "wit-parser"
version = "0.12.1"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6ace9943d89bbf3dbbc71b966da0e7302057b311f36a4ac3d65ddfef17b52cf"
checksum = "43771ee863a16ec4ecf9da0fc65c3bbd4a1235c8e3da5f094b562894843dfa76"
dependencies = [
"anyhow",
"id-arena",

View File

@ -13,20 +13,15 @@ lto = true
[dependencies]
anyhow = "1.0"
bincode = "1.3.3"
cargo-component-bindings = { git = "https://github.com/bytecodealliance/cargo-component" }
rand = "0.8.5"
rand = "0.8"
serde = {version = "1.0", features = ["derive"] }
serde_json = "1.0"
sha2 = "0.10.8"
wit-bindgen = { version = "0.11.0", default_features = false }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "5390bab780733f1660d14c254ec985df2816bf1d" }
uqbar_process_lib = { path = "../../../process_lib" }
[lib]
crate-type = ["cdylib"]
[package.metadata.component]
package = "component:uq-process"
[package.metadata.component.target]
path = "wit"
[package.metadata.component.dependencies]
package = "uqbar:process"

View File

@ -1 +0,0 @@
../../../../src/kernel_types.rs

View File

@ -1,20 +1,20 @@
cargo_component_bindings::generate!();
use bindings::{
component::uq_process::types::*, get_capability, get_payload, print_to_terminal, receive,
send_request, send_response, Guest,
};
use serde::{Deserialize, Serialize};
use sha2::Digest;
use std::collections::{HashMap, HashSet};
use uqbar_process_lib::kernel_types as kt;
use uqbar_process_lib::uqbar::process::standard as wit;
use uqbar_process_lib::{
get_capability, get_payload, get_typed_state, grant_messaging, println, receive, set_state,
Address, Message, NodeId, PackageId, ProcessId, Request, Response,
};
#[allow(dead_code)]
mod kernel_types;
use kernel_types as kt;
use kernel_types::{PackageManifestEntry, PackageMetadata, PackageVersion};
#[allow(dead_code)]
mod process_lib;
use process_lib::PackageId;
wit_bindgen::generate!({
path: "../../../wit",
world: "process",
exports: {
world: Component,
},
});
#[allow(dead_code)]
mod ft_worker_lib;
@ -66,7 +66,7 @@ struct PackageListing {
pub publisher: NodeId,
pub description: Option<String>,
pub website: Option<String>,
pub version: PackageVersion,
pub version: kt::PackageVersion,
pub version_hash: String, // sha256 hash of the package zip or whatever
}
@ -158,30 +158,26 @@ pub enum InstallResponse {
Failure,
}
//
// app store init()
//
impl Guest for Component {
fn init(our: Address) {
assert_eq!(our.process, "main:app_store:uqbar");
fn init(our: String) {
let our = Address::from_str(&our).unwrap();
// begin by granting messaging capabilities to http_server and terminal,
// so that they can send us requests.
process_lib::grant_messaging(
grant_messaging(
&our,
&Vec::from([
ProcessId::from_str("http_server:sys:uqbar").unwrap(),
ProcessId::from_str("terminal:terminal:uqbar").unwrap(),
]),
);
print_to_terminal(0, &format!("app_store main proc: start"));
println!("{}: start", our.process);
// load in our saved state or initalize a new one if none exists
let mut state = process_lib::get_state::<State>().unwrap_or(State {
packages: HashMap::new(),
requested_packages: HashSet::new(),
});
let mut state =
get_typed_state(|bytes| Ok(bincode::deserialize(bytes)?)).unwrap_or(State {
packages: HashMap::new(),
requested_packages: HashSet::new(),
});
// active the main messaging loop: handle requests and responses
loop {
@ -189,170 +185,131 @@ impl Guest for Component {
Ok((source, message)) => (source, message),
Err((error, _context)) => {
// TODO handle net errors more usefully based on their context
print_to_terminal(0, &format!("net error: {:?}", error.kind));
println!("net error: {:?}", error.kind);
continue;
}
};
match message {
Message::Request(req) => {
match &serde_json::from_slice::<Req>(&req.ipc) {
Ok(Req::LocalRequest(local_request)) => {
match handle_local_request(&our, &source, local_request, &mut state) {
Ok(None) => continue,
Ok(Some(resp)) => {
if req.expects_response.is_some() {
send_response(
&Response {
inherit: false,
ipc: serde_json::to_vec(&resp).unwrap(),
metadata: None,
},
None,
);
}
}
Err(err) => {
print_to_terminal(
0,
&format!("app-store: local request error: {:?}", err),
);
}
}
}
Ok(Req::RemoteRequest(remote_request)) => {
match handle_remote_request(&our, &source, remote_request, &mut state) {
Ok(None) => continue,
Ok(Some(resp)) => {
if req.expects_response.is_some() {
send_response(
&Response {
inherit: false,
ipc: serde_json::to_vec(&resp).unwrap(),
metadata: None,
},
None,
);
}
}
Err(err) => {
print_to_terminal(
0,
&format!("app-store: remote request error: {:?}", err),
);
}
}
}
Ok(Req::FTWorkerResult(FTWorkerResult::ReceiveSuccess(name))) => {
// do with file what you'd like here
print_to_terminal(
0,
&format!("file_transfer: successfully received {:?}", name,),
);
// remove leading / and .zip from file name to get package ID
let package_id =
match PackageId::from_str(name[1..].trim_end_matches(".zip")) {
Ok(package_id) => package_id,
Err(_) => {
print_to_terminal(
0,
&format!("app store: bad package filename: {}", name),
);
continue;
}
};
if state.requested_packages.remove(&package_id) {
// auto-take zip from payload and request ourself with New
let _ = send_request(
&our,
&Request {
inherit: true, // will inherit payload!
expects_response: None,
ipc: serde_json::to_vec(&Req::LocalRequest(
LocalRequest::NewPackage {
package: package_id,
mirror: true,
},
))
.unwrap(),
metadata: None,
},
None,
None,
);
}
}
Ok(Req::FTWorkerCommand(_)) => {
spawn_receive_transfer(&our, &req.ipc);
}
e => {
print_to_terminal(
0,
&format!("app store bad request: {:?}, error {:?}", req.ipc, e),
);
continue;
}
}
}
Message::Response((response, context)) => {
match &serde_json::from_slice::<Resp>(&response.ipc) {
Ok(Resp::RemoteResponse(remote_response)) => match remote_response {
RemoteResponse::DownloadApproved => {
print_to_terminal(
0,
"app store: download approved, should be starting",
);
}
RemoteResponse::DownloadDenied => {
print_to_terminal(
0,
"app store: could not download package from that node!",
);
}
},
Ok(Resp::FTWorkerResult(ft_worker_result)) => {
let Ok(context) = serde_json::from_slice::<FileTransferContext>(&context.unwrap_or_default()) else {
print_to_terminal(0, "file_transfer: got weird local request");
continue;
};
match ft_worker_result {
FTWorkerResult::SendSuccess => {
print_to_terminal(
0,
&format!(
"file_transfer: successfully shared app {} in {:.4}s",
context.file_name,
std::time::SystemTime::now()
.duration_since(context.start_time)
.unwrap()
.as_secs_f64(),
),
);
}
e => {
print_to_terminal(
0,
&format!("app store file transfer: error {:?}", e),
);
}
}
}
e => {
print_to_terminal(
0,
&format!(
"app store bad response: {:?}, error {:?}",
response.ipc, e
),
);
continue;
}
}
}
match handle_message(&our, &source, &mut state, &message) {
Ok(()) => {}
Err(e) => println!("app-store: error handling message: {:?}", e),
}
}
}
}
fn handle_message(
our: &Address,
source: &Address,
mut state: &mut State,
message: &Message,
) -> anyhow::Result<()> {
match message {
Message::Request(req) => {
match &serde_json::from_slice::<Req>(&req.ipc) {
Ok(Req::LocalRequest(local_request)) => {
match handle_local_request(&our, &source, local_request, &mut state) {
Ok(None) => return Ok(()),
Ok(Some(resp)) => {
if req.expects_response.is_some() {
Response::new()
.ipc_bytes(serde_json::to_vec(&resp)?)
.send()?;
}
}
Err(err) => {
println!("app-store: local request error: {:?}", err);
}
}
}
Ok(Req::RemoteRequest(remote_request)) => {
match handle_remote_request(&our, &source, remote_request, &mut state) {
Ok(None) => return Ok(()),
Ok(Some(resp)) => {
if req.expects_response.is_some() {
Response::new()
.ipc_bytes(serde_json::to_vec(&resp)?)
.send()?;
}
}
Err(err) => {
println!("app-store: remote request error: {:?}", err);
}
}
}
Ok(Req::FTWorkerResult(FTWorkerResult::ReceiveSuccess(name))) => {
// do with file what you'd like here
println!("file_transfer: successfully received {:?}", name);
// remove leading / and .zip from file name to get package ID
let package_id = match PackageId::from_str(name[1..].trim_end_matches(".zip")) {
Ok(package_id) => package_id,
Err(e) => {
println!("app store: bad package filename: {}", name);
return Err(anyhow::anyhow!(e));
}
};
if state.requested_packages.remove(&package_id) {
// auto-take zip from payload and request ourself with New
Request::new()
.target(our.clone())?
.inherit(true)
.ipc_bytes(serde_json::to_vec(&Req::LocalRequest(
LocalRequest::NewPackage {
package: package_id,
mirror: true,
},
))?)
.send()?;
}
}
Ok(Req::FTWorkerCommand(_)) => {
spawn_receive_transfer(&our, &req.ipc);
}
e => {
return Err(anyhow::anyhow!(
"app store bad request: {:?}, error {:?}",
req.ipc,
e
))
}
}
}
Message::Response((response, context)) => {
match &serde_json::from_slice::<Resp>(&response.ipc) {
Ok(Resp::RemoteResponse(remote_response)) => match remote_response {
RemoteResponse::DownloadApproved => {
println!("app store: download approved, should be starting");
}
RemoteResponse::DownloadDenied => {
println!("app store: could not download package from that node!");
}
},
Ok(Resp::FTWorkerResult(ft_worker_result)) => {
let Ok(context) =
serde_json::from_slice::<FileTransferContext>(&context.as_ref().unwrap())
else {
return Err(anyhow::anyhow!("file_transfer: got weird local request"));
};
match ft_worker_result {
FTWorkerResult::SendSuccess => {
println!(
"file_transfer: successfully shared app {} in {:.4}s",
context.file_name,
std::time::SystemTime::now()
.duration_since(context.start_time)
.unwrap()
.as_secs_f64(),
);
}
e => return Err(anyhow::anyhow!("file_transfer: {:?}", e)),
}
}
_ => return Err(anyhow::anyhow!("bad response from file transfer worker")),
}
}
}
Ok(())
}
fn handle_local_request(
our: &Address,
source: &Address,
@ -364,81 +321,67 @@ fn handle_local_request(
}
match request {
LocalRequest::NewPackage { package, mirror } => {
let Some(mut payload) = get_payload() else {
return Err(anyhow::anyhow!("no payload"));
};
let vfs_address = Address {
node: our.node.clone(),
process: ProcessId::from_str("vfs:sys:uqbar")?,
};
Request::new()
.target(vfs_address.clone())?
.ipc_bytes(serde_json::to_vec(&kt::VfsRequest {
drive: package.to_string(),
action: kt::VfsAction::New,
})?)
.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);
let version_hash = format!("{:x}", hasher.finalize());
let _ = process_lib::send_and_await_response(
&vfs_address,
false,
serde_json::to_vec(&kt::VfsRequest {
drive: package.to_string(),
action: kt::VfsAction::New,
})?,
None,
None,
5,
)?;
// add zip bytes
payload.mime = Some("application/zip".to_string());
let _ = process_lib::send_and_await_response(
&vfs_address,
true,
serde_json::to_vec(&kt::VfsRequest {
Request::new()
.target(vfs_address.clone())?
.ipc_bytes(serde_json::to_vec(&kt::VfsRequest {
drive: package.to_string(),
action: kt::VfsAction::Add {
full_path: package.to_string(),
entry_type: kt::AddEntryType::ZipArchive,
},
})?,
None,
Some(&payload),
5,
)?;
})?)
.payload(payload.clone())
.send_and_await_response(5)??;
// save the zip file itself in VFS for sharing with other nodes
// call it <package>.zip
let _ = process_lib::send_and_await_response(
&vfs_address,
true,
serde_json::to_vec(&kt::VfsRequest {
Request::new()
.target(vfs_address.clone())?
.inherit(true)
.ipc_bytes(serde_json::to_vec(&kt::VfsRequest {
drive: package.to_string(),
action: kt::VfsAction::Add {
full_path: format!("/{}.zip", package.to_string()),
entry_type: kt::AddEntryType::NewFile,
},
})?,
None,
Some(&payload),
5,
)?;
let _ = process_lib::send_and_await_response(
&vfs_address,
false,
serde_json::to_vec(&kt::VfsRequest {
})?)
.payload(payload)
.send_and_await_response(5)??;
Request::new()
.target(vfs_address.clone())?
.ipc_bytes(serde_json::to_vec(&kt::VfsRequest {
drive: package.to_string(),
action: kt::VfsAction::GetEntry("/metadata.json".into()),
})?,
None,
None,
5,
)?;
})?)
.send_and_await_response(5)??;
let Some(payload) = get_payload() else {
return Err(anyhow::anyhow!("no metadata payload"));
};
let metadata = String::from_utf8(payload.bytes)?;
let metadata = serde_json::from_str::<PackageMetadata>(&metadata)?;
let metadata = serde_json::from_str::<kt::PackageMetadata>(&metadata)?;
let listing_data = PackageListing {
name: metadata.package,
@ -455,30 +398,27 @@ fn handle_local_request(
auto_update: true,
};
state.packages.insert(package.clone(), package_state);
process_lib::set_state::<State>(&state);
crate::set_state(&bincode::serialize(state)?);
Ok(Some(Resp::NewPackageResponse(NewPackageResponse::Success)))
}
LocalRequest::Download {
package,
install_from,
} => Ok(Some(Resp::DownloadResponse(
match process_lib::send_and_await_response(
&Address {
node: install_from.clone(),
process: our.process.clone(),
},
true,
serde_json::to_vec(&RemoteRequest::Download(package.clone()))?,
None,
None,
5,
) {
Ok((_source, Message::Response((resp, _context)))) => {
match Request::new()
.target(Address::new(&install_from, our.process.clone())?)?
.inherit(true)
.ipc_bytes(serde_json::to_vec(&RemoteRequest::Download(
package.clone(),
))?)
.send_and_await_response(5)
{
Ok(Ok((_source, Message::Response((resp, _context))))) => {
let resp = serde_json::from_slice::<Resp>(&resp.ipc)?;
match resp {
Resp::RemoteResponse(RemoteResponse::DownloadApproved) => {
state.requested_packages.insert(package.clone());
process_lib::set_state::<State>(&state);
crate::set_state(&bincode::serialize(&state)?);
DownloadResponse::Started
}
_ => DownloadResponse::Failure,
@ -492,22 +432,18 @@ fn handle_local_request(
node: our.node.clone(),
process: ProcessId::from_str("vfs:sys:uqbar")?,
};
let _ = process_lib::send_and_await_response(
&vfs_address,
false,
serde_json::to_vec(&kt::VfsRequest {
Request::new()
.target(Address::new(&our.node, "vfs:sys:uqbar")?)?
.ipc_bytes(serde_json::to_vec(&kt::VfsRequest {
drive: package.to_string(),
action: kt::VfsAction::GetEntry("/manifest.json".into()),
})?,
None,
None,
5,
)?;
})?)
.send_and_await_response(5)??;
let Some(payload) = get_payload() else {
return Err(anyhow::anyhow!("no payload"));
};
let manifest = String::from_utf8(payload.bytes)?;
let manifest = serde_json::from_str::<Vec<PackageManifestEntry>>(&manifest)?;
let manifest = serde_json::from_str::<Vec<kt::PackageManifestEntry>>(&manifest)?;
for entry in manifest {
let path = if entry.process_wasm_path.starts_with("/") {
entry.process_wasm_path
@ -515,19 +451,15 @@ fn handle_local_request(
format!("/{}", entry.process_wasm_path)
};
let (_, hash_response) = process_lib::send_and_await_response(
&vfs_address,
false,
serde_json::to_vec(&kt::VfsRequest {
let (_, hash_response) = Request::new()
.target(Address::new(&our.node, "vfs:sys:uqbar")?)?
.ipc_bytes(serde_json::to_vec(&kt::VfsRequest {
drive: package.to_string(),
action: kt::VfsAction::GetHash(path.clone()),
})?,
None,
None,
5,
)?;
})?)
.send_and_await_response(5)??;
let Message::Response((Response { ipc, .. }, _)) = hash_response else {
let Message::Response((wit::Response { ipc, .. }, _)) = hash_response else {
return Err(anyhow::anyhow!("bad vfs response"));
};
let kt::VfsResponse::GetHash(Some(hash)) = serde_json::from_slice(&ipc)? else {
@ -579,9 +511,9 @@ fn handle_local_request(
node: our.node.clone(),
process: parsed_process_id.clone(),
},
&"\"messaging\"".into()
&"\"messaging\"".into(),
) else {
print_to_terminal(0, &format!("app-store: no cap for {} to give away!", process_name));
println!("app-store: no cap for {} to give away!", process_name);
continue;
};
initial_capabilities.insert(kt::de_wit_signed_capability(messaging_cap));
@ -591,63 +523,46 @@ fn handle_local_request(
let Ok(parsed_new_process_id) = ProcessId::from_str(&process_id) else {
return Err(anyhow::anyhow!("app-store: invalid process id!"));
};
let _ = process_lib::send_request(
&Address {
node: our.node.clone(),
process: ProcessId::from_str("kernel:sys:uqbar")?,
},
false,
serde_json::to_vec(&kt::KernelCommand::KillProcess(kt::ProcessId::de_wit(
parsed_new_process_id.clone(),
)))?,
None,
None,
None,
);
Request::new()
.target(Address::new(&our.node, "kernel:sys:uqbar")?)?
.ipc_bytes(serde_json::to_vec(&kt::KernelCommand::KillProcess(
kt::ProcessId::de_wit(parsed_new_process_id.clone()),
))?)
.send()?;
// kernel start process takes bytes as payload + wasm_bytes_handle...
// reconsider perhaps
let (_, _bytes_response) = process_lib::send_and_await_response(
&vfs_address,
false,
serde_json::to_vec(&kt::VfsRequest {
let (_, _bytes_response) = Request::new()
.target(Address::new(&our.node, "vfs:sys:uqbar")?)?
.ipc_bytes(serde_json::to_vec(&kt::VfsRequest {
drive: package.to_string(),
action: kt::VfsAction::GetEntry(path),
})?,
None,
None,
5,
)?;
})?)
.send_and_await_response(5)??;
let Some(payload) = get_payload() else {
return Err(anyhow::anyhow!("no wasm bytes payload."));
};
let _ = process_lib::send_and_await_response(
&Address {
node: our.node.clone(),
process: ProcessId::from_str("kernel:sys:uqbar")?,
},
false,
serde_json::to_vec(&kt::KernelCommand::StartProcess {
Request::new()
.target(Address::new(&our.node, "kernel:sys:uqbar")?)?
.ipc_bytes(serde_json::to_vec(&kt::KernelCommand::StartProcess {
id: kt::ProcessId::de_wit(parsed_new_process_id),
wasm_bytes_handle: hash,
on_panic: entry.on_panic,
initial_capabilities,
public: entry.public,
})?,
None,
Some(&payload),
5,
)?;
})?)
.payload(payload)
.send_and_await_response(5)?;
}
Ok(Some(Resp::InstallResponse(InstallResponse::Success)))
}
LocalRequest::Uninstall(package) => {
LocalRequest::Uninstall(_package) => {
// TODO
Ok(None)
}
LocalRequest::Delete(package) => {
LocalRequest::Delete(_package) => {
// TODO
Ok(None)
}
@ -663,28 +578,20 @@ fn handle_remote_request(
match request {
RemoteRequest::Download(package) => {
let Some(package_state) = state.packages.get(&package) else {
return Ok(Some(Resp::RemoteResponse(RemoteResponse::DownloadDenied)))
return Ok(Some(Resp::RemoteResponse(RemoteResponse::DownloadDenied)));
};
if !package_state.mirroring {
return Ok(Some(Resp::RemoteResponse(RemoteResponse::DownloadDenied)));
}
// get the .zip from VFS and attach as payload to response
let vfs_address = Address {
node: our.node.clone(),
process: ProcessId::from_str("vfs:sys:uqbar")?,
};
let file_name = format!("/{}.zip", package.to_string());
let _ = process_lib::send_and_await_response(
&vfs_address,
false,
serde_json::to_vec(&kt::VfsRequest {
Request::new()
.target(Address::new(&our.node, "vfs:sys:uqbar")?)?
.ipc_bytes(serde_json::to_vec(&kt::VfsRequest {
drive: package.to_string(),
action: kt::VfsAction::GetEntry(file_name.clone()),
})?,
None,
None,
5,
)?;
})?)
.send_and_await_response(5)?;
// transfer will inherit the payload bytes we receive from VFS
spawn_transfer(&our, &file_name, None, &source);
Ok(Some(Resp::RemoteResponse(RemoteResponse::DownloadApproved)))

View File

@ -1 +0,0 @@
../../../../src/process_lib.rs

View File

@ -23,29 +23,6 @@ version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
[[package]]
name = "cargo-component-bindings"
version = "0.3.0"
source = "git+https://github.com/bytecodealliance/cargo-component#5cddf6df7fd5ab5aa9bfd66f4cf2e2f6cc7d72f9"
dependencies = [
"cargo-component-macro",
"wit-bindgen 0.13.0",
]
[[package]]
name = "cargo-component-macro"
version = "0.3.0"
source = "git+https://github.com/bytecodealliance/cargo-component#5cddf6df7fd5ab5aa9bfd66f4cf2e2f6cc7d72f9"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
"wit-bindgen-core",
"wit-bindgen-rust",
"wit-component",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
@ -64,11 +41,11 @@ version = "0.1.0"
dependencies = [
"anyhow",
"bincode",
"cargo-component-bindings",
"rand",
"serde",
"serde_json",
"wit-bindgen 0.11.0",
"uqbar_process_lib",
"wit-bindgen",
]
[[package]]
@ -105,9 +82,9 @@ checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005"
[[package]]
name = "indexmap"
version = "2.0.2"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897"
checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f"
dependencies = [
"equivalent",
"hashbrown",
@ -128,9 +105,9 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67"
[[package]]
name = "libc"
version = "0.2.149"
version = "0.2.150"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b"
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
[[package]]
name = "log"
@ -206,18 +183,18 @@ checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090"
[[package]]
name = "serde"
version = "1.0.189"
version = "1.0.191"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537"
checksum = "a834c4821019838224821468552240d4d95d14e751986442c816572d39a080c9"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.189"
version = "1.0.191"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5"
checksum = "46fa52d5646bce91b680189fe5b1c049d2ea38dabb4e2e7c8d00ca12cfbfbcfd"
dependencies = [
"proc-macro2",
"quote",
@ -226,9 +203,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.107"
version = "1.0.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65"
checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b"
dependencies = [
"itoa",
"ryu",
@ -252,9 +229,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.38"
version = "2.0.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b"
checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a"
dependencies = [
"proc-macro2",
"quote",
@ -279,6 +256,17 @@ 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",
"rand",
"serde",
"wit-bindgen",
]
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
@ -287,18 +275,18 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-encoder"
version = "0.35.0"
version = "0.36.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ca90ba1b5b0a70d3d49473c5579951f3bddc78d47b59256d2f9d4922b150aca"
checksum = "822b645bf4f2446b949776ffca47e2af60b167209ffb70814ef8779d299cd421"
dependencies = [
"leb128",
]
[[package]]
name = "wasm-metadata"
version = "0.10.9"
version = "0.10.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14abc161bfda5b519aa229758b68f2a52b45a12b993808665c857d1a9a00223c"
checksum = "2167ce53b2faa16a92c6cafd4942cff16c9a4fa0c5a5a0a41131ee4e49fc055f"
dependencies = [
"anyhow",
"indexmap",
@ -312,9 +300,9 @@ dependencies = [
[[package]]
name = "wasmparser"
version = "0.115.0"
version = "0.116.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e06c0641a4add879ba71ccb3a1e4278fd546f76f1eafb21d8f7b07733b547cd5"
checksum = "a58e28b80dd8340cb07b8242ae654756161f6fc8d0038123d679b7b99964fa50"
dependencies = [
"indexmap",
"semver",
@ -322,18 +310,8 @@ dependencies = [
[[package]]
name = "wit-bindgen"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8a3e8e965dc50e6eb4410d9a11720719fadc6a1713803ea5f3be390b81c8279"
dependencies = [
"bitflags",
]
[[package]]
name = "wit-bindgen"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7d92ce0ca6b6074059413a9581a637550c3a740581c854f9847ec293c8aed71"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"bitflags",
"wit-bindgen-rust-macro",
@ -341,9 +319,8 @@ dependencies = [
[[package]]
name = "wit-bindgen-core"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "565b945ae074886071eccf9cdaf8ccd7b959c2b0d624095bea5fe62003e8b3e0"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"anyhow",
"wit-component",
@ -352,9 +329,8 @@ dependencies = [
[[package]]
name = "wit-bindgen-rust"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5695ff4e41873ed9ce56d2787e6b5772bdad9e70e2c1d2d160621d1762257f4f"
version = "0.13.2"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"anyhow",
"heck",
@ -365,9 +341,8 @@ dependencies = [
[[package]]
name = "wit-bindgen-rust-macro"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a91835ea4231da1fe7971679d505ba14be7826e192b6357f08465866ef482e08"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"anyhow",
"proc-macro2",
@ -380,9 +355,9 @@ dependencies = [
[[package]]
name = "wit-component"
version = "0.16.0"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e87488b57a08e2cbbd076b325acbe7f8666965af174d69d5929cd373bd54547f"
checksum = "480cc1a078b305c1b8510f7c455c76cbd008ee49935f3a6c5fd5e937d8d95b1e"
dependencies = [
"anyhow",
"bitflags",
@ -399,9 +374,9 @@ dependencies = [
[[package]]
name = "wit-parser"
version = "0.12.1"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6ace9943d89bbf3dbbc71b966da0e7302057b311f36a4ac3d65ddfef17b52cf"
checksum = "43771ee863a16ec4ecf9da0fc65c3bbd4a1235c8e3da5f094b562894843dfa76"
dependencies = [
"anyhow",
"id-arena",

View File

@ -13,19 +13,14 @@ lto = true
[dependencies]
anyhow = "1.0"
bincode = "1.3.3"
cargo-component-bindings = { git = "https://github.com/bytecodealliance/cargo-component" }
rand = "0.8"
serde = {version = "1.0", features = ["derive"] }
serde_json = "1.0"
wit-bindgen = { version = "0.11.0", default_features = false }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "5390bab780733f1660d14c254ec985df2816bf1d" }
uqbar_process_lib = { path = "../../../process_lib" }
[lib]
crate-type = ["cdylib"]
[package.metadata.component]
package = "component:uq-process"
[package.metadata.component.target]
path = "wit"
[package.metadata.component.dependencies]
package = "uqbar:process"

View File

@ -1,6 +1,5 @@
use super::bindings::component::uq_process::types::*;
use super::bindings::{print_to_terminal, send_request, spawn, Address, Payload};
use serde::{Deserialize, Serialize};
use uqbar_process_lib::uqbar::process::standard::*;
#[derive(Debug, Serialize, Deserialize)]
pub struct FileTransferContext {
@ -84,15 +83,17 @@ pub fn spawn_transfer(
.unwrap(),
metadata: None,
},
Some(&serde_json::to_vec(&FileTransferContext {
file_name: file_name.into(),
file_size: match &payload_or_inherit {
Some(p) => Some(p.bytes.len() as u64),
None => None, // TODO
},
start_time: std::time::SystemTime::now(),
})
.unwrap()),
Some(
&serde_json::to_vec(&FileTransferContext {
file_name: file_name.into(),
file_size: match &payload_or_inherit {
Some(p) => Some(p.bytes.len() as u64),
None => None, // TODO
},
start_time: std::time::SystemTime::now(),
})
.unwrap(),
),
payload_or_inherit.as_ref(),
);
}

View File

@ -1,15 +1,17 @@
cargo_component_bindings::generate!();
use bindings::component::uq_process::types::*;
use bindings::{get_payload, print_to_terminal, receive, send_request, send_response, Guest};
use serde::{Deserialize, Serialize};
struct Component;
use uqbar_process_lib::uqbar::process::standard::*;
mod ft_worker_lib;
#[allow(dead_code)]
mod process_lib;
use ft_worker_lib::*;
wit_bindgen::generate!({
path: "../../../wit",
world: "process",
exports: {
world: Component,
},
});
/// internal worker protocol
#[derive(Debug, Serialize, Deserialize)]
pub enum FTWorkerProtocol {
@ -17,8 +19,10 @@ pub enum FTWorkerProtocol {
Finished,
}
struct Component;
impl Guest for Component {
fn init(our: Address) {
fn init(our: String) {
let our = Address::from_str(&our).unwrap();
print_to_terminal(1, &format!("{}: start", our.process));
let Ok((parent_process, Message::Request(req))) = receive() else {
@ -49,7 +53,7 @@ impl Guest for Component {
// then upon reciving affirmative response,
// send contents in chunks and wait for
// acknowledgement.
match bindings::send_and_await_response(
match send_and_await_response(
&Address::from_str(&target).unwrap(),
&Request {
inherit: false,

View File

@ -1 +0,0 @@
../../../../src/process_lib.rs

View File

@ -1,3 +0,0 @@
# This file is automatically generated by cargo-component.
# It is not intended for manual editing.
version = 1

290
modules/chess/Cargo.lock generated
View File

@ -46,33 +46,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.4.0"
version = "2.4.1"
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#36c221e41db3e87dec4c82eadcb9bc8f37626533"
dependencies = [
"cargo-component-macro",
"wit-bindgen",
]
[[package]]
name = "cargo-component-macro"
version = "0.1.0"
source = "git+https://github.com/bytecodealliance/cargo-component#36c221e41db3e87dec4c82eadcb9bc8f37626533"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
"wit-bindgen-core",
"wit-bindgen-rust",
"wit-bindgen-rust-lib",
"wit-component",
]
checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
[[package]]
name = "cfg-if"
@ -87,10 +63,10 @@ dependencies = [
"anyhow",
"base64",
"bincode",
"cargo-component-bindings",
"pleco",
"serde",
"serde_json",
"uqbar_process_lib",
"wit-bindgen",
]
@ -148,15 +124,6 @@ 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 = "fuchsia-cprng"
version = "0.1.1"
@ -164,10 +131,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
[[package]]
name = "hashbrown"
version = "0.14.0"
name = "getrandom"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "hashbrown"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156"
[[package]]
name = "heck"
@ -190,21 +168,11 @@ 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"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d"
checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f"
dependencies = [
"equivalent",
"hashbrown",
@ -231,9 +199,9 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67"
[[package]]
name = "libc"
version = "0.2.148"
version = "0.2.150"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b"
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
[[package]]
name = "log"
@ -241,12 +209,6 @@ 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 = "memoffset"
version = "0.9.0"
@ -272,12 +234,6 @@ dependencies = [
"libc",
]
[[package]]
name = "percent-encoding"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94"
[[package]]
name = "pleco"
version = "0.5.0"
@ -288,28 +244,23 @@ dependencies = [
"lazy_static",
"mucow",
"num_cpus",
"rand",
"rand 0.6.5",
"rayon",
]
[[package]]
name = "proc-macro2"
version = "1.0.66"
name = "ppv-lite86"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
dependencies = [
"unicode-ident",
]
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "pulldown-cmark"
version = "0.9.3"
name = "proc-macro2"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77a1a2f1f0a7ecff9c31abbe177637be0e97a0aef46cf8738ece09327985d998"
checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
dependencies = [
"bitflags 1.3.2",
"memchr",
"unicase",
"unicode-ident",
]
[[package]]
@ -329,7 +280,7 @@ checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca"
dependencies = [
"autocfg 0.1.8",
"libc",
"rand_chacha",
"rand_chacha 0.1.1",
"rand_core 0.4.2",
"rand_hc",
"rand_isaac",
@ -340,6 +291,17 @@ dependencies = [
"winapi",
]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha 0.3.1",
"rand_core 0.6.4",
]
[[package]]
name = "rand_chacha"
version = "0.1.1"
@ -350,6 +312,16 @@ dependencies = [
"rand_core 0.3.1",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core 0.6.4",
]
[[package]]
name = "rand_core"
version = "0.3.1"
@ -365,6 +337,15 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
name = "rand_hc"
version = "0.1.0"
@ -470,24 +451,24 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "semver"
version = "1.0.18"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918"
checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090"
[[package]]
name = "serde"
version = "1.0.188"
version = "1.0.191"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e"
checksum = "a834c4821019838224821468552240d4d95d14e751986442c816572d39a080c9"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.188"
version = "1.0.191"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2"
checksum = "46fa52d5646bce91b680189fe5b1c049d2ea38dabb4e2e7c8d00ca12cfbfbcfd"
dependencies = [
"proc-macro2",
"quote",
@ -496,9 +477,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.106"
version = "1.0.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2cc66a619ed80bf7a0f6b17dd063a84b88f6dea1813737cf469aef1d081142c2"
checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b"
dependencies = [
"itoa",
"ryu",
@ -507,9 +488,9 @@ dependencies = [
[[package]]
name = "smallvec"
version = "1.11.0"
version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9"
checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a"
[[package]]
name = "spdx"
@ -522,59 +503,20 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.32"
version = "2.0.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "239814284fd6f1a4ffe4ca893952cdd93c224b6a1571c9a9eadd670295c0c9e2"
checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a"
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"
version = "1.0.12"
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",
]
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "unicode-segmentation"
@ -589,40 +531,41 @@ 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"
name = "uqbar_process_lib"
version = "0.2.0"
dependencies = [
"form_urlencoded",
"idna",
"percent-encoding",
"anyhow",
"bincode",
"rand 0.8.5",
"serde",
"wit-bindgen",
]
[[package]]
name = "version_check"
version = "0.9.4"
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-encoder"
version = "0.32.0"
version = "0.36.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ba64e81215916eaeb48fee292f29401d69235d62d8b8fd92a7b2844ec5ae5f7"
checksum = "822b645bf4f2446b949776ffca47e2af60b167209ffb70814ef8779d299cd421"
dependencies = [
"leb128",
]
[[package]]
name = "wasm-metadata"
version = "0.10.3"
version = "0.10.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08dc59d1fa569150851542143ca79438ca56845ccb31696c70225c638e063471"
checksum = "2167ce53b2faa16a92c6cafd4942cff16c9a4fa0c5a5a0a41131ee4e49fc055f"
dependencies = [
"anyhow",
"indexmap",
"serde",
"serde_derive",
"serde_json",
"spdx",
"wasm-encoder",
@ -631,9 +574,9 @@ dependencies = [
[[package]]
name = "wasmparser"
version = "0.112.0"
version = "0.116.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e986b010f47fcce49cf8ea5d5f9e5d2737832f12b53ae8ae785bbe895d0877bf"
checksum = "a58e28b80dd8340cb07b8242ae654756161f6fc8d0038123d679b7b99964fa50"
dependencies = [
"indexmap",
"semver",
@ -663,19 +606,17 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "wit-bindgen"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8a3e8e965dc50e6eb4410d9a11720719fadc6a1713803ea5f3be390b81c8279"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"bitflags 2.4.0",
"bitflags 2.4.1",
"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"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"anyhow",
"wit-component",
@ -684,54 +625,42 @@ dependencies = [
[[package]]
name = "wit-bindgen-rust"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "399c60e6ea8598d1380e792f13d557007834f0fb799fea6503408cbc5debb4ae"
version = "0.13.2"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
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"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"anyhow",
"proc-macro2",
"quote",
"syn",
"wit-bindgen-core",
"wit-bindgen-rust",
"wit-bindgen-rust-lib",
"wit-component",
]
[[package]]
name = "wit-component"
version = "0.14.0"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66d9f2d16dd55d1a372dcfd4b7a466ea876682a5a3cb97e71ec9eef04affa876"
checksum = "480cc1a078b305c1b8510f7c455c76cbd008ee49935f3a6c5fd5e937d8d95b1e"
dependencies = [
"anyhow",
"bitflags 2.4.0",
"bitflags 2.4.1",
"indexmap",
"log",
"serde",
"serde_derive",
"serde_json",
"wasm-encoder",
"wasm-metadata",
@ -741,16 +670,17 @@ dependencies = [
[[package]]
name = "wit-parser"
version = "0.11.0"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61e8b849bea13cc2315426b16efe6eb6813466d78f5fde69b0bb150c9c40e0dc"
checksum = "43771ee863a16ec4ecf9da0fc65c3bbd4a1235c8e3da5f094b562894843dfa76"
dependencies = [
"anyhow",
"id-arena",
"indexmap",
"log",
"pulldown-cmark",
"semver",
"serde",
"serde_derive",
"serde_json",
"unicode-xid",
"url",
]

View File

@ -12,21 +12,16 @@ lto = true
[dependencies]
anyhow = "1.0"
base64 = "0.13"
bincode = "1.3.3"
cargo-component-bindings = { git = "https://github.com/bytecodealliance/cargo-component" }
pleco = "0.5"
serde = {version = "1.0", features = ["derive"] }
serde_json = "1.0"
wit-bindgen = { version = "0.11.0", default_features = false }
base64 = "0.13"
pleco = "0.5"
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "5390bab780733f1660d14c254ec985df2816bf1d" }
uqbar_process_lib = { path = "../../process_lib" }
[lib]
crate-type = ["cdylib"]
[package.metadata.component]
package = "component:uq-process"
[package.metadata.component.target]
path = "wit"
[package.metadata.component.dependencies]
package = "uqbar:process"

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -1 +0,0 @@
../../../src/process_lib.rs

View File

@ -1,3 +0,0 @@
# This file is automatically generated by cargo-component.
# It is not intended for manual editing.
version = 1

View File

@ -19,39 +19,15 @@ dependencies = [
[[package]]
name = "bitflags"
version = "1.3.2"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
[[package]]
name = "bitflags"
version = "2.4.0"
name = "cfg-if"
version = "1.0.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#36c221e41db3e87dec4c82eadcb9bc8f37626533"
dependencies = [
"cargo-component-macro",
"wit-bindgen",
]
[[package]]
name = "cargo-component-macro"
version = "0.1.0"
source = "git+https://github.com/bytecodealliance/cargo-component#36c221e41db3e87dec4c82eadcb9bc8f37626533"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
"wit-bindgen-core",
"wit-bindgen-rust",
"wit-bindgen-rust-lib",
"wit-component",
]
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "equivalent"
@ -60,19 +36,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "form_urlencoded"
version = "1.2.0"
name = "getrandom"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652"
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
dependencies = [
"percent-encoding",
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "hashbrown"
version = "0.14.0"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156"
[[package]]
name = "heck"
@ -89,9 +67,9 @@ version = "0.1.0"
dependencies = [
"anyhow",
"bincode",
"cargo-component-bindings",
"serde",
"serde_json",
"uqbar_process_lib",
"wit-bindgen",
]
@ -101,21 +79,11 @@ 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"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d"
checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f"
dependencies = [
"equivalent",
"hashbrown",
@ -134,6 +102,12 @@ version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67"
[[package]]
name = "libc"
version = "0.2.150"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
[[package]]
name = "log"
version = "0.4.20"
@ -141,37 +115,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
[[package]]
name = "memchr"
version = "2.6.3"
name = "ppv-lite86"
version = "0.2.17"
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"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "proc-macro2"
version = "1.0.66"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
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"
@ -181,6 +138,36 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
name = "ryu"
version = "1.0.15"
@ -189,24 +176,24 @@ checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
[[package]]
name = "semver"
version = "1.0.18"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918"
checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090"
[[package]]
name = "serde"
version = "1.0.188"
version = "1.0.191"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e"
checksum = "a834c4821019838224821468552240d4d95d14e751986442c816572d39a080c9"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.188"
version = "1.0.191"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2"
checksum = "46fa52d5646bce91b680189fe5b1c049d2ea38dabb4e2e7c8d00ca12cfbfbcfd"
dependencies = [
"proc-macro2",
"quote",
@ -215,9 +202,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.106"
version = "1.0.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2cc66a619ed80bf7a0f6b17dd063a84b88f6dea1813737cf469aef1d081142c2"
checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b"
dependencies = [
"itoa",
"ryu",
@ -226,9 +213,9 @@ dependencies = [
[[package]]
name = "smallvec"
version = "1.11.0"
version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9"
checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a"
[[package]]
name = "spdx"
@ -241,59 +228,20 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.32"
version = "2.0.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "239814284fd6f1a4ffe4ca893952cdd93c224b6a1571c9a9eadd670295c0c9e2"
checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a"
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"
version = "1.0.12"
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",
]
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "unicode-segmentation"
@ -308,40 +256,41 @@ 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"
name = "uqbar_process_lib"
version = "0.2.0"
dependencies = [
"form_urlencoded",
"idna",
"percent-encoding",
"anyhow",
"bincode",
"rand",
"serde",
"wit-bindgen",
]
[[package]]
name = "version_check"
version = "0.9.4"
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-encoder"
version = "0.32.0"
version = "0.36.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ba64e81215916eaeb48fee292f29401d69235d62d8b8fd92a7b2844ec5ae5f7"
checksum = "822b645bf4f2446b949776ffca47e2af60b167209ffb70814ef8779d299cd421"
dependencies = [
"leb128",
]
[[package]]
name = "wasm-metadata"
version = "0.10.3"
version = "0.10.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08dc59d1fa569150851542143ca79438ca56845ccb31696c70225c638e063471"
checksum = "2167ce53b2faa16a92c6cafd4942cff16c9a4fa0c5a5a0a41131ee4e49fc055f"
dependencies = [
"anyhow",
"indexmap",
"serde",
"serde_derive",
"serde_json",
"spdx",
"wasm-encoder",
@ -350,9 +299,9 @@ dependencies = [
[[package]]
name = "wasmparser"
version = "0.112.0"
version = "0.116.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e986b010f47fcce49cf8ea5d5f9e5d2737832f12b53ae8ae785bbe895d0877bf"
checksum = "a58e28b80dd8340cb07b8242ae654756161f6fc8d0038123d679b7b99964fa50"
dependencies = [
"indexmap",
"semver",
@ -360,19 +309,17 @@ dependencies = [
[[package]]
name = "wit-bindgen"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8a3e8e965dc50e6eb4410d9a11720719fadc6a1713803ea5f3be390b81c8279"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"bitflags 2.4.0",
"bitflags",
"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"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"anyhow",
"wit-component",
@ -381,54 +328,42 @@ dependencies = [
[[package]]
name = "wit-bindgen-rust"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "399c60e6ea8598d1380e792f13d557007834f0fb799fea6503408cbc5debb4ae"
version = "0.13.2"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
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"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"anyhow",
"proc-macro2",
"quote",
"syn",
"wit-bindgen-core",
"wit-bindgen-rust",
"wit-bindgen-rust-lib",
"wit-component",
]
[[package]]
name = "wit-component"
version = "0.14.0"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66d9f2d16dd55d1a372dcfd4b7a466ea876682a5a3cb97e71ec9eef04affa876"
checksum = "480cc1a078b305c1b8510f7c455c76cbd008ee49935f3a6c5fd5e937d8d95b1e"
dependencies = [
"anyhow",
"bitflags 2.4.0",
"bitflags",
"indexmap",
"log",
"serde",
"serde_derive",
"serde_json",
"wasm-encoder",
"wasm-metadata",
@ -438,16 +373,17 @@ dependencies = [
[[package]]
name = "wit-parser"
version = "0.11.0"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61e8b849bea13cc2315426b16efe6eb6813466d78f5fde69b0bb150c9c40e0dc"
checksum = "43771ee863a16ec4ecf9da0fc65c3bbd4a1235c8e3da5f094b562894843dfa76"
dependencies = [
"anyhow",
"id-arena",
"indexmap",
"log",
"pulldown-cmark",
"semver",
"serde",
"serde_derive",
"serde_json",
"unicode-xid",
"url",
]

View File

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

View File

@ -1,200 +1,170 @@
cargo_component_bindings::generate!();
use bindings::component::uq_process::types::*;
use bindings::{
get_payload, print_to_terminal, receive, send_request, send_requests, send_response, Guest,
};
use serde_json::json;
use uqbar_process_lib::{get_payload, receive, Address, Message, Payload, Request, Response};
#[allow(dead_code)]
mod process_lib;
wit_bindgen::generate!({
path: "../../wit",
world: "process",
exports: {
world: Component,
},
});
struct Component;
const HOME_PAGE: &str = include_str!("home.html");
fn generate_http_binding(
add: Address,
path: &str,
authenticated: bool,
) -> (Address, Request, Option<Context>, Option<Payload>) {
(
add,
Request {
inherit: false,
expects_response: None,
ipc: json!({
"BindPath": {
"path": path,
"authenticated": authenticated,
"local_only": false
}
})
.to_string()
.as_bytes()
.to_vec(),
metadata: None,
},
None,
None,
)
fn serialize_json_message(message: &serde_json::Value) -> anyhow::Result<Vec<u8>> {
Ok(serde_json::to_vec(message)?)
}
impl Guest for Component {
fn init(our: Address) {
print_to_terminal(0, "homepage: start");
fn init(our: String) {
let our = Address::from_str(&our).unwrap();
println!("homepage: start");
let bindings_address = Address {
node: our.node.clone(),
process: ProcessId::from_str("http_server:sys:uqbar").unwrap(),
match main(our) {
Ok(_) => {}
Err(e) => {
println!("homepage: ended with error: {:?}", e);
}
}
}
}
fn main(our: Address) -> anyhow::Result<()> {
// bind to root path on http_server
Request::new()
.target(Address::new(&our.node, "http_server:sys:uqbar")?)?
.ipc(
&json!({
"BindPath": {
"path": "/",
"authenticated": true,
"local_only": false
}
}),
serialize_json_message,
)?
.send()?;
loop {
let Ok((_source, message)) = receive() else {
println!("homepage: got network error");
continue;
};
let Message::Request(request) = message else {
println!("homepage: got unexpected message: {:?}", message);
continue;
};
// <address, request, option<context>, option<payload>>
let http_endpoint_binding_requests: [(Address, Request, Option<Context>, Option<Payload>);
1] = [generate_http_binding(bindings_address.clone(), "/", true)];
send_requests(&http_endpoint_binding_requests);
loop {
let Ok((_source, message)) = receive() else {
print_to_terminal(0, "homepage: got network error");
let message_json: serde_json::Value = match serde_json::from_slice(&request.ipc) {
Ok(v) => v,
Err(_) => {
println!("homepage: failed to parse ipc JSON, skipping");
continue;
};
let Message::Request(request) = message else {
print_to_terminal(0, &format!("homepage: got unexpected message: {:?}", message));
continue;
};
}
};
let message_json: serde_json::Value = match serde_json::from_slice(&request.ipc) {
Ok(v) => v,
Err(_) => {
print_to_terminal(1, "homepage: failed to parse ipc JSON, skipping");
continue;
}
};
if message_json["path"] == "/" && message_json["method"] == "GET" {
print_to_terminal(1, "homepage: sending response");
send_response(
&Response {
inherit: false,
ipc: serde_json::json!({
"action": "response",
"status": 200,
"headers": {
"Content-Type": "text/html",
},
})
.to_string()
.as_bytes()
.to_vec(),
metadata: None,
},
Some(&Payload {
mime: Some("text/html".to_string()),
bytes: HOME_PAGE
.replace("${our}", &our.node)
.to_string()
.as_bytes()
.to_vec(),
if message_json["path"] == "/" && message_json["method"] == "GET" {
println!("homepage: sending response");
Response::new()
.ipc(
&json!({
"action": "response",
"status": 200,
"headers": {
"Content-Type": "text/html",
},
}),
);
} else if message_json["path"].is_string() {
send_response(
&Response {
inherit: false,
ipc: json!({
"action": "response",
"status": 404,
"headers": {
"Content-Type": "text/html",
},
})
serialize_json_message,
)?
.payload(Payload {
mime: Some("text/html".to_string()),
bytes: HOME_PAGE
.replace("${our}", &our.node)
.to_string()
.as_bytes()
.to_vec(),
metadata: None,
},
Some(&Payload {
mime: Some("text/html".to_string()),
bytes: "Not Found".to_string().as_bytes().to_vec(),
})
.send()?;
} else if message_json["path"].is_string() {
Response::new()
.ipc(
&json!({
"action": "response",
"status": 404,
"headers": {
"Content-Type": "text/html",
},
}),
);
} else if message_json["hello"] == "world" {
send_response(
&Response {
inherit: false,
ipc: serde_json::json!({
"hello": "to you too"
})
.to_string()
.as_bytes()
.to_vec(),
metadata: None,
},
Some(&Payload {
mime: Some("application/json".to_string()),
bytes: serde_json::json!({
"hello": "to you too"
})
.to_string()
.as_bytes()
.to_vec(),
serialize_json_message,
)?
.payload(Payload {
mime: Some("text/html".to_string()),
bytes: "Not Found".to_string().as_bytes().to_vec(),
})
.send()?;
} else if message_json["hello"] == "world" {
Response::new()
.ipc(
&json!({
"hello": "to you too"
}),
);
} else {
if let Some(payload) = get_payload() {
if let Ok(json) = serde_json::from_slice::<serde_json::Value>(&payload.bytes) {
print_to_terminal(1, format!("JSON: {}", json).as_str());
if json["message"] == "ping" {
// WebSocket pushes are sent as requests
send_request(
&Address {
node: our.node.clone(),
process: ProcessId::from_str("encryptor:sys:uqbar").unwrap(),
},
&Request {
inherit: false,
expects_response: None,
ipc: serde_json::json!({
"EncryptAndForwardAction": {
"channel_id": "homepage",
"forward_to": {
"node": our.node.clone(),
"process": {
"process_name": "http_server",
"package_name": "sys",
"publisher_node": "uqbar"
serialize_json_message,
)?
.payload(Payload {
mime: Some("application/json".to_string()),
bytes: serde_json::json!({
"hello": "to you too"
})
.to_string()
.as_bytes()
.to_vec(),
})
.send()?;
} else {
if let Some(payload) = get_payload() {
if let Ok(json) = serde_json::from_slice::<serde_json::Value>(&payload.bytes) {
// println!("JSON: {}", json);
if json["message"] == "ping" {
// WebSocket pushes are sent as requests
Request::new()
.target(Address::new(&our.node, "encryptor:sys:uqbar")?)?
.ipc(
&json!({
"EncryptAndForwardAction": {
"channel_id": "homepage",
"forward_to": {
"node": our.node.clone(),
"process": {
"process_name": "http_server",
"package_name": "sys",
"publisher_node": "uqbar"
}
}, // node, process
"json": Some(json!({ // this is the JSON to forward
"WebSocketPush": {
"target": {
"node": our.node.clone(),
"id": "homepage", // If the message passed in an ID then we could send to just that ID
}
}, // node, process
"json": Some(serde_json::json!({ // this is the JSON to forward
"WebSocketPush": {
"target": {
"node": our.node.clone(),
"id": "homepage", // If the message passed in an ID then we could send to just that ID
}
}
})),
}
}
})),
}
})
.to_string()
.as_bytes()
.to_vec(),
metadata: None,
},
None,
Some(&Payload {
mime: Some("application/json".to_string()),
bytes: serde_json::json!({
"pong": true
})
.to_string()
.as_bytes()
.to_vec(),
}),
);
}
serialize_json_message,
)?
.payload(Payload {
mime: Some("application/json".to_string()),
bytes: serde_json::json!({
"pong": true
})
.to_string()
.as_bytes()
.to_vec(),
})
.send()?;
}
}
}

View File

@ -1,3 +0,0 @@
# This file is automatically generated by cargo-component.
# It is not intended for manual editing.
version = 1

View File

@ -19,39 +19,15 @@ dependencies = [
[[package]]
name = "bitflags"
version = "1.3.2"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
[[package]]
name = "bitflags"
version = "2.4.0"
name = "cfg-if"
version = "1.0.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#aa6e3c1168273b5cf6221fa0206f07f2ffb8567d"
dependencies = [
"cargo-component-macro",
"wit-bindgen",
]
[[package]]
name = "cargo-component-macro"
version = "0.1.0"
source = "git+https://github.com/bytecodealliance/cargo-component#aa6e3c1168273b5cf6221fa0206f07f2ffb8567d"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
"wit-bindgen-core",
"wit-bindgen-rust",
"wit-bindgen-rust-lib",
"wit-component",
]
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "equivalent"
@ -60,19 +36,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "form_urlencoded"
version = "1.2.0"
name = "getrandom"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652"
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
dependencies = [
"percent-encoding",
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "hashbrown"
version = "0.14.0"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156"
[[package]]
name = "heck"
@ -85,13 +63,13 @@ dependencies = [
[[package]]
name = "http_proxy"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"anyhow",
"bincode",
"cargo-component-bindings",
"serde",
"serde_json",
"uqbar_process_lib",
"wit-bindgen",
]
@ -101,21 +79,11 @@ 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"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d"
checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f"
dependencies = [
"equivalent",
"hashbrown",
@ -134,6 +102,12 @@ version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67"
[[package]]
name = "libc"
version = "0.2.150"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
[[package]]
name = "log"
version = "0.4.20"
@ -141,37 +115,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
[[package]]
name = "memchr"
version = "2.6.3"
name = "ppv-lite86"
version = "0.2.17"
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"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "proc-macro2"
version = "1.0.66"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
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"
@ -181,6 +138,36 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
name = "ryu"
version = "1.0.15"
@ -189,24 +176,24 @@ checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
[[package]]
name = "semver"
version = "1.0.18"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918"
checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090"
[[package]]
name = "serde"
version = "1.0.188"
version = "1.0.191"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e"
checksum = "a834c4821019838224821468552240d4d95d14e751986442c816572d39a080c9"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.188"
version = "1.0.191"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2"
checksum = "46fa52d5646bce91b680189fe5b1c049d2ea38dabb4e2e7c8d00ca12cfbfbcfd"
dependencies = [
"proc-macro2",
"quote",
@ -215,9 +202,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.105"
version = "1.0.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360"
checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b"
dependencies = [
"itoa",
"ryu",
@ -226,9 +213,9 @@ dependencies = [
[[package]]
name = "smallvec"
version = "1.11.0"
version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9"
checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a"
[[package]]
name = "spdx"
@ -241,59 +228,20 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.31"
version = "2.0.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "718fa2415bcb8d8bd775917a1bf12a7931b6dfa890753378538118181e0cb398"
checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a"
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"
version = "1.0.12"
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",
]
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "unicode-segmentation"
@ -308,40 +256,41 @@ 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"
name = "uqbar_process_lib"
version = "0.2.0"
dependencies = [
"form_urlencoded",
"idna",
"percent-encoding",
"anyhow",
"bincode",
"rand",
"serde",
"wit-bindgen",
]
[[package]]
name = "version_check"
version = "0.9.4"
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-encoder"
version = "0.32.0"
version = "0.36.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ba64e81215916eaeb48fee292f29401d69235d62d8b8fd92a7b2844ec5ae5f7"
checksum = "822b645bf4f2446b949776ffca47e2af60b167209ffb70814ef8779d299cd421"
dependencies = [
"leb128",
]
[[package]]
name = "wasm-metadata"
version = "0.10.3"
version = "0.10.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08dc59d1fa569150851542143ca79438ca56845ccb31696c70225c638e063471"
checksum = "2167ce53b2faa16a92c6cafd4942cff16c9a4fa0c5a5a0a41131ee4e49fc055f"
dependencies = [
"anyhow",
"indexmap",
"serde",
"serde_derive",
"serde_json",
"spdx",
"wasm-encoder",
@ -350,9 +299,9 @@ dependencies = [
[[package]]
name = "wasmparser"
version = "0.112.0"
version = "0.116.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e986b010f47fcce49cf8ea5d5f9e5d2737832f12b53ae8ae785bbe895d0877bf"
checksum = "a58e28b80dd8340cb07b8242ae654756161f6fc8d0038123d679b7b99964fa50"
dependencies = [
"indexmap",
"semver",
@ -360,19 +309,17 @@ dependencies = [
[[package]]
name = "wit-bindgen"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8a3e8e965dc50e6eb4410d9a11720719fadc6a1713803ea5f3be390b81c8279"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"bitflags 2.4.0",
"bitflags",
"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"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"anyhow",
"wit-component",
@ -381,54 +328,42 @@ dependencies = [
[[package]]
name = "wit-bindgen-rust"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "399c60e6ea8598d1380e792f13d557007834f0fb799fea6503408cbc5debb4ae"
version = "0.13.2"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
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"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"anyhow",
"proc-macro2",
"quote",
"syn",
"wit-bindgen-core",
"wit-bindgen-rust",
"wit-bindgen-rust-lib",
"wit-component",
]
[[package]]
name = "wit-component"
version = "0.14.0"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66d9f2d16dd55d1a372dcfd4b7a466ea876682a5a3cb97e71ec9eef04affa876"
checksum = "480cc1a078b305c1b8510f7c455c76cbd008ee49935f3a6c5fd5e937d8d95b1e"
dependencies = [
"anyhow",
"bitflags 2.4.0",
"bitflags",
"indexmap",
"log",
"serde",
"serde_derive",
"serde_json",
"wasm-encoder",
"wasm-metadata",
@ -438,16 +373,17 @@ dependencies = [
[[package]]
name = "wit-parser"
version = "0.11.0"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61e8b849bea13cc2315426b16efe6eb6813466d78f5fde69b0bb150c9c40e0dc"
checksum = "43771ee863a16ec4ecf9da0fc65c3bbd4a1235c8e3da5f094b562894843dfa76"
dependencies = [
"anyhow",
"id-arena",
"indexmap",
"log",
"pulldown-cmark",
"semver",
"serde",
"serde_derive",
"serde_json",
"unicode-xid",
"url",
]

View File

@ -1,6 +1,6 @@
[package]
name = "http_proxy"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -11,20 +11,15 @@ opt-level = "s"
lto = true
[dependencies]
anyhow = "1.0.72"
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 }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "5390bab780733f1660d14c254ec985df2816bf1d" }
uqbar_process_lib = { path = "../../process_lib" }
[lib]
crate-type = ["cdylib"]
[package.metadata.component]
package = "component:uq-process"
[package.metadata.component.target]
path = "wit"
[package.metadata.component.dependencies]
package = "uqbar:process"

View File

@ -1,42 +1,60 @@
cargo_component_bindings::generate!();
use serde::{Deserialize, Serialize};
use serde_json::json;
use std::collections::HashMap;
use bindings::component::uq_process::types::*;
use bindings::{
get_payload, print_to_terminal, receive, send_request, send_requests, send_response, Guest,
use uqbar_process_lib::{
get_payload, receive, println, Address, Message, Payload, Request, Response,
};
#[allow(dead_code)]
mod process_lib;
wit_bindgen::generate!({
path: "../../wit",
world: "process",
exports: {
world: Component,
},
});
struct Component;
impl Guest for Component {
fn init(our: String) {
let our = Address::from_str(&our).unwrap();
//print_to_terminal(1, "http_proxy: start");
match main(our) {
Ok(_) => {}
Err(e) => {
println!("http_proxy: ended with error: {:?}", e);
}
}
}
}
const PROXY_HOME_PAGE: &str = include_str!("http_proxy.html");
struct Component;
fn send_http_response(status: u16, headers: HashMap<String, String>, payload_bytes: Vec<u8>) {
send_response(
&Response {
inherit: false,
ipc: serde_json::json!({
"status": status,
"headers": headers,
})
.to_string()
.as_bytes()
.to_vec(),
metadata: None,
},
Some(&Payload {
mime: Some("text/html".to_string()),
bytes: payload_bytes,
}),
)
fn serialize_json_message(message: &serde_json::Value) -> anyhow::Result<Vec<u8>> {
Ok(serde_json::to_vec(message)?)
}
fn send_not_found() {
fn send_http_response(
status: u16,
headers: HashMap<String, String>,
payload_bytes: Vec<u8>,
) -> anyhow::Result<()> {
Response::new()
.ipc(
&json!({
"status": status,
"headers": headers,
}),
serialize_json_message,
)?
.payload(Payload {
mime: Some("text/html".to_string()),
bytes: payload_bytes,
})
.send()?;
Ok(())
}
fn send_not_found() -> anyhow::Result<()> {
send_http_response(
404,
HashMap::new(),
@ -44,359 +62,234 @@ fn send_not_found() {
)
}
impl Guest for Component {
fn init(our: Address) {
print_to_terminal(1, "http_proxy: start");
fn main(our: Address) -> anyhow::Result<()> {
let mut registrations: HashMap<String, String> = HashMap::new();
let mut registrations: HashMap<String, String> = HashMap::new();
// bind to all of our favorite paths
for path in ["/", "/static/*", "/list", "/register", "/serve/:username/*"] {
Request::new()
.target(Address::new(&our.node, "http_server:sys:uqbar")?)?
.ipc(
&json!({
"BindPath": {
"path": path,
"authenticated": true,
"local_only": false
}
}),
serialize_json_message,
)?
.send()?;
}
let bindings_address = Address {
node: our.node.clone(),
process: ProcessId::from_str("http_server:sys:uqbar").unwrap(),
loop {
let Ok((_source, message)) = receive() else {
//print_to_terminal(0, "http_proxy: got network error");
let mut headers = HashMap::new();
headers.insert("Content-Type".to_string(), "text/html".to_string());
send_http_response(
503,
headers,
format!("<h1>Node Offline</h1>").as_bytes().to_vec(),
)?;
continue;
};
let Message::Request(request) = message else {
println!("http_proxy: got unexpected message");
continue;
};
// <address, request, option<context>, option<payload>>
let http_endpoint_binding_requests: [(Address, Request, Option<Context>, Option<Payload>);
5] = [
(
bindings_address.clone(),
Request {
inherit: false,
expects_response: None,
ipc: json!({
"BindPath": {
"path": "/",
"authenticated": true,
"local_only": false
}
})
.to_string()
.as_bytes()
.to_vec(),
metadata: None,
},
None,
None,
),
(
bindings_address.clone(),
Request {
inherit: false,
expects_response: None,
ipc: json!({
"BindPath": {
"path": "/static/*",
"authenticated": true,
"local_only": false
}
})
.to_string()
.as_bytes()
.to_vec(),
metadata: None,
},
None,
None,
),
(
bindings_address.clone(),
Request {
inherit: false,
expects_response: None,
ipc: json!({
"BindPath": {
"path": "/list",
"authenticated": true,
"local_only": false
}
})
.to_string()
.as_bytes()
.to_vec(),
metadata: None,
},
None,
None,
),
(
bindings_address.clone(),
Request {
inherit: false,
expects_response: None,
ipc: json!({
"BindPath": {
"path": "/register",
"authenticated": true,
"local_only": false
}
})
.to_string()
.as_bytes()
.to_vec(),
metadata: None,
},
None,
None,
),
(
bindings_address.clone(),
Request {
inherit: false,
expects_response: None,
ipc: json!({
"BindPath": {
"path": "/serve/:username/*",
"authenticated": true,
"local_only": false
}
})
.to_string()
.as_bytes()
.to_vec(),
metadata: None,
},
None,
None,
),
];
send_requests(&http_endpoint_binding_requests);
loop {
let Ok((_source, message)) = receive() else {
print_to_terminal(0, "http_proxy: got network error");
let mut headers = HashMap::new();
headers.insert("Content-Type".to_string(), "text/html".to_string());
send_http_response(503, headers, format!("<h1>Node Offline</h1>").as_bytes().to_vec());
let message_json: serde_json::Value = match serde_json::from_slice(&request.ipc) {
Ok(v) => v,
Err(_) => {
//print_to_terminal(1, "http_proxy: failed to parse ipc JSON, skipping");
continue;
};
let Message::Request(request) = message else {
print_to_terminal(0, "http_proxy: got unexpected message");
continue;
};
let message_json: serde_json::Value = match serde_json::from_slice(&request.ipc) {
Ok(v) => v,
Err(_) => {
print_to_terminal(1, "http_proxy: failed to parse ipc JSON, skipping");
continue;
}
};
print_to_terminal(
1,
format!("http_proxy: got request: {}", message_json).as_str(),
);
if message_json["path"] == "/" && message_json["method"] == "GET" {
send_response(
&Response {
inherit: false,
ipc: serde_json::json!({
"action": "response",
"status": 200,
"headers": {
"Content-Type": "text/html",
},
})
.to_string()
.as_bytes()
.to_vec(),
metadata: None,
},
Some(&Payload {
mime: Some("text/html".to_string()),
bytes: PROXY_HOME_PAGE
.replace("${our}", &our.node)
.as_bytes()
.to_vec(),
}),
);
} else if message_json["path"] == "/list" && message_json["method"] == "GET" {
send_response(
&Response {
inherit: false,
ipc: serde_json::json!({
"action": "response",
"status": 200,
"headers": {
"Content-Type": "application/json",
},
})
.to_string()
.as_bytes()
.to_vec(),
metadata: None,
},
Some(&Payload {
mime: Some("application/json".to_string()),
bytes: serde_json::json!({"registrations": registrations})
.to_string()
.as_bytes()
.to_vec(),
}),
);
} else if message_json["path"] == "/register" && message_json["method"] == "POST" {
let mut status = 204;
let Some(payload) = get_payload() else {
print_to_terminal(1, "/register POST with no bytes");
continue;
};
let body: serde_json::Value = match serde_json::from_slice(&payload.bytes) {
Ok(s) => s,
Err(e) => {
print_to_terminal(1, format!("Bad body format: {}", e).as_str());
continue;
}
};
let username = body["username"].as_str().unwrap_or("");
print_to_terminal(1, format!("Register proxy for: {}", username).as_str());
if !username.is_empty() {
registrations.insert(username.to_string(), "foo".to_string());
} else {
status = 400;
}
send_response(
&Response {
inherit: false,
ipc: serde_json::json!({
"action": "response",
"status": status,
"headers": {
"Content-Type": "text/html",
},
})
.to_string()
.as_bytes()
.to_vec(),
metadata: None,
},
Some(&Payload {
mime: Some("text/html".to_string()),
bytes: (if status == 400 {
"Bad Request"
} else {
"Success"
})
.to_string()
.as_bytes()
.to_vec(),
}),
);
} else if message_json["path"] == "/register" && message_json["method"] == "DELETE" {
print_to_terminal(1, "HERE IN /register to delete something");
let username = message_json["query_params"]["username"]
.as_str()
.unwrap_or("");
let mut status = 204;
if !username.is_empty() {
registrations.remove(username);
} else {
status = 400;
}
send_response(
&Response {
inherit: false,
ipc: serde_json::json!({
"action": "response",
"status": status,
"headers": {
"Content-Type": "text/html",
},
})
.to_string()
.as_bytes()
.to_vec(),
metadata: None,
},
Some(&Payload {
mime: Some("text/html".to_string()),
bytes: (if status == 400 {
"Bad Request"
} else {
"Success"
})
.to_string()
.as_bytes()
.to_vec(),
}),
);
} else if message_json["path"] == "/serve/:username/*" {
let username = message_json["url_params"]["username"]
.as_str()
.unwrap_or("");
let raw_path = message_json["raw_path"].as_str().unwrap_or("");
print_to_terminal(1, format!("proxy for user: {}", username).as_str());
if username.is_empty() || raw_path.is_empty() {
send_not_found();
} else if !registrations.contains_key(username) {
send_response(
&Response {
inherit: false,
ipc: json!({
"action": "response",
"status": 403,
"headers": {
"Content-Type": "text/html",
},
})
.to_string()
.as_bytes()
.to_vec(),
metadata: None,
},
Some(&Payload {
mime: Some("text/html".to_string()),
bytes: "Not Authorized".to_string().as_bytes().to_vec(),
}),
);
} else {
let path_parts: Vec<&str> = raw_path.split('/').collect();
let mut proxied_path = "/".to_string();
if let Some(pos) = path_parts.iter().position(|&x| x == "serve") {
proxied_path = format!("/{}", path_parts[pos + 2..].join("/"));
print_to_terminal(1, format!("Path to proxy: {}", proxied_path).as_str());
}
let payload = get_payload();
send_request(
&Address {
node: username.into(),
process: ProcessId::from_str("http_server:sys:uqbar").unwrap(),
},
&Request {
inherit: true,
expects_response: None,
ipc: json!({
"method": message_json["method"],
"path": proxied_path,
"headers": message_json["headers"],
"proxy_path": raw_path,
"query_params": message_json["query_params"],
})
.to_string()
.as_bytes()
.to_vec(),
metadata: None,
},
None,
payload.as_ref(),
);
}
} else {
send_not_found();
}
};
//print_to_terminal(
// 1,
// format!("http_proxy: got request: {}", message_json).as_str(),
//);
if message_json["path"] == "/" && message_json["method"] == "GET" {
Response::new()
.ipc(
&json!({
"action": "response",
"status": 200,
"headers": {
"Content-Type": "text/html",
},
}),
serialize_json_message,
)?
.payload(Payload {
mime: Some("text/html".to_string()),
bytes: PROXY_HOME_PAGE
.replace("${our}", &our.node)
.as_bytes()
.to_vec(),
})
.send()?;
} else if message_json["path"] == "/list" && message_json["method"] == "GET" {
Response::new()
.ipc(
&json!({
"action": "response",
"status": 200,
"headers": {
"Content-Type": "application/json",
},
}),
serialize_json_message,
)?
.payload(Payload {
mime: Some("application/json".to_string()),
bytes: serde_json::json!({"registrations": registrations})
.to_string()
.as_bytes()
.to_vec(),
})
.send()?;
} else if message_json["path"] == "/register" && message_json["method"] == "POST" {
let mut status = 204;
let Some(payload) = get_payload() else {
//print_to_terminal(1, "/register POST with no bytes");
continue;
};
let body: serde_json::Value = match serde_json::from_slice(&payload.bytes) {
Ok(s) => s,
Err(e) => {
//print_to_terminal(1, format!("Bad body format: {}", e).as_str());
continue;
}
};
let username = body["username"].as_str().unwrap_or("");
//print_to_terminal(1, format!("Register proxy for: {}", username).as_str());
if !username.is_empty() {
registrations.insert(username.to_string(), "foo".to_string());
} else {
status = 400;
}
Response::new()
.ipc(
&json!({
"action": "response",
"status": 200,
"headers": {
"Content-Type": "text/html",
},
}),
serialize_json_message,
)?
.payload(Payload {
mime: Some("text/html".to_string()),
bytes: (if status == 400 {
"Bad Request"
} else {
"Success"
})
.to_string()
.as_bytes()
.to_vec(),
})
.send()?;
} else if message_json["path"] == "/register" && message_json["method"] == "DELETE" {
//print_to_terminal(1, "HERE IN /register to delete something");
let username = message_json["query_params"]["username"]
.as_str()
.unwrap_or("");
let mut status = 204;
if !username.is_empty() {
registrations.remove(username);
} else {
status = 400;
}
Response::new()
.ipc(
&json!({
"action": "response",
"status": status,
"headers": {
"Content-Type": "text/html",
},
}),
serialize_json_message,
)?
.payload(Payload {
mime: Some("text/html".to_string()),
bytes: (if status == 400 {
"Bad Request"
} else {
"Success"
})
.to_string()
.as_bytes()
.to_vec(),
})
.send()?;
} else if message_json["path"] == "/serve/:username/*" {
let username = message_json["url_params"]["username"]
.as_str()
.unwrap_or("");
let raw_path = message_json["raw_path"].as_str().unwrap_or("");
//print_to_terminal(1, format!("proxy for user: {}", username).as_str());
if username.is_empty() || raw_path.is_empty() {
send_not_found()?;
} else if !registrations.contains_key(username) {
Response::new()
.ipc(
&json!({
"action": "response",
"status": 403,
"headers": {
"Content-Type": "text/html",
},
}),
serialize_json_message,
)?
.payload(Payload {
mime: Some("text/html".to_string()),
bytes: "Not Authorized".to_string().as_bytes().to_vec(),
})
.send()?;
} else {
let path_parts: Vec<&str> = raw_path.split('/').collect();
let mut proxied_path = "/".to_string();
if let Some(pos) = path_parts.iter().position(|&x| x == "serve") {
proxied_path = format!("/{}", path_parts[pos + 2..].join("/"));
//print_to_terminal(1, format!("Path to proxy: {}", proxied_path).as_str());
}
Request::new()
.target(Address::new(&username, "http_server:sys:uqbar")?)?
.inherit(true)
.ipc(
&json!({
"method": message_json["method"],
"path": proxied_path,
"headers": message_json["headers"],
"proxy_path": raw_path,
"query_params": message_json["query_params"],
}),
serialize_json_message,
)?
.send()?;
}
} else {
send_not_found()?;
}
}
}

View File

@ -1 +0,0 @@
../../../src/process_lib.rs

View File

@ -17,12 +17,6 @@ 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"
@ -30,28 +24,10 @@ 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",
]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "equivalent"
@ -60,12 +36,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "form_urlencoded"
version = "1.2.0"
name = "getrandom"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652"
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
dependencies = [
"percent-encoding",
"cfg-if",
"libc",
"wasi",
]
[[package]]
@ -89,16 +67,6 @@ 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"
@ -122,10 +90,10 @@ version = "0.1.0"
dependencies = [
"anyhow",
"bincode",
"cargo-component-bindings",
"serde",
"serde_json",
"thiserror",
"uqbar_process_lib",
"wit-bindgen",
]
@ -135,6 +103,12 @@ version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67"
[[package]]
name = "libc"
version = "0.2.150"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
[[package]]
name = "log"
version = "0.4.20"
@ -142,16 +116,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
[[package]]
name = "memchr"
version = "2.6.3"
name = "ppv-lite86"
version = "0.2.17"
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"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "proc-macro2"
@ -162,17 +130,6 @@ 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"
@ -182,6 +139,36 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
name = "ryu"
version = "1.0.15"
@ -271,51 +258,12 @@ dependencies = [
"syn",
]
[[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"
@ -329,40 +277,41 @@ 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"
name = "uqbar_process_lib"
version = "0.2.0"
dependencies = [
"form_urlencoded",
"idna",
"percent-encoding",
"anyhow",
"bincode",
"rand",
"serde",
"wit-bindgen",
]
[[package]]
name = "version_check"
version = "0.9.4"
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-encoder"
version = "0.32.0"
version = "0.36.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ba64e81215916eaeb48fee292f29401d69235d62d8b8fd92a7b2844ec5ae5f7"
checksum = "822b645bf4f2446b949776ffca47e2af60b167209ffb70814ef8779d299cd421"
dependencies = [
"leb128",
]
[[package]]
name = "wasm-metadata"
version = "0.10.3"
version = "0.10.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08dc59d1fa569150851542143ca79438ca56845ccb31696c70225c638e063471"
checksum = "2167ce53b2faa16a92c6cafd4942cff16c9a4fa0c5a5a0a41131ee4e49fc055f"
dependencies = [
"anyhow",
"indexmap",
"serde",
"serde_derive",
"serde_json",
"spdx",
"wasm-encoder",
@ -371,9 +320,9 @@ dependencies = [
[[package]]
name = "wasmparser"
version = "0.112.0"
version = "0.116.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e986b010f47fcce49cf8ea5d5f9e5d2737832f12b53ae8ae785bbe895d0877bf"
checksum = "a58e28b80dd8340cb07b8242ae654756161f6fc8d0038123d679b7b99964fa50"
dependencies = [
"indexmap",
"semver",
@ -381,19 +330,17 @@ dependencies = [
[[package]]
name = "wit-bindgen"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8a3e8e965dc50e6eb4410d9a11720719fadc6a1713803ea5f3be390b81c8279"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"bitflags 2.4.0",
"bitflags",
"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"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"anyhow",
"wit-component",
@ -402,54 +349,42 @@ dependencies = [
[[package]]
name = "wit-bindgen-rust"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "399c60e6ea8598d1380e792f13d557007834f0fb799fea6503408cbc5debb4ae"
version = "0.13.2"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
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"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"anyhow",
"proc-macro2",
"quote",
"syn",
"wit-bindgen-core",
"wit-bindgen-rust",
"wit-bindgen-rust-lib",
"wit-component",
]
[[package]]
name = "wit-component"
version = "0.14.0"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66d9f2d16dd55d1a372dcfd4b7a466ea876682a5a3cb97e71ec9eef04affa876"
checksum = "480cc1a078b305c1b8510f7c455c76cbd008ee49935f3a6c5fd5e937d8d95b1e"
dependencies = [
"anyhow",
"bitflags 2.4.0",
"bitflags",
"indexmap",
"log",
"serde",
"serde_derive",
"serde_json",
"wasm-encoder",
"wasm-metadata",
@ -459,16 +394,17 @@ dependencies = [
[[package]]
name = "wit-parser"
version = "0.11.0"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61e8b849bea13cc2315426b16efe6eb6813466d78f5fde69b0bb150c9c40e0dc"
checksum = "43771ee863a16ec4ecf9da0fc65c3bbd4a1235c8e3da5f094b562894843dfa76"
dependencies = [
"anyhow",
"id-arena",
"indexmap",
"log",
"pulldown-cmark",
"semver",
"serde",
"serde_derive",
"serde_json",
"unicode-xid",
"url",
]

View File

@ -13,11 +13,11 @@ 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"
thiserror = "1.0"
wit-bindgen = { version = "0.11.0", default_features = false }
uqbar_process_lib = { path = "../../../process_lib" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "5390bab780733f1660d14c254ec985df2816bf1d" }
[lib]
crate-type = ["cdylib"]

View File

@ -1 +0,0 @@
../../../../src/kernel_types.rs

View File

@ -1,22 +1,21 @@
cargo_component_bindings::generate!();
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
// use serde::{Deserialize, Serialize};
use bindings::component::uq_process::types::*;
use bindings::{
create_capability, get_capability, has_capability, print_to_terminal, receive, send_request,
send_response, spawn, Guest,
};
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;
wit_bindgen::generate!({
path: "../../../wit",
world: "process",
exports: {
world: Component,
},
});
mod kernel_types;
use kernel_types as kt;
mod key_value_types;
use key_value_types as kv;
mod process_lib;
struct Component;
const PREFIX: &str = "key_value-";
@ -41,30 +40,24 @@ fn make_db_cap(kind: &str, db: &str) -> String {
fn forward_if_have_cap(
our: &Address,
operation_type: &str,
// operation_type: OperationType,
db: &str,
ipc: Vec<u8>,
db_to_process: &mut DbToProcess,
) -> anyhow::Result<()> {
if has_capability(&make_db_cap(operation_type, db)) {
if wit::has_capability(&make_db_cap(operation_type, db)) {
// forward
let Some(process_id) = db_to_process.get(db) else {
return Err(kv::KeyValueError::DbDoesNotExist.into());
};
send_request(
&Address {
Request::new()
.target(wit::Address {
node: our.node.clone(),
process: process_id.clone(),
},
&Request {
inherit: true,
expects_response: None,
ipc,
metadata: None,
},
None,
None,
);
})?
// .target(Address::new(our.node.clone(), process_id.clone()))?
.inherit(true)
.ipc_bytes(ipc)
.send()?;
return Ok(());
} else {
// reject
@ -73,19 +66,18 @@ fn forward_if_have_cap(
}
fn handle_message(our: &Address, db_to_process: &mut DbToProcess) -> anyhow::Result<()> {
let (source, message) = receive().unwrap();
// let (source, message) = receive()?;
let (source, message) = wit::receive().unwrap();
if our.node != source.node {
return Err(kv::KeyValueError::RejectForeign.into());
}
match message {
Message::Response(_) => {
wit::Message::Response(_) => {
return Err(kv::KeyValueError::UnexpectedResponse.into());
}
Message::Request(Request { ipc, .. }) => {
match process_lib::parse_message_ipc(&ipc)? {
wit::Message::Request(wit::Request { ipc, .. }) => {
match serde_json::from_slice(&ipc)? {
kv::KeyValueMessage::New { ref db } => {
// TODO: make atomic
// (1): create vfs drive
@ -100,76 +92,58 @@ fn handle_message(our: &Address, db_to_process: &mut DbToProcess) -> anyhow::Res
// (1)
let vfs_address = Address {
node: our.node.clone(),
process: kt::ProcessId::new("vfs", "sys", "uqbar").en_wit(),
process: ProcessId::new("vfs", "sys", "uqbar"),
};
let vfs_drive = format!("{}{}", PREFIX, db);
let _ = process_lib::send_and_await_response(
&vfs_address,
false,
serde_json::to_vec(&kt::VfsRequest {
let _ = Request::new()
.target(vfs_address.clone())?
.ipc_bytes(serde_json::to_vec(&kt::VfsRequest {
drive: vfs_drive.clone(),
action: kt::VfsAction::New,
})
.unwrap(),
None,
None,
15,
)
.unwrap();
})?)
.send_and_await_response(15)??;
// (2)
let vfs_read = get_capability(&vfs_address, &make_vfs_cap("read", &vfs_drive))
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 =
get_capability(&vfs_address, &make_vfs_cap("write", &vfs_drive)).ok_or(
wit::get_capability(&vfs_address, &make_vfs_cap("write", &vfs_drive)).ok_or(
anyhow::anyhow!("New failed: no vfs 'write' capability found"),
)?;
let spawned_process_id = match spawn(
let spawned_process_id = match wit::spawn(
None,
"/key_value_worker.wasm",
&OnPanic::None, // TODO: notify us
&Capabilities::Some(vec![vfs_read, vfs_write]),
&wit::OnPanic::None, // TODO: notify us
&wit::Capabilities::Some(vec![vfs_read, vfs_write]),
false, // not public
) {
Ok(spawned_process_id) => spawned_process_id,
Err(e) => {
print_to_terminal(0, &format!("couldn't spawn: {}", e));
wit::print_to_terminal(0, &format!("couldn't spawn: {}", e));
panic!("couldn't spawn"); // TODO
}
};
// grant caps
create_capability(&source.process, &make_db_cap("read", db));
create_capability(&source.process, &make_db_cap("write", db));
wit::create_capability(&source.process, &make_db_cap("read", db));
wit::create_capability(&source.process, &make_db_cap("write", db));
// initialize worker
send_request(
&Address {
Request::new()
.target(wit::Address {
node: our.node.clone(),
process: spawned_process_id.clone(),
},
&Request {
inherit: false,
expects_response: None,
ipc: ipc.clone(),
metadata: None,
},
None,
None,
);
})?
.ipc_bytes(ipc.clone())
.send()?;
// (4)
db_to_process.insert(db.into(), spawned_process_id);
// TODO: persistence?
send_response(
&Response {
inherit: false,
ipc,
metadata: None,
},
None,
);
Response::new()
.ipc_bytes(ipc)
.send()?;
}
kv::KeyValueMessage::Write { ref db, .. } => {
forward_if_have_cap(our, "write", db, ipc, db_to_process)?;
@ -187,26 +161,24 @@ fn handle_message(our: &Address, db_to_process: &mut DbToProcess) -> anyhow::Res
}
}
struct Component;
impl Guest for Component {
fn init(our: Address) {
print_to_terminal(0, "key_value: begin");
fn init(our: String) {
wit::print_to_terminal(0, "key_value: begin");
let our = Address::from_str(&our).unwrap();
let mut db_to_process: DbToProcess = HashMap::new();
loop {
match handle_message(&our, &mut db_to_process) {
Ok(()) => {}
Err(e) => {
print_to_terminal(0, format!("key_value: error: {:?}", e,).as_str());
wit::print_to_terminal(0, format!("key_value: error: {:?}", e,).as_str());
if let Some(e) = e.downcast_ref::<kv::KeyValueError>() {
send_response(
&Response {
inherit: false,
ipc: serde_json::to_vec(&e).unwrap(),
metadata: None,
},
None,
);
Response::new()
.ipc_bytes(serde_json::to_vec(&e).unwrap())
.send()
.unwrap();
}
}
};

View File

@ -1 +0,0 @@
../../../../src/process_lib.rs

View File

@ -47,42 +47,12 @@ 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 = "cc"
version = "1.0.83"
@ -104,15 +74,6 @@ 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 = "getrandom"
version = "0.2.10"
@ -151,16 +112,6 @@ 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"
@ -184,11 +135,11 @@ version = "0.1.0"
dependencies = [
"anyhow",
"bincode",
"cargo-component-bindings",
"redb",
"serde",
"serde_json",
"thiserror",
"uqbar_process_lib",
"wit-bindgen",
]
@ -240,12 +191,6 @@ version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
[[package]]
name = "percent-encoding"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94"
[[package]]
name = "pin-project-lite"
version = "0.2.13"
@ -267,17 +212,6 @@ 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 = "pyo3-build-config"
version = "0.19.2"
@ -442,21 +376,6 @@ dependencies = [
"syn",
]
[[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 = "tokio"
version = "1.32.0"
@ -479,36 +398,12 @@ dependencies = [
"syn",
]
[[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"
@ -522,22 +417,16 @@ 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"
name = "uqbar_process_lib"
version = "0.2.0"
dependencies = [
"form_urlencoded",
"idna",
"percent-encoding",
"anyhow",
"bincode",
"rand",
"serde",
"wit-bindgen",
]
[[package]]
name = "version_check"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
@ -546,22 +435,23 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-encoder"
version = "0.32.0"
version = "0.36.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ba64e81215916eaeb48fee292f29401d69235d62d8b8fd92a7b2844ec5ae5f7"
checksum = "822b645bf4f2446b949776ffca47e2af60b167209ffb70814ef8779d299cd421"
dependencies = [
"leb128",
]
[[package]]
name = "wasm-metadata"
version = "0.10.3"
version = "0.10.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08dc59d1fa569150851542143ca79438ca56845ccb31696c70225c638e063471"
checksum = "2167ce53b2faa16a92c6cafd4942cff16c9a4fa0c5a5a0a41131ee4e49fc055f"
dependencies = [
"anyhow",
"indexmap",
"serde",
"serde_derive",
"serde_json",
"spdx",
"wasm-encoder",
@ -570,9 +460,9 @@ dependencies = [
[[package]]
name = "wasmparser"
version = "0.112.0"
version = "0.116.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e986b010f47fcce49cf8ea5d5f9e5d2737832f12b53ae8ae785bbe895d0877bf"
checksum = "a58e28b80dd8340cb07b8242ae654756161f6fc8d0038123d679b7b99964fa50"
dependencies = [
"indexmap",
"semver",
@ -580,19 +470,17 @@ dependencies = [
[[package]]
name = "wit-bindgen"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8a3e8e965dc50e6eb4410d9a11720719fadc6a1713803ea5f3be390b81c8279"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"bitflags 2.4.0",
"bitflags",
"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"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"anyhow",
"wit-component",
@ -601,54 +489,42 @@ dependencies = [
[[package]]
name = "wit-bindgen-rust"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "399c60e6ea8598d1380e792f13d557007834f0fb799fea6503408cbc5debb4ae"
version = "0.13.2"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
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"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"anyhow",
"proc-macro2",
"quote",
"syn",
"wit-bindgen-core",
"wit-bindgen-rust",
"wit-bindgen-rust-lib",
"wit-component",
]
[[package]]
name = "wit-component"
version = "0.14.0"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66d9f2d16dd55d1a372dcfd4b7a466ea876682a5a3cb97e71ec9eef04affa876"
checksum = "480cc1a078b305c1b8510f7c455c76cbd008ee49935f3a6c5fd5e937d8d95b1e"
dependencies = [
"anyhow",
"bitflags 2.4.0",
"bitflags",
"indexmap",
"log",
"serde",
"serde_derive",
"serde_json",
"wasm-encoder",
"wasm-metadata",
@ -658,16 +534,17 @@ dependencies = [
[[package]]
name = "wit-parser"
version = "0.11.0"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61e8b849bea13cc2315426b16efe6eb6813466d78f5fde69b0bb150c9c40e0dc"
checksum = "43771ee863a16ec4ecf9da0fc65c3bbd4a1235c8e3da5f094b562894843dfa76"
dependencies = [
"anyhow",
"id-arena",
"indexmap",
"log",
"pulldown-cmark",
"semver",
"serde",
"serde_derive",
"serde_json",
"unicode-xid",
"url",
]

View File

@ -13,12 +13,12 @@ lto = true
[dependencies]
anyhow = "1.0"
bincode = "1.3.3"
cargo-component-bindings = { git = "https://github.com/bytecodealliance/cargo-component" }
redb = { git = "https://github.com/uqbar-dao/redb", rev = "8e192d9" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "1.0"
wit-bindgen = { version = "0.11.0", default_features = false }
uqbar_process_lib = { path = "../../../process_lib" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "5390bab780733f1660d14c254ec985df2816bf1d" }
[lib]
crate-type = ["cdylib"]

View File

@ -1 +0,0 @@
../../../../src/kernel_types.rs

View File

@ -1,28 +1,29 @@
cargo_component_bindings::generate!();
use std::collections::HashMap;
use redb::ReadableTable;
use serde::{Deserialize, Serialize};
use bindings::component::uq_process::types::*;
use bindings::{get_payload, Guest, print_to_terminal, receive, send_and_await_response, send_response};
use uqbar_process_lib::{Address, ProcessId, Response};
use uqbar_process_lib::uqbar::process::standard as wit;
wit_bindgen::generate!({
path: "../../../wit",
world: "process",
exports: {
world: Component,
},
});
mod kernel_types;
use kernel_types as kt;
mod key_value_types;
use key_value_types as kv;
mod process_lib;
struct Component;
const PREFIX: &str = "key_value-";
const TABLE: redb::TableDefinition<&[u8], &[u8]> = redb::TableDefinition::new("process");
fn get_payload_wrapped() -> Option<(Option<String>, Vec<u8>)> {
match get_payload() {
match wit::get_payload() {
None => None,
Some(Payload { mime, bytes }) => Some((mime, bytes)),
Some(wit::Payload { mime, bytes }) => Some((mime, bytes)),
}
}
@ -38,21 +39,21 @@ fn send_and_await_response_wrapped(
) -> (Vec<u8>, Option<String>) {
let payload = match payload {
None => None,
Some((mime, bytes)) => Some(Payload { mime, bytes }),
Some((mime, bytes)) => Some(wit::Payload { mime, bytes }),
};
let (
_,
Message::Response((Response { ipc, metadata, .. }, _)),
) = send_and_await_response(
&Address {
wit::Message::Response((wit::Response { ipc, metadata, .. }, _)),
) = wit::send_and_await_response(
&wit::Address {
node: target_node,
process: kt::ProcessId::new(
process: ProcessId::new(
&target_process,
&target_package,
&target_publisher,
).en_wit(),
),
},
&Request {
&wit::Request {
inherit: false,
expects_response: Some(timeout),
ipc: request_ipc,
@ -69,20 +70,19 @@ fn send_and_await_response_wrapped(
}
fn handle_message (
our: &Address,
our: &wit::Address,
db_handle: &mut Option<redb::Database>,
) -> anyhow::Result<()> {
let (source, message) = receive().unwrap();
// let (source, message) = receive()?;
let (source, message) = wit::receive().unwrap();
if our.node != source.node {
return Err(kv::KeyValueError::RejectForeign.into());
}
match message {
Message::Response(_) => { unimplemented!() },
Message::Request(Request { inherit: _ , expects_response: _, ipc, metadata: _ }) => {
match process_lib::parse_message_ipc(&ipc)? {
wit::Message::Response(_) => { unimplemented!() },
wit::Message::Request(wit::Request { ipc, .. }) => {
match serde_json::from_slice(&ipc)? {
kv::KeyValueMessage::New { db } => {
let vfs_drive = format!("{}{}", PREFIX, db);
match db_handle {
@ -90,7 +90,7 @@ fn handle_message (
return Err(kv::KeyValueError::DbAlreadyExists.into());
},
None => {
print_to_terminal(0, "key_value_worker: Create");
wit::print_to_terminal(1, "key_value_worker: Create");
*db_handle = Some(redb::Database::create(
format!("/{}.redb", db),
our.node.clone(),
@ -98,7 +98,7 @@ fn handle_message (
get_payload_wrapped,
send_and_await_response_wrapped,
)?);
print_to_terminal(0, "key_value_worker: Create done");
wit::print_to_terminal(1, "key_value_worker: Create done");
},
}
},
@ -107,7 +107,8 @@ fn handle_message (
return Err(kv::KeyValueError::DbDoesNotExist.into());
};
let Payload { mime: _, ref bytes } = get_payload().ok_or(anyhow::anyhow!("couldnt get bytes for Write"))?;
let wit::Payload { ref bytes, .. } = wit::get_payload()
.ok_or(anyhow::anyhow!("couldnt get bytes for Write"))?;
let write_txn = db_handle.begin_write()?;
{
@ -116,14 +117,9 @@ fn handle_message (
}
write_txn.commit()?;
send_response(
&Response {
inherit: false,
ipc,
metadata: None,
},
None,
);
Response::new()
.ipc_bytes(ipc)
.send()?;
},
kv::KeyValueMessage::Read { ref key, .. } => {
let Some(db_handle) = db_handle else {
@ -136,36 +132,31 @@ fn handle_message (
match table.get(&key[..])? {
None => {
send_response(
&Response {
inherit: false,
ipc,
metadata: None,
},
None,
);
Response::new()
.ipc_bytes(ipc)
.send()?;
},
Some(v) => {
let bytes = v.value().to_vec();
print_to_terminal(
wit::print_to_terminal(
1,
&format!(
"key_value_worker: key, val: {:?}, {}",
key,
if bytes.len() < 100 { format!("{:?}", bytes) } else { "<elided>".into() },
if bytes.len() < 100 {
format!("{:?}", bytes)
} else {
"<elided>".into()
},
),
);
send_response(
&Response {
inherit: false,
ipc,
metadata: None,
},
Some(&Payload {
Response::new()
.ipc_bytes(ipc)
.payload(wit::Payload {
mime: None,
bytes,
}),
);
})
.send()?;
},
};
},
@ -179,29 +170,27 @@ fn handle_message (
}
}
struct Component;
impl Guest for Component {
fn init(our: Address) {
print_to_terminal(1, "key_value_worker: begin");
fn init(our: String) {
wit::print_to_terminal(1, "key_value_worker: begin");
let our = Address::from_str(&our).unwrap();
let mut db_handle: Option<redb::Database> = None;
loop {
match handle_message(&our, &mut db_handle) {
Ok(()) => {},
Err(e) => {
print_to_terminal(0, format!(
wit::print_to_terminal(0, format!(
"key_value_worker: error: {:?}",
e,
).as_str());
if let Some(e) = e.downcast_ref::<kv::KeyValueError>() {
send_response(
&Response {
inherit: false,
ipc: serde_json::to_vec(&e).unwrap(),
metadata: None,
},
None,
);
Response::new()
.ipc_bytes(serde_json::to_vec(&e).unwrap())
.send()
.unwrap();
}
panic!("");
},

View File

@ -1 +0,0 @@
../../../../src/process_lib.rs

460
modules/orgs/Cargo.lock generated
View File

@ -1,460 +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 = "base64"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
[[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#36c221e41db3e87dec4c82eadcb9bc8f37626533"
dependencies = [
"cargo-component-macro",
"wit-bindgen",
]
[[package]]
name = "cargo-component-macro"
version = "0.1.0"
source = "git+https://github.com/bytecodealliance/cargo-component#36c221e41db3e87dec4c82eadcb9bc8f37626533"
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 = "orgs"
version = "0.1.0"
dependencies = [
"anyhow",
"base64",
"bincode",
"cargo-component-bindings",
"serde",
"serde_json",
"wit-bindgen",
]
[[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.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328"
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.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65"
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.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9caece70c63bfba29ec2fed841a09851b14a235c60010fa4de58089b6c025668"
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.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[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",
]

View File

@ -1,31 +0,0 @@
[package]
name = "orgs"
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 }
base64 = "0.13"
[lib]
crate-type = ["cdylib"]
[package.metadata.component]
package = "component:uq-process"
[package.metadata.component.target]
path = "wit"
[package.metadata.component.dependencies]

View File

@ -1,12 +0,0 @@
[
{
"process_name": "orgs",
"process_wasm_path": "/orgs.wasm",
"on_panic": "Restart",
"request_networking": true,
"request_messaging": [
"http_bindings:http_bindings:uqbar"
],
"public": false
}
]

View File

@ -1,5 +0,0 @@
{
"package": "orgs",
"publisher": "uqbar",
"version": [0, 1, 0]
}

File diff suppressed because it is too large Load Diff

View File

@ -1 +0,0 @@
../../../src/process_lib.rs

View File

@ -1,3 +0,0 @@
# This file is automatically generated by cargo-component.
# It is not intended for manual editing.
version = 1

View File

@ -23,9 +23,9 @@ dependencies = [
[[package]]
name = "alloy-rlp"
version = "0.3.2"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f938f00332d63a5b0ac687bd6f46d03884638948921d9f8b50c59563d421ae25"
checksum = "cc0fac0fc16baf1f63f78b47c3d24718f3619b0714076f6a02957d808d52cbef"
dependencies = [
"arrayvec",
"bytes",
@ -42,7 +42,7 @@ dependencies = [
"heck",
"proc-macro2",
"quote",
"syn 2.0.28",
"syn 2.0.39",
"syn-solidity",
"tiny-keccak",
]
@ -61,9 +61,9 @@ dependencies = [
[[package]]
name = "anyhow"
version = "1.0.72"
version = "1.0.75"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b13c32d80ecc7ab747b80c3784bce54ee8a7a0cc4fbda9bf4cda2cf6fe90854"
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
[[package]]
name = "arrayvec"
@ -109,52 +109,21 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.3.3"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42"
checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
[[package]]
name = "byteorder"
version = "1.4.3"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "bytes"
version = "1.4.0"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be"
[[package]]
name = "cargo-component-bindings"
version = "0.1.0"
source = "git+https://github.com/bytecodealliance/cargo-component#d14cef65719d0d186218d1dfe5f04bbbf295dc80"
dependencies = [
"cargo-component-macro",
"wit-bindgen 0.9.0",
]
[[package]]
name = "cargo-component-macro"
version = "0.1.0"
source = "git+https://github.com/bytecodealliance/cargo-component#d14cef65719d0d186218d1dfe5f04bbbf295dc80"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.28",
"wit-bindgen-core",
"wit-bindgen-rust",
"wit-component 0.13.1",
]
[[package]]
name = "cc"
version = "1.0.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
dependencies = [
"libc",
]
checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223"
[[package]]
name = "cfg-if"
@ -164,13 +133,14 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "const-hex"
version = "1.8.0"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08849ed393c907c90016652a01465a12d86361cd38ad2a7de026c56a520cc259"
checksum = "a5104de16b218eddf8e34ffe2f86f74bfa4e61e95a1b89732fccf6325efd0557"
dependencies = [
"cfg-if",
"cpufeatures",
"hex",
"proptest",
"serde",
]
@ -182,9 +152,9 @@ checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
[[package]]
name = "cpufeatures"
version = "0.2.9"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1"
checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0"
dependencies = [
"libc",
]
@ -222,30 +192,19 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "errno"
version = "0.3.3"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "136526188508e25c6fef639d7927dfb3e0e3084488bf202267829cf7fc23dbdd"
checksum = "ac3e13f66a2f95e32a39eaa81f6b95d42878ca0e1db0c7543723dfe12557e860"
dependencies = [
"errno-dragonfly",
"libc",
"windows-sys",
]
[[package]]
name = "errno-dragonfly"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf"
dependencies = [
"cc",
"libc",
]
[[package]]
name = "fastrand"
version = "2.0.0"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764"
checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5"
[[package]]
name = "fnv"
@ -253,15 +212,6 @@ version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[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 = "getrandom"
version = "0.2.10"
@ -275,9 +225,9 @@ dependencies = [
[[package]]
name = "hashbrown"
version = "0.14.0"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156"
[[package]]
name = "heck"
@ -306,21 +256,11 @@ 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"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d"
checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f"
dependencies = [
"equivalent",
"hashbrown",
@ -329,9 +269,9 @@ dependencies = [
[[package]]
name = "itoa"
version = "1.0.8"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b02a5381cc465bd3041d84623d0fa3b66738b52b8e2fc3bab8ad63ab032f4a"
checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
[[package]]
name = "lazy_static"
@ -347,39 +287,33 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67"
[[package]]
name = "libc"
version = "0.2.147"
version = "0.2.150"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
[[package]]
name = "libm"
version = "0.2.7"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7012b1bbb0719e1097c47611d3898568c546d597c2e74d66f6087edd5233ff4"
checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058"
[[package]]
name = "linux-raw-sys"
version = "0.4.5"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503"
checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f"
[[package]]
name = "log"
version = "0.4.19"
version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4"
[[package]]
name = "memchr"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
[[package]]
name = "num-traits"
version = "0.2.16"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2"
checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c"
dependencies = [
"autocfg",
"libm",
@ -391,12 +325,6 @@ version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
[[package]]
name = "percent-encoding"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94"
[[package]]
name = "ppv-lite86"
version = "0.2.17"
@ -405,22 +333,22 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "proc-macro2"
version = "1.0.66"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
dependencies = [
"unicode-ident",
]
[[package]]
name = "proptest"
version = "1.2.0"
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e35c06b98bf36aba164cc17cb25f7e232f5c4aeea73baa14b8a9f0d92dbfa65"
checksum = "7c003ac8c77cb07bb74f5f198bce836a689bcd5a42574612bf14d17bfd08c20e"
dependencies = [
"bit-set",
"bitflags 1.3.2",
"byteorder",
"bit-vec",
"bitflags 2.4.1",
"lazy_static",
"num-traits",
"rand",
@ -432,17 +360,6 @@ dependencies = [
"unarray",
]
[[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 = "qns_indexer"
version = "0.1.0"
@ -451,13 +368,12 @@ dependencies = [
"alloy-sol-types",
"anyhow",
"bincode",
"cargo-component-bindings",
"hex",
"rmp-serde",
"serde",
"serde_json",
"thiserror",
"wit-bindgen 0.11.0",
"uqbar_process_lib",
"wit-bindgen",
]
[[package]]
@ -468,9 +384,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
[[package]]
name = "quote"
version = "1.0.32"
version = "1.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965"
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
dependencies = [
"proc-macro2",
]
@ -516,18 +432,40 @@ dependencies = [
[[package]]
name = "redox_syscall"
version = "0.3.5"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29"
checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa"
dependencies = [
"bitflags 1.3.2",
]
[[package]]
name = "regex-syntax"
version = "0.6.29"
version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da"
[[package]]
name = "rmp"
version = "0.8.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f9860a6cc38ed1da53456442089b4dfa35e7cedaa326df63017af88385e6b20"
dependencies = [
"byteorder",
"num-traits",
"paste",
]
[[package]]
name = "rmp-serde"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bffea85eea980d8a74453e5d02a8d93028f3c34725de143085a844ebe953258a"
dependencies = [
"byteorder",
"rmp",
"serde",
]
[[package]]
name = "rmp"
@ -553,9 +491,9 @@ dependencies = [
[[package]]
name = "ruint"
version = "1.10.1"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95294d6e3a6192f3aabf91c38f56505a625aa495533442744185a36d75a790c4"
checksum = "724fd11728a3804e9944b14cab63825024c40bf42f8af87c8b5d97c4bbacf426"
dependencies = [
"proptest",
"rand",
@ -582,11 +520,11 @@ dependencies = [
[[package]]
name = "rustix"
version = "0.38.8"
version = "0.38.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19ed4fa021d81c8392ce04db050a3da9a60299050b7ae1cf482d862b54a7218f"
checksum = "2b426b0506e5d50a7d8dafcf2e81471400deb602392c7dd110815afb4eaf02a3"
dependencies = [
"bitflags 2.3.3",
"bitflags 2.4.1",
"errno",
"libc",
"linux-raw-sys",
@ -607,41 +545,41 @@ dependencies = [
[[package]]
name = "ryu"
version = "1.0.14"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe232bdf6be8c8de797b22184ee71118d63780ea42ac85b61d1baa6d3b782ae9"
checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
[[package]]
name = "semver"
version = "1.0.18"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918"
checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090"
[[package]]
name = "serde"
version = "1.0.167"
version = "1.0.191"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7daf513456463b42aa1d94cff7e0c24d682b429f020b9afa4f5ba5c40a22b237"
checksum = "a834c4821019838224821468552240d4d95d14e751986442c816572d39a080c9"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.167"
version = "1.0.191"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b69b106b68bc8054f0e974e70d19984040f8a5cf9215ca82626ea4853f82c4b9"
checksum = "46fa52d5646bce91b680189fe5b1c049d2ea38dabb4e2e7c8d00ca12cfbfbcfd"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.28",
"syn 2.0.39",
]
[[package]]
name = "serde_json"
version = "1.0.100"
version = "1.0.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f1e14e89be7aa4c4b78bdbdc9eb5bf8517829a600ae8eaa39a6e1d960b5185c"
checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b"
dependencies = [
"itoa",
"ryu",
@ -650,9 +588,9 @@ dependencies = [
[[package]]
name = "smallvec"
version = "1.11.0"
version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9"
checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a"
[[package]]
name = "smol_str"
@ -685,9 +623,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.28"
version = "2.0.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04361975b3f5e348b2189d8dc55bc942f278b2d482a6a0365de5bdd62d351567"
checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a"
dependencies = [
"proc-macro2",
"quote",
@ -703,14 +641,14 @@ dependencies = [
"paste",
"proc-macro2",
"quote",
"syn 2.0.28",
"syn 2.0.39",
]
[[package]]
name = "tempfile"
version = "3.8.0"
version = "3.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef"
checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5"
dependencies = [
"cfg-if",
"fastrand",
@ -719,26 +657,6 @@ dependencies = [
"windows-sys",
]
[[package]]
name = "thiserror"
version = "1.0.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d6d7a740b8a666a7e828dd00da9c0dc290dff53154ea77ac109281de90589b7"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49922ecae66cc8a249b77e68d1d0623c1b2c514f0060c27cdc68bd62a1219d35"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.28",
]
[[package]]
name = "tiny-keccak"
version = "2.0.2"
@ -748,56 +666,17 @@ dependencies = [
"crunchy",
]
[[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 = "unarray"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94"
[[package]]
name = "unicase"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
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"
version = "1.0.12"
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",
]
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "unicode-segmentation"
@ -812,14 +691,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]]
name = "url"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb"
name = "uqbar_process_lib"
version = "0.2.0"
dependencies = [
"form_urlencoded",
"idna",
"percent-encoding",
"anyhow",
"bincode",
"rand",
"serde",
"wit-bindgen",
]
[[package]]
@ -828,12 +707,6 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "version_check"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "wait-timeout"
version = "0.2.0"
@ -851,67 +724,34 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-encoder"
version = "0.30.0"
version = "0.36.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2f8e9778e04cbf44f58acc301372577375a666b966c50b03ef46144f80436a8"
dependencies = [
"leb128",
]
[[package]]
name = "wasm-encoder"
version = "0.31.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41763f20eafed1399fff1afb466496d3a959f58241436cfdc17e3f5ca954de16"
checksum = "822b645bf4f2446b949776ffca47e2af60b167209ffb70814ef8779d299cd421"
dependencies = [
"leb128",
]
[[package]]
name = "wasm-metadata"
version = "0.9.0"
version = "0.10.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d51db59397fc650b5f2fc778e4a5c4456cd856bed7fc1ec15f8d3e28229dc463"
checksum = "2167ce53b2faa16a92c6cafd4942cff16c9a4fa0c5a5a0a41131ee4e49fc055f"
dependencies = [
"anyhow",
"indexmap",
"serde",
"serde_derive",
"serde_json",
"spdx",
"wasm-encoder 0.30.0",
"wasmparser 0.108.0",
]
[[package]]
name = "wasm-metadata"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be44e148f09a188971ec512250b3ae136029e2df586dd740586ce76a17ee657d"
dependencies = [
"anyhow",
"indexmap",
"serde",
"serde_json",
"spdx",
"wasm-encoder 0.31.1",
"wasmparser 0.110.0",
"wasm-encoder",
"wasmparser",
]
[[package]]
name = "wasmparser"
version = "0.108.0"
version = "0.116.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76c956109dcb41436a39391139d9b6e2d0a5e0b158e1293ef352ec977e5e36c5"
dependencies = [
"indexmap",
"semver",
]
[[package]]
name = "wasmparser"
version = "0.110.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1dfcdb72d96f01e6c85b6bf20102e7423bdbaad5c337301bab2bbf253d26413c"
checksum = "a58e28b80dd8340cb07b8242ae654756161f6fc8d0038123d679b7b99964fa50"
dependencies = [
"indexmap",
"semver",
@ -985,118 +825,83 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
[[package]]
name = "wit-bindgen"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f5c3d15a04ce994fad2c5442a754b404ab1fee23c903a04a560f84f94fdf63c0"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"bitflags 2.3.3",
"bitflags 2.4.1",
"wit-bindgen-rust-macro",
]
[[package]]
name = "wit-bindgen"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8a3e8e965dc50e6eb4410d9a11720719fadc6a1713803ea5f3be390b81c8279"
dependencies = [
"bitflags 2.3.3",
]
[[package]]
name = "wit-bindgen-core"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9658ec54d4a3c9e2f079bc65a131093337595b595fbf82f805008469838cdea"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"anyhow",
"wit-component 0.12.0",
"wit-component",
"wit-parser",
]
[[package]]
name = "wit-bindgen-rust"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21ae6a6198ba9765771b977e2af985a0d5ac71b59f999da5c4ee1c7bbd8ca8dc"
dependencies = [
"heck",
"wasm-metadata 0.9.0",
"wit-bindgen-core",
"wit-bindgen-rust-lib",
"wit-component 0.12.0",
]
[[package]]
name = "wit-bindgen-rust-lib"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c31de8c6c77cac1fd4927c7584d1314cd5e838cfb40b53333d6dffc7a132dda"
version = "0.13.2"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"anyhow",
"heck",
"wasm-metadata",
"wit-bindgen-core",
"wit-component",
]
[[package]]
name = "wit-bindgen-rust-macro"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a2abe5c7c4c08468d01590aa96c8a684dd94fb9241a248af88eef7edac61e43"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"anyhow",
"proc-macro2",
"syn 2.0.28",
"quote",
"syn 2.0.39",
"wit-bindgen-core",
"wit-bindgen-rust",
"wit-bindgen-rust-lib",
"wit-component 0.12.0",
"wit-component",
]
[[package]]
name = "wit-component"
version = "0.12.0"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "253bd426c532f1cae8c633c517c63719920535f3a7fada3589de40c5b734e393"
checksum = "480cc1a078b305c1b8510f7c455c76cbd008ee49935f3a6c5fd5e937d8d95b1e"
dependencies = [
"anyhow",
"bitflags 1.3.2",
"bitflags 2.4.1",
"indexmap",
"log",
"wasm-encoder 0.30.0",
"wasm-metadata 0.9.0",
"wasmparser 0.108.0",
"wit-parser",
]
[[package]]
name = "wit-component"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d843f4dfead0d465b09e8bfba4d3dcb1a1bcc857f87917d348c7fa401158bc5"
dependencies = [
"anyhow",
"bitflags 2.3.3",
"indexmap",
"log",
"wasm-encoder 0.31.1",
"wasm-metadata 0.10.1",
"wasmparser 0.110.0",
"serde",
"serde_derive",
"serde_json",
"wasm-encoder",
"wasm-metadata",
"wasmparser",
"wit-parser",
]
[[package]]
name = "wit-parser"
version = "0.9.2"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "541efa2046e544de53a9da1e2f6299e63079840360c9e106f1f8275a97771318"
checksum = "43771ee863a16ec4ecf9da0fc65c3bbd4a1235c8e3da5f094b562894843dfa76"
dependencies = [
"anyhow",
"id-arena",
"indexmap",
"log",
"pulldown-cmark",
"semver",
"serde",
"serde_derive",
"serde_json",
"unicode-xid",
"url",
]
[[package]]

View File

@ -11,25 +11,19 @@ opt-level = "s"
lto = true
[dependencies]
cargo-component-bindings = { git = "https://github.com/bytecodealliance/cargo-component" }
rmp-serde = "1.1.2"
serde_json = "1.0"
serde = {version = "1.0", features = ["derive"] }
wit-bindgen = { version = "0.11.0", default_features = false }
thiserror = "1.0.43"
anyhow = "1.0"
alloy-sol-types = "0.3.2"
hex = "0.4.3"
alloy-primitives = "0.3.3"
alloy-sol-types = "0.3.2"
bincode = "1.3.3"
hex = "0.4.3"
rmp-serde = "1.1.2"
serde = {version = "1.0", features = ["derive"] }
serde_json = "1.0"
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "5390bab780733f1660d14c254ec985df2816bf1d" }
uqbar_process_lib = { path = "../../process_lib" }
[lib]
crate-type = ["cdylib"]
[package.metadata.component]
package = "component:uq-process"
[package.metadata.component.target]
path = "wit"
[package.metadata.component.dependencies]
package = "uqbar:process"

View File

@ -1,17 +1,22 @@
cargo_component_bindings::generate!();
use alloy_primitives::FixedBytes;
use alloy_sol_types::{sol, SolEvent};
use bindings::component::uq_process::types::*;
use bindings::{print_to_terminal, receive, send_request, send_response, UqProcess};
use hex;
use serde::{Deserialize, Serialize};
use serde_json::json;
use std::collections::HashMap;
use std::string::FromUtf8Error;
use uqbar_process_lib::{
get_typed_state, receive, set_state, Address, Message, Payload, Request,
Response,
};
#[allow(dead_code)]
mod process_lib;
wit_bindgen::generate!({
path: "../../wit",
world: "process",
exports: {
world: Component,
},
});
struct Component;
@ -98,8 +103,18 @@ fn subscribe_to_qns(from_block: u64) -> Vec<u8> {
.to_vec()
}
impl UqProcess for Component {
fn init(our: Address) {
fn serialize_message(message: &NetActions) -> anyhow::Result<Vec<u8>> {
Ok(rmp_serde::to_vec(message)?)
}
fn serialize_json_message(message: &serde_json::Value) -> anyhow::Result<Vec<u8>> {
Ok(serde_json::to_vec(message)?)
}
impl Guest for Component {
fn init(our: String) {
let our = Address::from_str(&our).unwrap();
let mut state: State = State {
names: HashMap::new(),
nodes: HashMap::new(),
@ -107,247 +122,196 @@ impl UqProcess for Component {
};
// if we have state, load it in
match process_lib::get_state::<State>() {
match get_typed_state(|bytes| Ok(bincode::deserialize(bytes)?)) {
Some(s) => {
state = s;
}
None => {}
}
bindings::print_to_terminal(
0,
&format!("qns_indexer: starting at block {}", state.block),
);
println!("qns_indexer: starting at block {}", state.block);
// shove all state into net::net
send_request(
&Address {
node: our.node.clone(),
process: ProcessId::from_str("net:sys:uqbar").unwrap(),
},
&Request {
inherit: false,
expects_response: None,
metadata: None,
ipc: rmp_serde::to_vec(&NetActions::QnsBatchUpdate(
state.nodes.values().cloned().collect::<Vec<_>>(),
))
.unwrap(),
},
None,
None,
);
let _ = send_request(
&Address {
node: our.node.clone(),
process: ProcessId::from_str("eth_rpc:sys:uqbar").unwrap(),
},
&Request {
inherit: false, // TODO what
expects_response: Some(5), // TODO evaluate
metadata: None,
// -1 because there could be other events in the last processed block
ipc: subscribe_to_qns(state.block - 1),
},
None,
None,
);
let http_server_address = ProcessId::from_str("http_server:sys:uqbar").unwrap();
let _register_endpoint = send_request(
&Address {
node: our.node.clone(),
process: http_server_address.clone(),
},
&Request {
inherit: false,
expects_response: None,
metadata: None,
ipc: json!({
"BindPath": {
"path": "/node/:name",
"authenticated": false,
"local_only": false
}
})
.to_string()
.as_bytes()
.to_vec(),
},
None,
None,
);
loop {
let Ok((source, message)) = receive() else {
print_to_terminal(0, "qns_indexer: got network error");
continue;
};
let Message::Request(request) = message else {
// TODO we should store the subscription ID for eth_rpc
// incase we want to cancel/reset it
// print_to_terminal(0, "qns_indexer: got response");
continue;
};
if source.process == http_server_address {
if let Ok(ipc_json) =
serde_json::from_slice::<serde_json::Value>(&request.ipc)
{
if ipc_json["path"].as_str().unwrap_or_default() == "/node/:name" {
if let Some(name) = ipc_json["url_params"]["name"].as_str() {
if let Some(node) = state.nodes.get(name) {
send_response(
&Response {
inherit: false,
ipc: serde_json::json!({
"status": 200,
"headers": {
"Content-Type": "application/json",
},
})
.to_string()
.as_bytes()
.to_vec(),
metadata: None,
},
Some(&Payload {
mime: Some("application/json".to_string()),
bytes: serde_json::to_string(&node)
.unwrap()
.as_bytes()
.to_vec(),
}),
);
continue;
}
}
}
}
send_response(
&Response {
inherit: false,
ipc: serde_json::json!({
"status": 404,
"headers": {
"Content-Type": "application/json",
},
})
.to_string()
.as_bytes()
.to_vec(),
metadata: None,
},
Some(&Payload {
mime: Some("application/json".to_string()),
bytes: "Not Found".to_string().as_bytes().to_vec(),
}),
);
continue;
match main(our, state) {
Ok(_) => {}
Err(e) => {
println!("qns_indexer: ended with error: {:?}", e);
}
let Ok(msg) = serde_json::from_slice::<AllActions>(&request.ipc) else {
print_to_terminal(0, "qns_indexer: got invalid message");
continue;
};
match msg {
// Probably more message types later...maybe not...
AllActions::EventSubscription(e) => {
state.block = hex_to_u64(&e.block_number).unwrap();
match decode_hex(&e.topics[0].clone()) {
NodeRegistered::SIGNATURE_HASH => {
// bindings::print_to_terminal(0, format!("qns_indexer: got NodeRegistered event: {:?}", e).as_str());
let node = &e.topics[1];
let decoded =
NodeRegistered::decode_data(&decode_hex_to_vec(&e.data), true)
.unwrap();
let Ok(name) = dnswire_decode(decoded.0.clone()) else {
bindings::print_to_terminal(
1,
&format!("qns_indexer: failed to decode name: {:?}", decoded.0),
);
continue;
};
state.names.insert(node.to_string(), name);
}
WsChanged::SIGNATURE_HASH => {
let node = &e.topics[1];
let decoded =
WsChanged::decode_data(&decode_hex_to_vec(&e.data), true).unwrap();
let public_key = hex::encode(decoded.0);
let ip = decoded.1;
let port = decoded.2;
let routers_raw = decoded.3;
let routers: Vec<String> = routers_raw
.iter()
.map(|r| {
let key = hex::encode(r);
match state.names.get(&key) {
Some(name) => name.clone(),
None => format!("0x{}", key), // TODO it should actually just panic here
}
})
.collect::<Vec<String>>();
let Some(name) = state.names.get(node) else {
bindings::print_to_terminal(0, &format!("qns_indexer: failed to find name for node during WsChanged: {:?}", node));
continue;
};
let update = QnsUpdate {
name: name.clone(),
owner: "0x".to_string(), // TODO or get rid of
node: node.clone(),
public_key: format!("0x{}", public_key),
ip: format!(
"{}.{}.{}.{}",
(ip >> 24) & 0xFF,
(ip >> 16) & 0xFF,
(ip >> 8) & 0xFF,
ip & 0xFF
),
port,
routers,
};
state.nodes.insert(name.clone(), update.clone());
send_request(
&Address {
node: our.node.clone(),
process: ProcessId::from_str("net:sys:uqbar").unwrap(),
},
&Request {
inherit: false,
expects_response: None,
metadata: None,
ipc: rmp_serde::to_vec(&NetActions::QnsUpdate(update.clone()))
.unwrap(),
},
None,
None,
);
}
event => {
bindings::print_to_terminal(
0,
format!("qns_indexer: got unknown event: {:?}", event).as_str(),
);
}
}
}
}
process_lib::set_state::<State>(&state);
}
}
}
fn main(our: Address, mut state: State) -> anyhow::Result<()> {
// shove all state into net::net
Request::new()
.target(Address::new(&our.node, "net:sys:uqbar")?)?
.ipc(
&NetActions::QnsBatchUpdate(state.nodes.values().cloned().collect::<Vec<_>>()),
serialize_message,
)?
.send()?;
Request::new()
.target(Address::new(&our.node, "eth_rpc:sys:uqbar")?)?
.ipc_bytes(subscribe_to_qns(state.block - 1))
.expects_response(5)
.send()?;
Request::new()
.target(Address::new(&our.node, "http_server:sys:uqbar")?)?
.ipc(
&json!({
"BindPath": {
"path": "/node/:name",
"authenticated": false,
"local_only": false
}
}),
serialize_json_message,
)?
.send()?;
loop {
let Ok((source, message)) = receive() else {
println!("qns_indexer: got network error");
continue;
};
let Message::Request(request) = message else {
// TODO we should store the subscription ID for eth_rpc
// incase we want to cancel/reset it
continue;
};
if source.process == "http_server:sys:uqbar" {
if let Ok(ipc_json) = serde_json::from_slice::<serde_json::Value>(&request.ipc) {
if ipc_json["path"].as_str().unwrap_or_default() == "/node/:name" {
if let Some(name) = ipc_json["url_params"]["name"].as_str() {
if let Some(node) = state.nodes.get(name) {
Response::new()
.ipc(
&serde_json::json!({
"status": 200,
"headers": {
"Content-Type": "application/json",
},
}),
serialize_json_message,
)?
.payload(Payload {
mime: Some("application/json".to_string()),
bytes: serde_json::to_string(&node)
.unwrap()
.as_bytes()
.to_vec(),
})
.send()?;
continue;
}
}
}
}
Response::new()
.ipc(
&serde_json::json!({
"status": 404,
"headers": {
"Content-Type": "application/json",
},
}),
serialize_json_message,
)?
.payload(Payload {
mime: Some("application/json".to_string()),
bytes: "Not Found".to_string().as_bytes().to_vec(),
})
.send()?;
continue;
}
let Ok(msg) = serde_json::from_slice::<AllActions>(&request.ipc) else {
println!("qns_indexer: got invalid message");
continue;
};
match msg {
// Probably more message types later...maybe not...
AllActions::EventSubscription(e) => {
state.block = hex_to_u64(&e.block_number).unwrap();
match decode_hex(&e.topics[0].clone()) {
NodeRegistered::SIGNATURE_HASH => {
// print_to_terminal(0, format!("qns_indexer: got NodeRegistered event: {:?}", e).as_str());
let node = &e.topics[1];
let decoded =
NodeRegistered::decode_data(&decode_hex_to_vec(&e.data), true).unwrap();
let Ok(name) = dnswire_decode(decoded.0.clone()) else {
// print_to_terminal(
// 1,
// &format!("qns_indexer: failed to decode name: {:?}", decoded.0),
// );
continue;
};
state.names.insert(node.to_string(), name);
}
WsChanged::SIGNATURE_HASH => {
let node = &e.topics[1];
let decoded =
WsChanged::decode_data(&decode_hex_to_vec(&e.data), true).unwrap();
let public_key = hex::encode(decoded.0);
let ip = decoded.1;
let port = decoded.2;
let routers_raw = decoded.3;
let routers: Vec<String> = routers_raw
.iter()
.map(|r| {
let key = hex::encode(r);
match state.names.get(&key) {
Some(name) => name.clone(),
None => format!("0x{}", key), // TODO it should actually just panic here
}
})
.collect::<Vec<String>>();
let Some(name) = state.names.get(node) else {
println!(
"qns_indexer: failed to find name for node during WsChanged: {:?}",
node
);
continue;
};
let update = QnsUpdate {
name: name.clone(),
owner: "0x".to_string(), // TODO or get rid of
node: node.clone(),
public_key: format!("0x{}", public_key),
ip: format!(
"{}.{}.{}.{}",
(ip >> 24) & 0xFF,
(ip >> 16) & 0xFF,
(ip >> 8) & 0xFF,
ip & 0xFF
),
port,
routers,
};
state.nodes.insert(name.clone(), update.clone());
Request::new()
.target(Address::new(&our.node, "net:sys:uqbar")?)?
.ipc(&NetActions::QnsUpdate(update.clone()), serialize_message)?
.send()?;
}
event => {
println!("qns_indexer: got unknown event: {:?}", event);
}
}
}
}
set_state(&bincode::serialize(&state)?);
}
}
// helpers
// TODO these probably exist somewhere in alloy...not sure where though.
fn decode_hex(s: &str) -> FixedBytes<32> {

View File

@ -1 +0,0 @@
../../../src/process_lib.rs

View File

@ -23,12 +23,6 @@ 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"
@ -42,28 +36,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[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",
]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "equivalent"
@ -72,12 +48,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "form_urlencoded"
version = "1.2.0"
name = "getrandom"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652"
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
dependencies = [
"percent-encoding",
"cfg-if",
"libc",
"wasi",
]
[[package]]
@ -101,16 +79,6 @@ 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"
@ -134,18 +102,18 @@ version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67"
[[package]]
name = "libc"
version = "0.2.150"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
[[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 = "num-traits"
version = "0.2.17"
@ -162,10 +130,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
[[package]]
name = "percent-encoding"
version = "2.3.0"
name = "ppv-lite86"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "proc-macro2"
@ -176,17 +144,6 @@ 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"
@ -196,6 +153,36 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
name = "rmp"
version = "0.8.12"
@ -282,11 +269,11 @@ version = "0.1.0"
dependencies = [
"anyhow",
"bincode",
"cargo-component-bindings",
"rmp-serde",
"serde",
"serde_json",
"thiserror",
"uqbar_process_lib",
"wit-bindgen",
]
@ -321,51 +308,12 @@ dependencies = [
"syn",
]
[[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"
@ -379,40 +327,41 @@ 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"
name = "uqbar_process_lib"
version = "0.2.0"
dependencies = [
"form_urlencoded",
"idna",
"percent-encoding",
"anyhow",
"bincode",
"rand",
"serde",
"wit-bindgen",
]
[[package]]
name = "version_check"
version = "0.9.4"
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-encoder"
version = "0.32.0"
version = "0.36.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ba64e81215916eaeb48fee292f29401d69235d62d8b8fd92a7b2844ec5ae5f7"
checksum = "822b645bf4f2446b949776ffca47e2af60b167209ffb70814ef8779d299cd421"
dependencies = [
"leb128",
]
[[package]]
name = "wasm-metadata"
version = "0.10.3"
version = "0.10.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08dc59d1fa569150851542143ca79438ca56845ccb31696c70225c638e063471"
checksum = "2167ce53b2faa16a92c6cafd4942cff16c9a4fa0c5a5a0a41131ee4e49fc055f"
dependencies = [
"anyhow",
"indexmap",
"serde",
"serde_derive",
"serde_json",
"spdx",
"wasm-encoder",
@ -421,9 +370,9 @@ dependencies = [
[[package]]
name = "wasmparser"
version = "0.112.0"
version = "0.116.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e986b010f47fcce49cf8ea5d5f9e5d2737832f12b53ae8ae785bbe895d0877bf"
checksum = "a58e28b80dd8340cb07b8242ae654756161f6fc8d0038123d679b7b99964fa50"
dependencies = [
"indexmap",
"semver",
@ -431,19 +380,17 @@ dependencies = [
[[package]]
name = "wit-bindgen"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8a3e8e965dc50e6eb4410d9a11720719fadc6a1713803ea5f3be390b81c8279"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"bitflags 2.4.0",
"bitflags",
"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"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"anyhow",
"wit-component",
@ -452,54 +399,42 @@ dependencies = [
[[package]]
name = "wit-bindgen-rust"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "399c60e6ea8598d1380e792f13d557007834f0fb799fea6503408cbc5debb4ae"
version = "0.13.2"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
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"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"anyhow",
"proc-macro2",
"quote",
"syn",
"wit-bindgen-core",
"wit-bindgen-rust",
"wit-bindgen-rust-lib",
"wit-component",
]
[[package]]
name = "wit-component"
version = "0.14.0"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66d9f2d16dd55d1a372dcfd4b7a466ea876682a5a3cb97e71ec9eef04affa876"
checksum = "480cc1a078b305c1b8510f7c455c76cbd008ee49935f3a6c5fd5e937d8d95b1e"
dependencies = [
"anyhow",
"bitflags 2.4.0",
"bitflags",
"indexmap",
"log",
"serde",
"serde_derive",
"serde_json",
"wasm-encoder",
"wasm-metadata",
@ -509,16 +444,17 @@ dependencies = [
[[package]]
name = "wit-parser"
version = "0.11.0"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61e8b849bea13cc2315426b16efe6eb6813466d78f5fde69b0bb150c9c40e0dc"
checksum = "43771ee863a16ec4ecf9da0fc65c3bbd4a1235c8e3da5f094b562894843dfa76"
dependencies = [
"anyhow",
"id-arena",
"indexmap",
"log",
"pulldown-cmark",
"semver",
"serde",
"serde_derive",
"serde_json",
"unicode-xid",
"url",
]

View File

@ -13,12 +13,12 @@ lto = true
[dependencies]
anyhow = "1.0"
bincode = "1.3.3"
cargo-component-bindings = { git = "https://github.com/bytecodealliance/cargo-component" }
rmp-serde = "1.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "1.0"
wit-bindgen = { version = "0.11.0", default_features = false }
uqbar_process_lib = { path = "../../../process_lib" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "5390bab780733f1660d14c254ec985df2816bf1d" }
[lib]
crate-type = ["cdylib"]

View File

@ -1 +0,0 @@
../../../../src/kernel_types.rs

View File

@ -1,17 +1,19 @@
cargo_component_bindings::generate!();
use std::collections::{HashMap, HashSet};
use bindings::component::uq_process::types::*;
use bindings::{create_capability, get_capability, Guest, has_capability, print_to_terminal, receive, send_request, send_response, spawn};
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;
wit_bindgen::generate!({
path: "../../../wit",
world: "process",
exports: {
world: Component,
},
});
mod kernel_types;
use kernel_types as kt;
mod sqlite_types;
use sqlite_types as sq;
mod process_lib;
struct Component;
const PREFIX: &str = "sqlite-";
@ -39,25 +41,20 @@ fn forward_if_have_cap(
ipc: Vec<u8>,
db_to_process: &mut DbToProcess,
) -> anyhow::Result<()> {
if has_capability(&make_db_cap(operation_type, db)) {
if wit::has_capability(&make_db_cap(operation_type, db)) {
// forward
let Some(process_id) = db_to_process.get(db) else {
return Err(sq::SqliteError::DbDoesNotExist.into());
};
send_request(
&Address {
Request::new()
.target(wit::Address {
node: our.node.clone(),
process: process_id.clone(),
},
&Request {
inherit: true,
expects_response: None,
ipc,
metadata: None,
},
None,
None,
);
})?
// .target(Address::new(our.node.clone(), process_id.clone()))?
.inherit(true)
.ipc_bytes(ipc)
.send()?;
return Ok(());
} else {
// reject
@ -71,19 +68,18 @@ fn handle_message (
read_keywords: &HashSet<String>,
write_keywords: &HashSet<String>,
) -> anyhow::Result<()> {
let (source, message) = receive().unwrap();
// let (source, message) = receive()?;
let (source, message) = wit::receive().unwrap();
if our.node != source.node {
return Err(sq::SqliteError::RejectForeign.into());
}
match message {
Message::Response(_) => {
wit::Message::Response(_) => {
return Err(sq::SqliteError::UnexpectedResponse.into());
},
Message::Request(Request { ipc, .. }) => {
match process_lib::parse_message_ipc(&ipc)? {
wit::Message::Request(wit::Request { ipc, .. }) => {
match serde_json::from_slice(&ipc)? {
sq::SqliteMessage::New { ref db } => {
// TODO: make atomic
// (1): create vfs drive
@ -98,74 +94,58 @@ fn handle_message (
// (1)
let vfs_address = Address {
node: our.node.clone(),
process: kt::ProcessId::new("vfs", "sys", "uqbar").en_wit(),
process: ProcessId::new("vfs", "sys", "uqbar"),
};
let vfs_drive = format!("{}{}", PREFIX, db);
let _ = process_lib::send_and_await_response(
&vfs_address,
false,
serde_json::to_vec(&kt::VfsRequest {
let _ = Request::new()
.target(vfs_address.clone())?
.ipc_bytes(serde_json::to_vec(&kt::VfsRequest {
drive: vfs_drive.clone(),
action: kt::VfsAction::New,
}).unwrap(),
None,
None,
15,
).unwrap();
})?)
.send_and_await_response(15)??;
// (2)
let vfs_read = get_capability(
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 = get_capability(
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 spawned_process_id = match spawn(
let spawned_process_id = match wit::spawn(
None,
"/sqlite_worker.wasm",
&OnPanic::None, // TODO: notify us
&Capabilities::Some(vec![vfs_read, vfs_write]),
&wit::OnPanic::None, // TODO: notify us
&wit::Capabilities::Some(vec![vfs_read, vfs_write]),
false, // not public
) {
Ok(spawned_process_id) => spawned_process_id,
Err(e) => {
print_to_terminal(0, &format!("couldn't spawn: {}", e));
wit::print_to_terminal(0, &format!("couldn't spawn: {}", e));
panic!("couldn't spawn"); // TODO
},
};
// grant caps
create_capability(&source.process, &make_db_cap("read", db));
create_capability(&source.process, &make_db_cap("write", db));
wit::create_capability(&source.process, &make_db_cap("read", db));
wit::create_capability(&source.process, &make_db_cap("write", db));
// initialize worker
send_request(
&Address {
Request::new()
.target(wit::Address {
node: our.node.clone(),
process: spawned_process_id.clone(),
},
&Request {
inherit: false,
expects_response: None,
ipc: ipc.clone(),
metadata: None,
},
None,
None,
);
})?
.ipc_bytes(ipc.clone())
.send()?;
// (4)
db_to_process.insert(db.into(), spawned_process_id);
// TODO: persistence?
send_response(
&Response {
inherit: false,
ipc,
metadata: None,
},
None,
);
Response::new()
.ipc_bytes(ipc)
.send()?;
},
sq::SqliteMessage::Write { ref db, ref statement } => {
let first_word = statement
@ -196,10 +176,12 @@ fn handle_message (
}
}
struct Component;
impl Guest for Component {
fn init(our: Address) {
print_to_terminal(0, "sqlite: begin");
fn init(our: String) {
wit::print_to_terminal(0, "sqlite: begin");
let our = Address::from_str(&our).unwrap();
let mut db_to_process: DbToProcess = HashMap::new();
let read_keywords: HashSet<String> = [
"ANALYZE",
@ -241,19 +223,15 @@ impl Guest for Component {
match handle_message(&our, &mut db_to_process, &read_keywords, &write_keywords) {
Ok(()) => {},
Err(e) => {
print_to_terminal(0, format!(
wit::print_to_terminal(0, format!(
"sqlite: error: {:?}",
e,
).as_str());
if let Some(e) = e.downcast_ref::<sq::SqliteError>() {
send_response(
&Response {
inherit: false,
ipc: serde_json::to_vec(&e).unwrap(),
metadata: None,
},
None,
);
Response::new()
.ipc_bytes(serde_json::to_vec(&e).unwrap())
.send()
.unwrap();
}
},
};

View File

@ -1 +0,0 @@
../../../../src/process_lib.rs

View File

@ -40,12 +40,6 @@ 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"
@ -58,30 +52,6 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[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 = "cc"
version = "1.0.83"
@ -116,12 +86,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a"
[[package]]
name = "form_urlencoded"
version = "1.2.0"
name = "getrandom"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652"
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
dependencies = [
"percent-encoding",
"cfg-if",
"libc",
"wasi",
]
[[package]]
@ -158,16 +130,6 @@ 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"
@ -213,12 +175,6 @@ 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 = "num-traits"
version = "0.2.17"
@ -240,18 +196,18 @@ version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
[[package]]
name = "percent-encoding"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94"
[[package]]
name = "pkg-config"
version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
[[package]]
name = "ppv-lite86"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "proc-macro2"
version = "1.0.66"
@ -261,17 +217,6 @@ 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"
@ -281,6 +226,36 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
name = "rmp"
version = "0.8.12"
@ -308,7 +283,7 @@ name = "rusqlite"
version = "0.29.0"
source = "git+https://github.com/uqbar-dao/rusqlite?rev=fa6ed84#fa6ed843b65f7dd78d53a1b74c7e5095d71c2bd4"
dependencies = [
"bitflags 2.4.0",
"bitflags",
"fallible-iterator",
"fallible-streaming-iterator",
"hashlink",
@ -380,12 +355,12 @@ version = "0.1.0"
dependencies = [
"anyhow",
"bincode",
"cargo-component-bindings",
"rmp-serde",
"rusqlite",
"serde",
"serde_json",
"thiserror",
"uqbar_process_lib",
"wit-bindgen",
]
@ -420,51 +395,12 @@ dependencies = [
"syn",
]
[[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"
@ -478,14 +414,14 @@ 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"
name = "uqbar_process_lib"
version = "0.2.0"
dependencies = [
"form_urlencoded",
"idna",
"percent-encoding",
"anyhow",
"bincode",
"rand",
"serde",
"wit-bindgen",
]
[[package]]
@ -501,23 +437,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "wasm-encoder"
version = "0.32.0"
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ba64e81215916eaeb48fee292f29401d69235d62d8b8fd92a7b2844ec5ae5f7"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-encoder"
version = "0.36.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "822b645bf4f2446b949776ffca47e2af60b167209ffb70814ef8779d299cd421"
dependencies = [
"leb128",
]
[[package]]
name = "wasm-metadata"
version = "0.10.3"
version = "0.10.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08dc59d1fa569150851542143ca79438ca56845ccb31696c70225c638e063471"
checksum = "2167ce53b2faa16a92c6cafd4942cff16c9a4fa0c5a5a0a41131ee4e49fc055f"
dependencies = [
"anyhow",
"indexmap",
"serde",
"serde_derive",
"serde_json",
"spdx",
"wasm-encoder",
@ -526,9 +469,9 @@ dependencies = [
[[package]]
name = "wasmparser"
version = "0.112.0"
version = "0.116.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e986b010f47fcce49cf8ea5d5f9e5d2737832f12b53ae8ae785bbe895d0877bf"
checksum = "a58e28b80dd8340cb07b8242ae654756161f6fc8d0038123d679b7b99964fa50"
dependencies = [
"indexmap",
"semver",
@ -536,19 +479,17 @@ dependencies = [
[[package]]
name = "wit-bindgen"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8a3e8e965dc50e6eb4410d9a11720719fadc6a1713803ea5f3be390b81c8279"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"bitflags 2.4.0",
"bitflags",
"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"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"anyhow",
"wit-component",
@ -557,54 +498,42 @@ dependencies = [
[[package]]
name = "wit-bindgen-rust"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "399c60e6ea8598d1380e792f13d557007834f0fb799fea6503408cbc5debb4ae"
version = "0.13.2"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
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"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"anyhow",
"proc-macro2",
"quote",
"syn",
"wit-bindgen-core",
"wit-bindgen-rust",
"wit-bindgen-rust-lib",
"wit-component",
]
[[package]]
name = "wit-component"
version = "0.14.0"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66d9f2d16dd55d1a372dcfd4b7a466ea876682a5a3cb97e71ec9eef04affa876"
checksum = "480cc1a078b305c1b8510f7c455c76cbd008ee49935f3a6c5fd5e937d8d95b1e"
dependencies = [
"anyhow",
"bitflags 2.4.0",
"bitflags",
"indexmap",
"log",
"serde",
"serde_derive",
"serde_json",
"wasm-encoder",
"wasm-metadata",
@ -614,16 +543,17 @@ dependencies = [
[[package]]
name = "wit-parser"
version = "0.11.0"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61e8b849bea13cc2315426b16efe6eb6813466d78f5fde69b0bb150c9c40e0dc"
checksum = "43771ee863a16ec4ecf9da0fc65c3bbd4a1235c8e3da5f094b562894843dfa76"
dependencies = [
"anyhow",
"id-arena",
"indexmap",
"log",
"pulldown-cmark",
"semver",
"serde",
"serde_derive",
"serde_json",
"unicode-xid",
"url",
]

View File

@ -13,13 +13,13 @@ lto = true
[dependencies]
anyhow = "1.0"
bincode = "1.3.3"
cargo-component-bindings = { git = "https://github.com/bytecodealliance/cargo-component" }
rmp-serde = "1.1"
rusqlite = { git = "https://github.com/uqbar-dao/rusqlite", rev = "fa6ed84", features = ["bundled", "wasm32-wasi-vfs"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "1.0"
wit-bindgen = { version = "0.11.0", default_features = false }
uqbar_process_lib = { path = "../../../process_lib" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "5390bab780733f1660d14c254ec985df2816bf1d" }
[lib]
crate-type = ["cdylib"]

View File

@ -1 +0,0 @@
../../../../src/kernel_types.rs

View File

@ -1,24 +1,24 @@
cargo_component_bindings::generate!();
use core::ffi::{c_char, c_int, c_ulonglong, CStr};
use std::ffi::CString;
use rusqlite::{types::FromSql, types::FromSqlError, types::ToSql, types::ValueRef};
use uqbar_process_lib::{Address, ProcessId, Response};
use uqbar_process_lib::uqbar::process::standard as wit;
use crate::sqlite_types::Deserializable;
use rusqlite::{types::FromSql, types::FromSqlError, types::ToSql, types::ValueRef};
// use serde::{Deserialize, Serialize};
wit_bindgen::generate!({
path: "../../../wit",
world: "process",
exports: {
world: Component,
},
});
use bindings::component::uq_process::types::*;
use bindings::{get_payload, Guest, print_to_terminal, receive, send_and_await_response, send_response};
mod kernel_types;
use kernel_types as kt;
mod process_lib;
mod sqlite_types;
use sqlite_types as sq;
struct Component;
const PREFIX: &str = "sqlite-";
impl ToSql for sq::SqlValue {
@ -167,11 +167,11 @@ fn from_cbytes_to_vec_u8(bytes: *mut CBytes) -> Vec<u8> {
bytes
}
impl From<Option<Payload>> for CPrePayload {
fn from(p: Option<Payload>) -> Self {
impl From<Option<wit::Payload>> for CPrePayload {
fn from(p: Option<wit::Payload>) -> Self {
let (is_empty, mime, bytes) = match p {
None => (0, COptionStr::new(None), CBytes::new_empty()),
Some(Payload { mime, bytes }) => {
Some(wit::Payload { mime, bytes }) => {
let mime = match mime {
Some(s) => Some(s.as_bytes().to_vec()),
None => None,
@ -187,14 +187,14 @@ impl From<Option<Payload>> for CPrePayload {
}
}
impl From<CPayload> for Option<Payload> {
impl From<CPayload> for Option<wit::Payload> {
fn from(p: CPayload) -> Self {
if p.is_empty == 0 {
None
} else {
let mime = from_coptionstr_to_option_string(p.mime);
let bytes = from_cbytes_to_vec_u8(p.bytes);
Some(Payload {
Some(wit::Payload {
mime,
bytes,
})
@ -202,13 +202,13 @@ impl From<CPayload> for Option<Payload> {
}
}
fn from_cpayload_to_option_payload(p: *const CPayload) -> Option<Payload> {
fn from_cpayload_to_option_payload(p: *const CPayload) -> Option<wit::Payload> {
if unsafe { (*p).is_empty == 0 } {
None
} else {
let mime = unsafe { from_coptionstr_to_option_string((*p).mime) };
let bytes = unsafe { from_cbytes_to_vec_u8((*p).bytes) };
Some(Payload {
Some(wit::Payload {
mime,
bytes,
})
@ -234,7 +234,7 @@ pub extern "C" fn get_payload_wrapped(return_val: *mut CPayload) {
// in memory due to an fs bug where chunk size may be bigger than requested
let max_len = unsafe { (*(*return_val).bytes).len.clone() };
let payload = get_payload();
let payload = wit::get_payload();
let mime_len = {
match payload {
None => None,
@ -317,13 +317,13 @@ pub extern "C" fn send_and_await_response_wrapped(
let request_metadata = from_coptionstr_to_option_string(request_metadata);
let (
_,
Message::Response((Response { ipc, metadata, .. }, _)),
) = send_and_await_response(
&Address {
wit::Message::Response((wit::Response { ipc, metadata, .. }, _)),
) = wit::send_and_await_response(
&wit::Address {
node: target_node,
process: target_process,
},
&Request {
&wit::Request {
inherit: false,
expects_response: Some(timeout),
ipc: request_ipc,
@ -346,25 +346,20 @@ pub extern "C" fn send_and_await_response_wrapped(
}
fn handle_message (
our: &Address,
our: &wit::Address,
db_handle: &mut Option<rusqlite::Connection>,
) -> anyhow::Result<()> {
let (source, message) = receive().unwrap();
// let (source, message) = receive()?;
let (source, message) = wit::receive().unwrap();
if our.node != source.node {
return Err(sq::SqliteError::RejectForeign.into());
}
match message {
Message::Response(_) => { unimplemented!() },
Message::Request(Request { ipc, .. }) => {
match process_lib::parse_message_ipc(&ipc)? {
wit::Message::Response(_) => { unimplemented!() },
wit::Message::Request(wit::Request { ipc, .. }) => {
match serde_json::from_slice(&ipc)? {
sq::SqliteMessage::New { db } => {
let vfs_address = Address {
node: our.node.clone(),
process: kt::ProcessId::new("vfs", "sys", "uqbar").en_wit(),
};
let vfs_drive = format!("{}{}", PREFIX, db);
match db_handle {
@ -391,7 +386,7 @@ fn handle_message (
return Err(sq::SqliteError::DbDoesNotExist.into());
};
match get_payload() {
match wit::get_payload() {
None => {
let parameters: Vec<&dyn rusqlite::ToSql> = vec![];
db_handle.execute(
@ -399,7 +394,7 @@ fn handle_message (
&parameters[..],
)?;
},
Some(Payload { mime: _, ref bytes }) => {
Some(wit::Payload { mime: _, ref bytes }) => {
let parameters = Vec::<sq::SqlValue>::from_serialized(&bytes)?;
let parameters: Vec<&dyn rusqlite::ToSql> = parameters
.iter()
@ -413,14 +408,9 @@ fn handle_message (
},
}
send_response(
&Response {
inherit: false,
ipc,
metadata: None,
},
None,
);
Response::new()
.ipc_bytes(ipc)
.send()?;
},
sq::SqliteMessage::Read { ref query, .. } => {
let Some(db_handle) = db_handle else {
@ -445,17 +435,13 @@ fn handle_message (
let results = rmp_serde::to_vec(&results).unwrap();
send_response(
&Response {
inherit: false,
ipc,
metadata: None,
},
Some(&Payload {
Response::new()
.ipc_bytes(ipc)
.payload(wit::Payload {
mime: None,
bytes: results,
}),
);
})
.send()?;
},
}
@ -464,10 +450,12 @@ fn handle_message (
}
}
struct Component;
impl Guest for Component {
fn init(our: Address) {
print_to_terminal(1, "sqlite_worker: begin");
fn init(our: String) {
wit::print_to_terminal(1, "sqlite_worker: begin");
let our = Address::from_str(&our).unwrap();
let mut db_handle: Option<rusqlite::Connection> = None;
loop {
@ -475,10 +463,16 @@ impl Guest for Component {
Ok(()) => {},
Err(e) => {
// TODO: should we send an error on failure?
print_to_terminal(0, format!(
wit::print_to_terminal(0, format!(
"sqlite_worker: error: {:?}",
e,
).as_str());
if let Some(e) = e.downcast_ref::<sq::SqliteError>() {
Response::new()
.ipc_bytes(serde_json::to_vec(&e).unwrap())
.send()
.unwrap();
}
},
};
}

View File

@ -1 +0,0 @@
../../../../src/process_lib.rs

View File

@ -1,3 +0,0 @@
# This file is automatically generated by cargo-component.
# It is not intended for manual editing.
version = 1

View File

@ -19,39 +19,15 @@ dependencies = [
[[package]]
name = "bitflags"
version = "1.3.2"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
[[package]]
name = "bitflags"
version = "2.4.0"
name = "cfg-if"
version = "1.0.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",
]
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "equivalent"
@ -60,19 +36,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "form_urlencoded"
version = "1.2.0"
name = "getrandom"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652"
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
dependencies = [
"percent-encoding",
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "hashbrown"
version = "0.14.0"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156"
[[package]]
name = "heck"
@ -89,21 +67,11 @@ 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"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d"
checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f"
dependencies = [
"equivalent",
"hashbrown",
@ -122,6 +90,12 @@ version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67"
[[package]]
name = "libc"
version = "0.2.149"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b"
[[package]]
name = "log"
version = "0.4.20"
@ -129,37 +103,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
[[package]]
name = "memchr"
version = "2.6.3"
name = "ppv-lite86"
version = "0.2.17"
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"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "proc-macro2"
version = "1.0.66"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
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"
@ -169,6 +126,36 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
name = "ryu"
version = "1.0.15"
@ -177,24 +164,24 @@ checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
[[package]]
name = "semver"
version = "1.0.18"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918"
checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090"
[[package]]
name = "serde"
version = "1.0.188"
version = "1.0.190"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e"
checksum = "91d3c334ca1ee894a2c6f6ad698fe8c435b76d504b13d436f0685d648d6d96f7"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.188"
version = "1.0.190"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2"
checksum = "67c5609f394e5c2bd7fc51efda478004ea80ef42fee983d5c67a65e34f32c0e3"
dependencies = [
"proc-macro2",
"quote",
@ -203,9 +190,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.105"
version = "1.0.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360"
checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b"
dependencies = [
"itoa",
"ryu",
@ -214,9 +201,9 @@ dependencies = [
[[package]]
name = "smallvec"
version = "1.11.0"
version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9"
checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a"
[[package]]
name = "spdx"
@ -229,9 +216,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.31"
version = "2.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "718fa2415bcb8d8bd775917a1bf12a7931b6dfa890753378538118181e0cb398"
checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b"
dependencies = [
"proc-macro2",
"quote",
@ -244,56 +231,17 @@ version = "0.1.0"
dependencies = [
"anyhow",
"bincode",
"cargo-component-bindings",
"serde",
"serde_json",
"uqbar_process_lib",
"wit-bindgen",
]
[[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"
version = "1.0.12"
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",
]
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "unicode-segmentation"
@ -308,40 +256,41 @@ 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"
name = "uqbar_process_lib"
version = "0.2.0"
dependencies = [
"form_urlencoded",
"idna",
"percent-encoding",
"anyhow",
"bincode",
"rand",
"serde",
"wit-bindgen",
]
[[package]]
name = "version_check"
version = "0.9.4"
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-encoder"
version = "0.32.0"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ba64e81215916eaeb48fee292f29401d69235d62d8b8fd92a7b2844ec5ae5f7"
checksum = "53ae0be20bf87918df4fa831bfbbd0b491d24aee407ed86360eae4c2c5608d38"
dependencies = [
"leb128",
]
[[package]]
name = "wasm-metadata"
version = "0.10.3"
version = "0.10.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08dc59d1fa569150851542143ca79438ca56845ccb31696c70225c638e063471"
checksum = "5621910462c61a8efc3248fdfb1739bf649bb335b0df935c27b340418105f9d8"
dependencies = [
"anyhow",
"indexmap",
"serde",
"serde_derive",
"serde_json",
"spdx",
"wasm-encoder",
@ -350,9 +299,9 @@ dependencies = [
[[package]]
name = "wasmparser"
version = "0.112.0"
version = "0.116.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e986b010f47fcce49cf8ea5d5f9e5d2737832f12b53ae8ae785bbe895d0877bf"
checksum = "53290b1276c5c2d47d694fb1a920538c01f51690e7e261acbe1d10c5fc306ea1"
dependencies = [
"indexmap",
"semver",
@ -360,19 +309,17 @@ dependencies = [
[[package]]
name = "wit-bindgen"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8a3e8e965dc50e6eb4410d9a11720719fadc6a1713803ea5f3be390b81c8279"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"bitflags 2.4.0",
"bitflags",
"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"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"anyhow",
"wit-component",
@ -381,54 +328,42 @@ dependencies = [
[[package]]
name = "wit-bindgen-rust"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "399c60e6ea8598d1380e792f13d557007834f0fb799fea6503408cbc5debb4ae"
version = "0.13.2"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
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"
version = "0.13.1"
source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=5390bab780733f1660d14c254ec985df2816bf1d#5390bab780733f1660d14c254ec985df2816bf1d"
dependencies = [
"anyhow",
"proc-macro2",
"quote",
"syn",
"wit-bindgen-core",
"wit-bindgen-rust",
"wit-bindgen-rust-lib",
"wit-component",
]
[[package]]
name = "wit-component"
version = "0.14.0"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66d9f2d16dd55d1a372dcfd4b7a466ea876682a5a3cb97e71ec9eef04affa876"
checksum = "480cc1a078b305c1b8510f7c455c76cbd008ee49935f3a6c5fd5e937d8d95b1e"
dependencies = [
"anyhow",
"bitflags 2.4.0",
"bitflags",
"indexmap",
"log",
"serde",
"serde_derive",
"serde_json",
"wasm-encoder",
"wasm-metadata",
@ -438,16 +373,17 @@ dependencies = [
[[package]]
name = "wit-parser"
version = "0.11.0"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61e8b849bea13cc2315426b16efe6eb6813466d78f5fde69b0bb150c9c40e0dc"
checksum = "43771ee863a16ec4ecf9da0fc65c3bbd4a1235c8e3da5f094b562894843dfa76"
dependencies = [
"anyhow",
"id-arena",
"indexmap",
"log",
"pulldown-cmark",
"semver",
"serde",
"serde_derive",
"serde_json",
"unicode-xid",
"url",
]

View File

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

View File

@ -1,101 +1,74 @@
cargo_component_bindings::generate!();
use bindings::{component::uq_process::types::*, print_to_terminal, receive, send_request, Guest};
use anyhow::anyhow;
use uqbar_process_lib::uqbar::process::standard as wit;
use uqbar_process_lib::{Address, ProcessId, Request, println};
#[allow(dead_code)]
mod process_lib;
wit_bindgen::generate!({
path: "../../wit",
world: "process",
exports: {
world: Component,
},
});
struct Component;
fn serialize_message(message: &&str) -> anyhow::Result<Vec<u8>> {
Ok(message.as_bytes().to_vec())
}
fn parse_command(our_name: &str, line: &str) {
fn parse_command(our_name: &str, line: &str) -> anyhow::Result<()> {
let (head, tail) = line.split_once(" ").unwrap_or((&line, ""));
match head {
"" | " " => {}
"" | " " => return Ok(()),
"!hi" => {
let (target, message) = match tail.split_once(" ") {
let (node_id, message) = match tail.split_once(" ") {
Some((s, t)) => (s, t),
None => {
print_to_terminal(0, &format!("invalid command: \"{}\"", line));
return;
}
None => return Err(anyhow!("invalid command: \"{line}\"")),
};
send_request(
&Address {
node: if target == "our" {
our_name.into()
} else {
target.into()
},
process: ProcessId::from_str("net:sys:uqbar").unwrap(),
},
&Request {
inherit: false,
expects_response: Some(5),
ipc: message.into(),
metadata: None,
},
None,
None,
);
let node_id = if node_id == "our" { our_name } else { node_id };
Request::new()
.target(Address::new(node_id, "net:sys:uqbar").unwrap())?
.ipc(&message, serialize_message)?
.expects_response(5)
.send()?;
Ok(())
}
"!message" => {
let (target_node, tail) = match tail.split_once(" ") {
let (node_id, tail) = match tail.split_once(" ") {
Some((s, t)) => (s, t),
None => {
print_to_terminal(0, &format!("invalid command: \"{}\"", line));
return;
}
None => return Err(anyhow!("invalid command: \"{line}\"")),
};
let (target_process, ipc) = match tail.split_once(" ") {
Some((a, p)) => (a, p),
None => {
print_to_terminal(0, &format!("invalid command: \"{}\"", line));
return;
}
None => return Err(anyhow!("invalid command: \"{line}\"")),
};
// TODO: why does this work but using the API below does not?
// Is it related to passing json in rather than a Serialize type?
//
send_request(
&Address {
node: if target_node == "our" {
our_name.into()
} else {
target_node.into()
},
process: ProcessId::from_str(target_process).unwrap_or_else(|_| {
ProcessId::from_str(&format!("{}:sys:uqbar", target_process)).unwrap()
}),
},
&Request {
inherit: false,
expects_response: None,
ipc: ipc.into(),
metadata: None,
},
None,
None,
);
}
_ => {
print_to_terminal(0, &format!("invalid command: \"{line}\""));
let node_id = if node_id == "our" { our_name } else { node_id };
let process = ProcessId::from_str(target_process).unwrap_or_else(|_| {
ProcessId::from_str(&format!("{}:sys:uqbar", target_process)).unwrap()
});
Request::new()
.target(Address::new(node_id, process).unwrap())?
.ipc(&ipc, serialize_message)?
.send()?;
Ok(())
}
_ => return Err(anyhow!("invalid command: \"{line}\"")),
}
}
struct Component;
impl Guest for Component {
fn init(our: Address) {
assert_eq!(our.process.to_string(), "terminal:terminal:uqbar");
print_to_terminal(1, &format!("terminal: start"));
fn init(our: String) {
let our = Address::from_str(&our).unwrap();
println!("terminal: start");
loop {
let (source, message) = match receive() {
let (source, message) = match wit::receive() {
Ok((source, message)) => (source, message),
Err((error, _context)) => {
print_to_terminal(0, &format!("net error: {:?}!", error.kind));
println!("terminal: net error: {:?}!", error.kind);
continue;
}
};
match message {
Message::Request(Request {
wit::Message::Request(wit::Request {
expects_response,
ipc,
..
@ -103,11 +76,14 @@ impl Guest for Component {
if our.node != source.node || our.process != source.process {
continue;
}
parse_command(&our.node, std::str::from_utf8(&ipc).unwrap_or_default());
match parse_command(&our.node, std::str::from_utf8(&ipc).unwrap_or_default()) {
Ok(()) => continue,
Err(e) => println!("terminal: {e}"),
}
}
Message::Response((Response { ipc, metadata, .. }, _)) => {
wit::Message::Response((wit::Response { ipc, metadata, .. }, _)) => {
if let Ok(txt) = std::str::from_utf8(&ipc) {
print_to_terminal(0, &format!("net response: {}", txt));
println!("terminal: net response: {txt}");
}
}
}

View File

@ -1 +0,0 @@
../../../src/process_lib.rs

312
process_lib/Cargo.lock generated Normal file
View File

@ -0,0 +1,312 @@
# 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",
]

11
process_lib/Cargo.toml Normal file
View File

@ -0,0 +1,11 @@
[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

@ -0,0 +1,509 @@
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(),
),
}
}

611
process_lib/src/lib.rs Normal file
View File

@ -0,0 +1,611 @@
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,
}

View File

@ -1,3 +1,8 @@
use crate::kernel::uqbar::process::standard as wit;
use crate::types as t;
use crate::FILESYSTEM_PROCESS_ID;
use crate::KERNEL_PROCESS_ID;
use crate::VFS_PROCESS_ID;
use anyhow::Result;
use ring::signature::{self, KeyPair};
use serde::{Deserialize, Serialize};
@ -10,24 +15,14 @@ use std::sync::{
};
use tokio::sync::mpsc;
use tokio::task::JoinHandle;
use uqbar::process::standard::Host as StandardHost;
use wasmtime::component::*;
use wasmtime::{Config, Engine, Store, WasmBacktraceDetails};
use wasmtime_wasi::preview2::{Table, WasiCtx, WasiCtxBuilder, WasiView};
use crate::types as t;
use crate::FILESYSTEM_PROCESS_ID;
use crate::KERNEL_PROCESS_ID;
use crate::VFS_PROCESS_ID;
// WIT errors when `use`ing interface unless we import this and implement Host for Process below
use crate::kernel::component::uq_process::types as wit;
use crate::kernel::component::uq_process::types::Host;
mod utils;
use crate::kernel::utils::*;
bindgen!({
path: "wit",
world: "uq-process",
world: "process",
async: true,
});
@ -38,7 +33,7 @@ type ProcessMessageSender =
type ProcessMessageReceiver =
tokio::sync::mpsc::Receiver<Result<t::KernelMessage, t::WrappedSendError>>;
struct Process {
struct ProcessState {
keypair: Arc<signature::Ed25519KeyPair>,
metadata: t::ProcessMetadata,
recv_in_process: ProcessMessageReceiver,
@ -54,7 +49,7 @@ struct Process {
}
struct ProcessWasi {
process: Process,
process: ProcessState,
table: Table,
wasi: WasiCtx,
}
@ -77,7 +72,7 @@ enum ProcessSender {
Userspace(ProcessMessageSender),
}
impl Host for ProcessWasi {}
//impl Host for ProcessWasi {}
impl WasiView for ProcessWasi {
fn table(&self) -> &Table {
@ -98,7 +93,7 @@ impl WasiView for ProcessWasi {
/// create the process API. this is where the functions that a process can use live.
///
#[async_trait::async_trait]
impl UqProcessImports for ProcessWasi {
impl StandardHost for ProcessWasi {
//
// system utils:
//
@ -123,27 +118,10 @@ impl UqProcessImports for ProcessWasi {
// process management:
//
/// todo -> move to kernel logic to enable persistence etc.
async fn set_on_panic(&mut self, _on_panic: wit::OnPanic) -> Result<()> {
unimplemented!();
// let on_panic = match on_panic {
// wit::OnPanic::None => t::OnPanic::None,
// wit::OnPanic::Restart => t::OnPanic::Restart,
// wit::OnPanic::Requests(reqs) => t::OnPanic::Requests(
// reqs.into_iter()
// .map(|(addr, req, payload)| {
// (
// de_wit_address(addr),
// de_wit_request(req),
// de_wit_payload(payload),
// )
// })
// .collect(),
// ),
// };
// self.process.metadata.on_panic = on_panic;
// Ok(())
/// 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);
Ok(())
}
/// create a message from the *kernel* to the filesystem,
@ -210,7 +188,7 @@ impl UqProcessImports for ProcessWasi {
.unwrap(),
metadata: None,
},
Some(Payload { mime: None, bytes }),
Some(wit::Payload { mime: None, bytes }),
)
.await
{
@ -373,7 +351,7 @@ impl UqProcessImports for ProcessWasi {
ipc: serde_json::to_vec(&t::KernelCommand::StartProcess {
id: new_process_id.clone(),
wasm_bytes_handle: hash,
on_panic: de_wit_on_panic(on_panic),
on_panic: t::de_wit_on_panic(on_panic),
// TODO
initial_capabilities: match capabilities {
wit::Capabilities::None => HashSet::new(),
@ -539,11 +517,12 @@ impl UqProcessImports for ProcessWasi {
async fn attach_capability(&mut self, capability: wit::SignedCapability) -> Result<()> {
match self.process.next_message_caps {
None => {
self.process.next_message_caps = Some(vec![de_wit_signed_capability(capability)]);
self.process.next_message_caps =
Some(vec![t::de_wit_signed_capability(capability)]);
Ok(())
}
Some(ref mut v) => {
v.push(de_wit_signed_capability(capability));
v.push(t::de_wit_signed_capability(capability));
Ok(())
}
}
@ -677,7 +656,7 @@ impl UqProcessImports for ProcessWasi {
/// if the prompting message did not have a payload, will return None.
/// will also return None if there is no prompting message.
async fn get_payload(&mut self) -> Result<Option<wit::Payload>> {
Ok(en_wit_payload(self.process.last_payload.clone()))
Ok(t::en_wit_payload(self.process.last_payload.clone()))
}
async fn send_request(
@ -769,7 +748,7 @@ async fn send_and_await_response(
}
}
impl Process {
impl ProcessState {
/// save a context for a given request.
async fn save_context(
&mut self,
@ -862,11 +841,11 @@ impl Process {
}
},
Err(e) => match self.contexts.remove(&e.id) {
None => return Err((en_wit_send_error(e.error), None)),
None => return Err((t::en_wit_send_error(e.error), None)),
Some((context, timeout_handle)) => {
timeout_handle.abort();
self.prompting_message = context.prompting_message;
return Err((en_wit_send_error(e.error), context.context));
return Err((t::en_wit_send_error(e.error), context.context));
}
},
};
@ -877,9 +856,9 @@ impl Process {
Ok((
km.source.en_wit().to_owned(),
match km.message {
t::Message::Request(request) => wit::Message::Request(en_wit_request(request)),
t::Message::Request(request) => wit::Message::Request(t::en_wit_request(request)),
t::Message::Response((response, _context)) => {
wit::Message::Response((en_wit_response(response), context))
wit::Message::Response((t::en_wit_response(response), context))
}
},
))
@ -976,7 +955,7 @@ impl Process {
// no rsvp because neither prompting message nor this request wants a response
(_, None, None) => None,
},
message: t::Message::Request(de_wit_request(request.clone())),
message: t::Message::Request(t::de_wit_request(request.clone())),
payload: payload.clone(),
signed_capabilities: None,
};
@ -996,7 +975,7 @@ impl Process {
error: t::SendError {
kind: t::SendErrorKind::Timeout,
target: t::Address::de_wit(target),
message: t::Message::Request(de_wit_request(request.clone())),
message: t::Message::Request(t::de_wit_request(request.clone())),
payload,
},
}))
@ -1032,7 +1011,7 @@ impl Process {
let payload = match response.inherit {
true => self.last_payload.clone(),
false => de_wit_payload(payload),
false => t::de_wit_payload(payload),
};
self.send_to_loop
@ -1042,7 +1021,7 @@ impl Process {
target,
rsvp: None,
message: t::Message::Response((
de_wit_response(response),
t::de_wit_response(response),
// the context will be set by the process receiving this Response.
None,
)),
@ -1132,10 +1111,10 @@ async fn make_process_loop(
Component::new(&engine, wasm_bytes).expect("make_process_loop: couldn't read file");
let mut linker = Linker::new(&engine);
UqProcess::add_to_linker(&mut linker, |state: &mut ProcessWasi| state).unwrap();
Process::add_to_linker(&mut linker, |state: &mut ProcessWasi| state).unwrap();
let mut table = Table::new();
let wasi = WasiCtxBuilder::new().build(&mut table).unwrap();
let table = Table::new();
let wasi = WasiCtxBuilder::new().build(); // (&mut table).unwrap();
wasmtime_wasi::preview2::command::add_to_linker(&mut linker).unwrap();
// wasmtime_wasi::preview2::bindings::clocks::wall_clock::add_to_linker(&mut linker, |t| t)
@ -1160,7 +1139,7 @@ async fn make_process_loop(
let mut store = Store::new(
engine,
ProcessWasi {
process: Process {
process: ProcessState {
keypair: keypair.clone(),
metadata: metadata.clone(),
recv_in_process,
@ -1181,7 +1160,7 @@ async fn make_process_loop(
Box::pin(async move {
let (bindings, _bindings) =
match UqProcess::instantiate_async(&mut store, &component, &linker).await {
match Process::instantiate_async(&mut store, &component, &linker).await {
Ok(b) => b,
Err(e) => {
let _ = send_to_terminal
@ -1198,7 +1177,10 @@ async fn make_process_loop(
};
// the process will run until it returns from init()
let is_error = match bindings.call_init(&mut store, &metadata.our.en_wit()).await {
let is_error = match bindings
.call_init(&mut store, &metadata.our.to_string())
.await
{
Ok(()) => {
let _ =
send_to_terminal

View File

@ -1,118 +0,0 @@
use crate::kernel::component::uq_process::types as wit;
use crate::types as t;
//
// conversions between wit types and kernel types (annoying!)
//
pub fn en_wit_message(message: t::Message) -> wit::Message {
match message {
t::Message::Request(request) => wit::Message::Request(en_wit_request(request)),
t::Message::Response((response, context)) => {
wit::Message::Response((en_wit_response(response), context))
}
}
}
pub fn de_wit_request(wit: wit::Request) -> t::Request {
t::Request {
inherit: wit.inherit,
expects_response: wit.expects_response,
ipc: wit.ipc,
metadata: wit.metadata,
}
}
pub fn en_wit_request(request: t::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) -> t::Response {
t::Response {
inherit: wit.inherit,
ipc: wit.ipc,
metadata: wit.metadata,
}
}
pub fn en_wit_response(response: t::Response) -> wit::Response {
wit::Response {
inherit: response.inherit,
ipc: response.ipc,
metadata: response.metadata,
}
}
pub fn en_wit_send_error(error: t::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: t::SendErrorKind) -> wit::SendErrorKind {
match kind {
t::SendErrorKind::Offline => wit::SendErrorKind::Offline,
t::SendErrorKind::Timeout => wit::SendErrorKind::Timeout,
}
}
pub fn de_wit_payload(wit: Option<wit::Payload>) -> Option<t::Payload> {
match wit {
None => None,
Some(wit) => Some(t::Payload {
mime: wit.mime,
bytes: wit.bytes,
}),
}
}
pub fn en_wit_payload(payload: Option<t::Payload>) -> Option<wit::Payload> {
match payload {
None => None,
Some(payload) => Some(wit::Payload {
mime: payload.mime,
bytes: payload.bytes,
}),
}
}
pub fn de_wit_signed_capability(wit: wit::SignedCapability) -> t::SignedCapability {
t::SignedCapability {
issuer: t::Address::de_wit(wit.issuer),
params: wit.params,
signature: wit.signature,
}
}
// pub fn en_wit_signed_capability(cap: t::SignedCapability) -> wit::SignedCapability {
// wit::SignedCapability {
// issuer: cap.issuer.en_wit().to_owned(),
// params: cap.params,
// signature: cap.signature,
// }
// }
pub fn de_wit_on_panic(wit: wit::OnPanic) -> t::OnPanic {
match wit {
wit::OnPanic::None => t::OnPanic::None,
wit::OnPanic::Restart => t::OnPanic::Restart,
wit::OnPanic::Requests(reqs) => t::OnPanic::Requests(
reqs.into_iter()
.map(|(address, request, payload)| {
(
t::Address::de_wit(address),
de_wit_request(request),
de_wit_payload(payload),
)
})
.collect(),
),
}
}

View File

@ -1,3 +1,4 @@
use crate::types::*;
use anyhow::Result;
use dotenv;
use std::env;
@ -5,8 +6,6 @@ use std::sync::Arc;
use tokio::sync::{mpsc, oneshot};
use tokio::{fs, time::timeout};
use crate::types::*;
mod encryptor;
mod eth_rpc;
mod filesystem;

View File

@ -1,307 +0,0 @@
use serde::{Deserialize, Serialize};
use super::bindings::component::uq_process::types::*;
use super::bindings::{get_capability, share_capability, Address, Payload, ProcessId, SendError};
#[derive(Hash, Eq, PartialEq, Debug, Clone, Serialize, Deserialize)]
pub struct PackageId {
pub package_name: String,
pub 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
}
}
#[allow(dead_code)]
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
}
}
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",
}
}
}
impl Address {
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("@")
}
}
#[derive(Debug)]
pub enum AddressParseError {
TooManyColons,
MissingNodeId,
MissingField,
}
pub fn send_and_await_response(
target: &Address,
inherit: bool,
ipc: Vec<u8>,
metadata: Option<Json>,
payload: Option<&Payload>,
timeout: u64,
) -> Result<(Address, Message), SendError> {
super::bindings::send_and_await_response(
target,
&Request {
inherit,
expects_response: Some(timeout),
ipc,
metadata,
},
payload,
)
}
pub fn send_request(
target: &Address,
inherit: bool,
ipc: Vec<u8>,
metadata: Option<Json>,
context: Option<&Vec<u8>>,
payload: Option<&Payload>,
) {
super::bindings::send_request(
target,
&Request {
inherit,
expects_response: None,
ipc,
metadata,
},
context,
payload,
)
}
pub fn get_state<T: serde::de::DeserializeOwned>() -> Option<T> {
match super::bindings::get_state() {
Some(bytes) => match bincode::deserialize::<T>(&bytes) {
Ok(state) => Some(state),
Err(_) => None,
},
None => None,
}
}
pub fn set_state<T>(state: &T)
where
T: serde::Serialize,
{
super::bindings::set_state(&bincode::serialize(state).unwrap());
}
pub fn parse_message_ipc<T>(json_bytes: &[u8]) -> anyhow::Result<T>
where
for<'a> T: serde::Deserialize<'a>,
{
let parsed: T = serde_json::from_slice(json_bytes)?;
Ok(parsed)
}
pub fn grant_messaging(our: &Address, grant_to: &Vec<ProcessId>) {
let Some(our_messaging_cap) = get_capability(
our,
&"\"messaging\"".into()
) else {
panic!("missing self-messaging cap!")
};
for process in grant_to {
share_capability(&process, &our_messaging_cap);
}
}
// move these to better place!
#[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,
}

View File

@ -1,4 +1,4 @@
use crate::kernel::component::uq_process::types as wit;
use crate::kernel::uqbar::process::standard as wit;
use ring::signature;
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
@ -16,93 +16,14 @@ lazy_static::lazy_static! {
}
//
// internal message pipes between kernel and runtime modules
// types shared between kernel and processes. frustratingly, this is an exact copy
// of the types in process_lib/src/kernel_types.rs
// this is because even though the types are identical, they will not match when
// used in the kernel context which generates bindings differently than the process
// standard library. make sure to keep this synced with kernel_types.rs
//
// keeps the from address so we know where to pipe error
pub type NetworkErrorSender = tokio::sync::mpsc::Sender<WrappedSendError>;
pub type NetworkErrorReceiver = tokio::sync::mpsc::Receiver<WrappedSendError>;
pub type MessageSender = tokio::sync::mpsc::Sender<KernelMessage>;
pub type MessageReceiver = tokio::sync::mpsc::Receiver<KernelMessage>;
pub type PrintSender = tokio::sync::mpsc::Sender<Printout>;
pub type PrintReceiver = tokio::sync::mpsc::Receiver<Printout>;
pub type DebugSender = tokio::sync::mpsc::Sender<DebugCommand>;
pub type DebugReceiver = tokio::sync::mpsc::Receiver<DebugCommand>;
pub type CapMessageSender = tokio::sync::mpsc::Sender<CapMessage>;
pub type CapMessageReceiver = tokio::sync::mpsc::Receiver<CapMessage>;
//
// types used for UQI: uqbar's identity system
//
pub type NodeId = String;
#[derive(Debug, Serialize, Deserialize)]
pub struct Registration {
pub username: NodeId,
pub password: String,
pub direct: bool,
}
#[derive(Debug)]
pub struct Keyfile {
pub username: String,
pub routers: Vec<String>,
pub networking_keypair: signature::Ed25519KeyPair,
pub jwt_secret_bytes: Vec<u8>,
pub file_key: Vec<u8>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct KeyfileVet {
pub password: String,
pub keyfile: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct KeyfileVetted {
pub username: String,
pub networking_key: String,
pub routers: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BootInfo {
pub password: String,
pub keyfile: String,
pub username: String,
pub reset: bool,
pub direct: bool,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Identity {
pub name: NodeId,
pub networking_key: String,
pub ws_routing: Option<(String, u16)>,
pub allowed_routers: Vec<NodeId>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct IdentityTransaction {
pub from: String,
pub signature: Option<String>,
pub to: String, // contract address
pub town_id: u32,
pub calldata: Identity,
pub nonce: String,
}
//
// 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.
@ -121,10 +42,9 @@ 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: match process_name {
Some(name) => name.to_string(),
None => rand::random::<u64>().to_string(),
},
process_name: process_name
.unwrap_or(&rand::random::<u64>().to_string())
.into(),
package_name: package_name.into(),
publisher_node: publisher_node.into(),
}
@ -260,7 +180,7 @@ pub struct SignedCapability {
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct SendError {
pub kind: SendErrorKind,
pub target: Address, // what the message was trying to reach
pub target: Address,
pub message: Message,
pub payload: Option<Payload>,
}
@ -288,6 +208,264 @@ impl OnPanic {
}
}
//
// 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: {},\n metadata: {}\n )",
request.inherit,
request.expects_response,
match serde_json::from_slice::<serde_json::Value>(&request.ipc) {
Ok(json) => format!("{}", json),
Err(_) => format!("{:?}", request.ipc),
},
&request.metadata.as_ref().unwrap_or(&"None".into()),
),
Message::Response((response, context)) => write!(
f,
"Response(\n inherit: {},\n ipc: {},\n metadata: {},\n context: {}\n )",
response.inherit,
match serde_json::from_slice::<serde_json::Value>(&response.ipc) {
Ok(json) => format!("{}", json),
Err(_) => format!("{:?}", response.ipc),
},
&response.metadata.as_ref().unwrap_or(&"None".into()),
if context.is_none() {
"None".into()
} else {
match serde_json::from_slice::<serde_json::Value>(&context.as_ref().unwrap()) {
Ok(json) => format!("{}", json),
Err(_) => format!("{:?}", context.as_ref().unwrap()),
}
},
),
}
}
}
//
// 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(),
),
}
}
//
// END SYNC WITH kernel_types.rs
//
//
// internal message pipes between kernel and runtime modules
//
// keeps the from address so we know where to pipe error
pub type NetworkErrorSender = tokio::sync::mpsc::Sender<WrappedSendError>;
pub type NetworkErrorReceiver = tokio::sync::mpsc::Receiver<WrappedSendError>;
pub type MessageSender = tokio::sync::mpsc::Sender<KernelMessage>;
pub type MessageReceiver = tokio::sync::mpsc::Receiver<KernelMessage>;
pub type PrintSender = tokio::sync::mpsc::Sender<Printout>;
pub type PrintReceiver = tokio::sync::mpsc::Receiver<Printout>;
pub type DebugSender = tokio::sync::mpsc::Sender<DebugCommand>;
pub type DebugReceiver = tokio::sync::mpsc::Receiver<DebugCommand>;
pub type CapMessageSender = tokio::sync::mpsc::Sender<CapMessage>;
pub type CapMessageReceiver = tokio::sync::mpsc::Receiver<CapMessage>;
//
// types used for UQI: uqbar's identity system
//
#[derive(Debug, Serialize, Deserialize)]
pub struct Registration {
pub username: NodeId,
pub password: String,
pub direct: bool,
}
#[derive(Debug)]
pub struct Keyfile {
pub username: String,
pub routers: Vec<String>,
pub networking_keypair: signature::Ed25519KeyPair,
pub jwt_secret_bytes: Vec<u8>,
pub file_key: Vec<u8>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct KeyfileVet {
pub password: String,
pub keyfile: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct KeyfileVetted {
pub username: String,
pub networking_key: String,
pub routers: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BootInfo {
pub password: String,
pub keyfile: String,
pub username: String,
pub reset: bool,
pub direct: bool,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Identity {
pub name: NodeId,
pub networking_key: String,
pub ws_routing: Option<(String, u16)>,
pub allowed_routers: Vec<NodeId>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct IdentityTransaction {
pub from: String,
pub signature: Option<String>,
pub to: String, // contract address
pub town_id: u32,
pub calldata: Identity,
pub nonce: String,
}
//
// kernel types that runtime modules use
//
@ -707,18 +885,6 @@ impl HttpClientError {
// custom kernel displays
//
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 KernelMessage {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(
@ -737,42 +903,6 @@ impl std::fmt::Display for KernelMessage {
}
}
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: {},\n metadata: {}\n )",
request.inherit,
request.expects_response,
match serde_json::from_slice::<serde_json::Value>(&request.ipc) {
Ok(json) => format!("{}", json),
Err(_) => format!("{:?}", request.ipc),
},
&request.metadata.as_ref().unwrap_or(&"None".into()),
),
Message::Response((response, context)) => write!(
f,
"Response(\n inherit: {},\n ipc: {},\n metadata: {},\n context: {}\n )",
response.inherit,
match serde_json::from_slice::<serde_json::Value>(&response.ipc) {
Ok(json) => format!("{}", json),
Err(_) => format!("{:?}", response.ipc),
},
&response.metadata.as_ref().unwrap_or(&"None".into()),
if context.is_none() {
"None".into()
} else {
match serde_json::from_slice::<serde_json::Value>(&context.as_ref().unwrap()) {
Ok(json) => format!("{}", json),
Err(_) => format!("{:?}", context.as_ref().unwrap()),
}
},
),
}
}
}
//
// http_server.rs types
//

Binary file not shown.

View File

@ -1,16 +1,16 @@
package component:uq-process@0.2.0
package uqbar:process@0.4.0;
interface types {
interface standard {
// JSON is passed over WASM boundary as a string.
type json = string
type json = string;
type node-id = string
type node-id = string;
// context, like ipc, is a protocol-defined cap'n proto schema
// context, like ipc, is a protocol-defined serialized byte array.
// it is used when building a Request to save information
// that will not be part of a Response, in order to more
// easily handle ("contextualize") that Response.
type context = list<u8>
type context = list<u8>;
record process-id {
process-name: string,
@ -100,104 +100,89 @@ interface types {
no-file-at-path,
// TODO more here?
}
}
world uq-process {
use types.{
json,
node-id,
context,
process-id,
address,
payload,
request,
response,
message,
capabilities,
signed-capability,
on-panic,
send-error,
send-error-kind,
spawn-error
}
// entry point to all programs
export init: func(our: address)
// system utils:
import print-to-terminal: func(verbosity: u8, message: string)
print-to-terminal: func(verbosity: u8, message: string);
// **more will be added here with regard to blockchains**
import get-eth-block: func() -> u64
get-eth-block: func() -> u64;
// process management:
import set-on-panic: func(on-panic: on-panic)
set-on-panic: func(on-panic: on-panic);
import get-state: func() -> option<list<u8>>
get-state: func() -> option<list<u8>>;
import set-state: func(bytes: list<u8>)
set-state: func(bytes: list<u8>);
import clear-state: func()
clear-state: func();
import spawn: func(
spawn: func(
name: option<string>,
wasm-path: string, // must be located within package's drive
on-panic: on-panic,
capabilities: capabilities,
public: bool
) -> result<process-id, spawn-error>
) -> result<process-id, spawn-error>;
// capabilities management
// gives us all our signed capabilities so we can send them to others
import get-capabilities: func() -> list<signed-capability>
get-capabilities: func() -> list<signed-capability>;
// gets a single specific capability
import get-capability: func(issuer: address, params: json) -> option<signed-capability>
get-capability: func(issuer: address, params: json) -> option<signed-capability>;
// attaches a specific signed capability to our next message
import attach-capability: func(capability: signed-capability)
attach-capability: func(capability: signed-capability);
// saves capabilities to our store, so we can use them
import save-capabilities: func(capabilities: list<signed-capability>)
save-capabilities: func(capabilities: list<signed-capability>);
// check to see if the sender of a prompting message has a given capability, issued by us
// if the prompting message has a remote source, they must have attached it.
import has-capability: func(params: json) -> bool
has-capability: func(params: json) -> bool;
// generates a new capability with our process as the issuer and gives it to the target,
// which must be a locally-running process.
import create-capability: func(to: process-id, params: json)
create-capability: func(to: process-id, params: json);
// take a signed capability and save it to a given locally-running process
import share-capability: func(to: process-id, capability: signed-capability)
share-capability: func(to: process-id, capability: signed-capability);
// message I/O:
// ingest next message when it arrives along with its source.
// almost all long-running processes will call this in a loop
import receive: func() -> result<tuple<address, message>, tuple<send-error, option<context>>>
receive: func() -> result<tuple<address, message>, tuple<send-error, option<context>>>;
// gets payload, if any, of the message we just received
import get-payload: func() -> option<payload>
get-payload: func() -> option<payload>;
// send message(s) to target(s)
import send-request:
func(target: address, request: request, context: option<context>, payload: option<payload>)
import send-requests:
func(requests: list<tuple<address, request, option<context>, option<payload>>>)
import send-response:
func(response: response, payload: option<payload>)
send-request:
func(target: address, request: request, context: option<context>, payload: option<payload>);
send-requests:
func(requests: list<tuple<address, request, option<context>, option<payload>>>);
send-response:
func(response: response, payload: option<payload>);
// send a single request, then block (internally) until its response
// the type is Message but will always contain Response
import send-and-await-response:
send-and-await-response:
func(target: address, request: request, payload: option<payload>) ->
result<tuple<address, message>, send-error>
result<tuple<address, message>, send-error>;
}
world lib {
import standard;
}
world process {
include lib;
export init: func(our: string);
}