mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-11-26 11:53:31 +03:00
fix build bug, fix app_tracker bugs, add share_capability fn to uqbar.wit
This commit is contained in:
parent
54bfff0715
commit
0684daac84
4
build.rs
4
build.rs
@ -36,6 +36,8 @@ where
|
||||
fn build_app(target_path: &str, name: &str, parent_pkg_path: Option<&str>) {
|
||||
let pwd = std::env::current_dir().unwrap();
|
||||
|
||||
println!("cargo:warning=building {}", target_path);
|
||||
|
||||
// Copy in newly-made wit IF old one is outdated
|
||||
if file_outdated(
|
||||
format!("{}/wit/", pwd.display()),
|
||||
@ -179,7 +181,7 @@ fn main() {
|
||||
let package_name = entry_path.file_name().unwrap().to_str().unwrap();
|
||||
// NOT YET building KV, waiting for deps to be ready
|
||||
if package_name == "key_value" {
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
// If Cargo.toml is present, build the app
|
||||
|
@ -1,7 +1,8 @@
|
||||
cargo_component_bindings::generate!();
|
||||
|
||||
use bindings::{
|
||||
component::uq_process::types::*, get_capability, get_payload, print_to_terminal, receive, Guest, send_request, send_response
|
||||
component::uq_process::types::*, get_capability, get_payload, print_to_terminal, receive,
|
||||
send_request, send_response, Guest,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashSet;
|
||||
@ -118,7 +119,6 @@ fn parse_command(our: &Address, request_string: String) -> anyhow::Result<Apptra
|
||||
format!("/{}", entry.process_wasm_path)
|
||||
};
|
||||
|
||||
|
||||
let (_, hash_response) = process_lib::send_and_await_response(
|
||||
&vfs_address,
|
||||
false,
|
||||
@ -134,7 +134,6 @@ fn parse_command(our: &Address, request_string: String) -> anyhow::Result<Apptra
|
||||
5,
|
||||
)?;
|
||||
|
||||
|
||||
let Message::Response((Response { ipc: Some(ipc), .. }, _)) = hash_response else {
|
||||
return Err(anyhow::anyhow!("bad vfs response"));
|
||||
};
|
||||
@ -178,12 +177,42 @@ fn parse_command(our: &Address, request_string: String) -> anyhow::Result<Apptra
|
||||
initial_capabilities.insert(kt::de_wit_signed_capability(write_cap));
|
||||
let mut public = false;
|
||||
|
||||
for process_name in &entry.grant_messaging {
|
||||
if process_name == "all" {
|
||||
public = true;
|
||||
continue;
|
||||
let entry_process_id = match ProcessId::from_str(
|
||||
&[entry.process_name.clone(), ":".into(), package.clone()].concat(),
|
||||
) {
|
||||
Ok(process_id) => process_id,
|
||||
Err(_) => {
|
||||
return Err(anyhow::anyhow!("app_tracker: invalid process id!"));
|
||||
}
|
||||
};
|
||||
|
||||
// let Some(messaging_cap) = get_capability(
|
||||
// &Address {
|
||||
// node: our.node.clone(),
|
||||
// process: entry_process_id,
|
||||
// },
|
||||
// &"\"messaging\"".into()
|
||||
// ) else {
|
||||
// return Err(anyhow::anyhow!(
|
||||
// "app_tracker: no messaging cap for {} to give away!",
|
||||
// entry.process_name,
|
||||
// ));
|
||||
// };
|
||||
// for process_name in &entry.grant_messaging {
|
||||
// if process_name == "all" {
|
||||
// public = true;
|
||||
// continue;
|
||||
// }
|
||||
// let Ok(parsed_process_id) = ProcessId::from_str(&process_name) else {
|
||||
// // TODO handle arbitrary caps here
|
||||
// continue;
|
||||
// };
|
||||
// bindings::share_capability(&parsed_process_id, &messaging_cap);
|
||||
// }
|
||||
|
||||
for process_name in &entry.request_messaging {
|
||||
let Ok(parsed_process_id) = ProcessId::from_str(&process_name) else {
|
||||
// TODO handle arbitrary caps here
|
||||
continue;
|
||||
};
|
||||
let Some(messaging_cap) = get_capability(
|
||||
@ -193,31 +222,12 @@ fn parse_command(our: &Address, request_string: String) -> anyhow::Result<Apptra
|
||||
},
|
||||
&"\"messaging\"".into()
|
||||
) else {
|
||||
return Err(anyhow::anyhow!(format!("app_tracker: no cap for {}", process_name)));
|
||||
print_to_terminal(0, &format!("app_tracker: no cap for {} to give away!", process_name));
|
||||
continue;
|
||||
};
|
||||
initial_capabilities.insert(kt::de_wit_signed_capability(messaging_cap));
|
||||
}
|
||||
|
||||
// // TODO fix request?
|
||||
// for process_name in &entry.request_messaging {
|
||||
// let Ok(parsed_process_id) = ProcessId::from_str(process_name) else {
|
||||
// continue;
|
||||
// };
|
||||
// let Some(messaging_cap) = get_capability(
|
||||
// &Address {
|
||||
// node: our.node.clone(),
|
||||
// process: parsed_process_id.clone(),
|
||||
// },
|
||||
// &serde_json::to_string(&serde_json::json!({
|
||||
// "messaging": kt::ProcessId::de_wit(parsed_process_id),
|
||||
// })).unwrap(),
|
||||
// ) else {
|
||||
// return Err(anyhow::anyhow!(format!("app_tracker: no cap for {}", process_name)));
|
||||
// };
|
||||
// initial_capabilities.insert(kt::de_wit_signed_capability(messaging_cap));
|
||||
// }
|
||||
|
||||
|
||||
let process_id = format!("{}:{}", entry.process_name, package.clone());
|
||||
let Ok(parsed_new_process_id) = ProcessId::from_str(&process_id) else {
|
||||
return Err(anyhow::anyhow!("app_tracker: invalid process id!"));
|
||||
@ -229,8 +239,11 @@ fn parse_command(our: &Address, request_string: String) -> anyhow::Result<Apptra
|
||||
},
|
||||
false,
|
||||
Some(
|
||||
serde_json::to_string(
|
||||
&kt::KernelCommand::KillProcess(kt::ProcessId::de_wit(parsed_new_process_id.clone()))).unwrap()),
|
||||
serde_json::to_string(&kt::KernelCommand::KillProcess(
|
||||
kt::ProcessId::de_wit(parsed_new_process_id.clone()),
|
||||
))
|
||||
.unwrap(),
|
||||
),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
@ -277,7 +290,6 @@ fn parse_command(our: &Address, request_string: String) -> anyhow::Result<Apptra
|
||||
Some(&payload),
|
||||
5,
|
||||
)?;
|
||||
|
||||
}
|
||||
Ok(ApptrackerResponse::Install { package })
|
||||
}
|
||||
@ -302,7 +314,12 @@ impl Guest for Component {
|
||||
}
|
||||
};
|
||||
match message {
|
||||
Message::Request(Request { ipc, expects_response, metadata, .. }) => {
|
||||
Message::Request(Request {
|
||||
ipc,
|
||||
expects_response,
|
||||
metadata,
|
||||
..
|
||||
}) => {
|
||||
let Some(command) = ipc else {
|
||||
continue;
|
||||
};
|
||||
|
@ -619,9 +619,8 @@ impl UqProcessImports for ProcessWasi {
|
||||
cap: cap.clone(),
|
||||
responder: tx,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
let _ = rx.await.unwrap();
|
||||
.await?;
|
||||
let _ = rx.await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@ -678,8 +677,36 @@ impl UqProcessImports for ProcessWasi {
|
||||
},
|
||||
responder: tx,
|
||||
})
|
||||
.await;
|
||||
let _ = rx.await.unwrap();
|
||||
.await?;
|
||||
let _ = rx.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn share_capability(
|
||||
&mut self,
|
||||
to: wit::ProcessId,
|
||||
signed_cap: wit::SignedCapability,
|
||||
) -> Result<()> {
|
||||
let pk = signature::UnparsedPublicKey::new(
|
||||
&signature::ED25519,
|
||||
self.process.keypair.public_key(),
|
||||
);
|
||||
let cap = t::Capability {
|
||||
issuer: t::Address::de_wit(signed_cap.issuer),
|
||||
params: signed_cap.params,
|
||||
};
|
||||
pk.verify(&bincode::serialize(&cap).unwrap(), &signed_cap.signature)?;
|
||||
let (tx, rx) = tokio::sync::oneshot::channel();
|
||||
let _ = self
|
||||
.process
|
||||
.caps_oracle
|
||||
.send(t::CapMessage::Add {
|
||||
on: t::ProcessId::de_wit(to),
|
||||
cap,
|
||||
responder: tx,
|
||||
})
|
||||
.await?;
|
||||
let _ = rx.await?;
|
||||
Ok(())
|
||||
}
|
||||
//
|
||||
@ -1194,13 +1221,24 @@ 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 {
|
||||
Ok(()) => false,
|
||||
Ok(()) => {
|
||||
let _ = send_to_terminal
|
||||
.send(t::Printout {
|
||||
verbosity: 0,
|
||||
content: format!(
|
||||
"process {:?} returned without error",
|
||||
metadata.our.process,
|
||||
),
|
||||
})
|
||||
.await;
|
||||
false
|
||||
}
|
||||
Err(e) => {
|
||||
let _ = send_to_terminal
|
||||
.send(t::Printout {
|
||||
verbosity: 0,
|
||||
content: format!(
|
||||
"mk: process {:?} ended with error:",
|
||||
"process {:?} ended with error:",
|
||||
metadata.our.process,
|
||||
),
|
||||
})
|
||||
@ -1419,6 +1457,15 @@ async fn handle_kernel_request(
|
||||
valid_capabilities.insert(cap);
|
||||
}
|
||||
|
||||
// always give process the messaging cap for itself
|
||||
valid_capabilities.insert(t::Capability {
|
||||
issuer: t::Address {
|
||||
node: our_name.clone(),
|
||||
process: id.clone(),
|
||||
},
|
||||
params: "\"messaging\"".into(),
|
||||
});
|
||||
|
||||
// fires "success" response back
|
||||
start_process(
|
||||
our_name,
|
||||
|
@ -56,6 +56,16 @@ impl ProcessId {
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -172,6 +172,9 @@ world uq-process {
|
||||
// which must be a locally-running process.
|
||||
import 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)
|
||||
|
||||
|
||||
// message I/O:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user