Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terminal: m caps #596

Open
wants to merge 3 commits into
base: v0.10.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions kinode/packages/terminal/m/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::{Arg, Command};
use kinode_process_lib::{println, script, Address, Request, SendErrorKind};
use kinode_process_lib::{our_capabilities, println, script, Address, Request, SendErrorKind};
use regex::Regex;

wit_bindgen::generate!({
Expand All @@ -10,7 +10,7 @@ wit_bindgen::generate!({
const USAGE: &str = "\x1b[1mUsage:\x1b[0m m <target> <body> [-a <await_time>]";

script!(init);
fn init(_our: Address, args: String) -> String {
fn init(our: Address, args: String) -> String {
if args.is_empty() {
return format!("Send a request to a process.\n{USAGE}");
}
Expand Down Expand Up @@ -58,7 +58,21 @@ fn init(_our: Address, args: String) -> String {
return format!("No body given.\n{USAGE}");
};

let req = Request::new().target(target).body(body.as_bytes().to_vec());
let target = if target.node() != "our" {
target
} else {
Address::new(our.node(), target.process)
};

let capabilities = our_capabilities()
.into_iter()
.filter(|cap| cap.issuer == target)
.collect();

let req = Request::new()
.target(target)
.body(body.as_bytes().to_vec())
.capabilities(capabilities);

match parsed.get_one::<u64>("await") {
Some(s) => {
Expand Down
16 changes: 16 additions & 0 deletions kinode/packages/terminal/pkg/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@
"request_capabilities": [
"app-store:app-store:sys",
"contacts:contacts:sys",
{
"process": "contacts:contacts:sys",
"params": "ReadNameOnly"
},
{
"process": "contacts:contacts:sys",
"params": "Read"
},
{
"process": "contacts:contacts:sys",
"params": "Add"
},
{
"process": "contacts:contacts:sys",
"params": "Remove"
},
"chess:chess:sys",
"eth:distro:sys",
{
Expand Down
10 changes: 4 additions & 6 deletions kinode/src/kernel/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,12 +507,10 @@ pub async fn make_process_loop(
reinitialize.await;
None
}
Some(wait_till) => {
Some(tokio::spawn(async move {
tokio::time::sleep_until(wait_till).await;
reinitialize.await;
}))
}
Some(wait_till) => Some(tokio::spawn(async move {
tokio::time::sleep_until(wait_till).await;
reinitialize.await;
})),
};
*restart_backoff_lock = Some(RestartBackoff {
next_soonest_restart_time,
Expand Down