From 62c113d64303b6a94f8975a0e09ea7172277e1eb Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Fri, 12 Jul 2024 14:55:31 -0700 Subject: [PATCH 1/8] new: improve templates --- Cargo.lock | 2 +- Cargo.toml | 2 +- .../no-ui/chat/{package_name}/Cargo.toml_ | 2 +- .../rust/no-ui/chat/{package_name}/src/lib.rs | 36 +-- .../no-ui/echo/{package_name}/Cargo.toml_ | 1 + .../rust/no-ui/echo/{package_name}/src/lib.rs | 21 +- .../fibonacci/{package_name}/Cargo.toml_ | 1 + .../no-ui/fibonacci/{package_name}/src/lib.rs | 28 +- .../no-ui/file_transfer/download/Cargo.toml_ | 1 + .../no-ui/file_transfer/download/src/lib.rs | 19 +- .../file_transfer/list_files/Cargo.toml_ | 1 + .../no-ui/file_transfer/list_files/src/lib.rs | 6 +- .../rust/no-ui/file_transfer/pkg/scripts.json | 6 +- .../no-ui/file_transfer/worker/Cargo.toml_ | 1 + .../no-ui/file_transfer/worker/src/lib.rs | 247 +++++++++--------- .../file_transfer/{package_name}/Cargo.toml_ | 3 +- .../file_transfer/{package_name}/src/lib.rs | 45 ++-- 17 files changed, 206 insertions(+), 216 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3b4814d4..6351a3ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1640,7 +1640,7 @@ dependencies = [ [[package]] name = "kit" -version = "0.6.6" +version = "0.6.7" dependencies = [ "anyhow", "base64 0.21.7", diff --git a/Cargo.toml b/Cargo.toml index 85f480bb..d9b288c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kit" -version = "0.6.6" +version = "0.6.7" edition = "2021" [build-dependencies] diff --git a/src/new/templates/rust/no-ui/chat/{package_name}/Cargo.toml_ b/src/new/templates/rust/no-ui/chat/{package_name}/Cargo.toml_ index c73909b5..04bd8918 100644 --- a/src/new/templates/rust/no-ui/chat/{package_name}/Cargo.toml_ +++ b/src/new/templates/rust/no-ui/chat/{package_name}/Cargo.toml_ @@ -5,8 +5,8 @@ edition = "2021" [dependencies] anyhow = "1.0" -bincode = "1.3.3" kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.0" } +process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" wit-bindgen = "0.24.0" diff --git a/src/new/templates/rust/no-ui/chat/{package_name}/src/lib.rs b/src/new/templates/rust/no-ui/chat/{package_name}/src/lib.rs index 4550b7c9..6b64b14f 100644 --- a/src/new/templates/rust/no-ui/chat/{package_name}/src/lib.rs +++ b/src/new/templates/rust/no-ui/chat/{package_name}/src/lib.rs @@ -1,28 +1,29 @@ use std::collections::HashMap; -use std::str::FromStr; use crate::kinode::process::{package_name}::{ChatMessage, Request as ChatRequest, Response as ChatResponse, SendRequest}; -use kinode_process_lib::{await_message, call_init, println, Address, ProcessId, Request, Response}; +use kinode_process_lib::{await_message, call_init, println, Address, Message, Request, Response}; wit_bindgen::generate!({ path: "target/wit", world: "{package_name_kebab}-{publisher_dotted_kebab}-v0", generate_unused_types: true, - additional_derives: [serde::Deserialize, serde::Serialize], + additional_derives: [serde::Deserialize, serde::Serialize, process_macros::SerdeJsonInto], }); type MessageArchive = HashMap>; -fn handle_message(our: &Address, message_archive: &mut MessageArchive) -> anyhow::Result<()> { - let message = await_message()?; - +fn handle_message( + our: &Address, + message: &Message, + message_archive: &mut MessageArchive, +) -> anyhow::Result<()> { if !message.is_request() { return Err(anyhow::anyhow!("unexpected Response: {:?}", message)); } let body = message.body(); let source = message.source(); - match serde_json::from_slice(body)? { + match body.try_into()? { ChatRequest::Send(SendRequest { ref target, ref message, @@ -41,9 +42,7 @@ fn handle_message(our: &Address, message_archive: &mut MessageArchive) -> anyhow let _ = Request::new() .target(Address { node: target.clone(), - process: ProcessId::from_str( - "{package_name}:{package_name}:{publisher}", - )?, + process: "{package_name}:{package_name}:{publisher}".parse()?, }) .body(body) .send_and_await_response(5)? @@ -58,18 +57,18 @@ fn handle_message(our: &Address, message_archive: &mut MessageArchive) -> anyhow .or_insert(vec![message]); } Response::new() - .body(serde_json::to_vec(&ChatResponse::Send).unwrap()) + .body(ChatResponse::Send) .send() .unwrap(); } ChatRequest::History(ref node) => { Response::new() - .body(serde_json::to_vec(&ChatResponse::History( + .body(ChatResponse::History( message_archive .get(node) .map(|msgs| msgs.clone()) .unwrap_or_default() - )).unwrap()) + )) .send() .unwrap(); } @@ -84,11 +83,12 @@ fn init(our: Address) { let mut message_archive = HashMap::new(); loop { - match handle_message(&our, &mut message_archive) { - Ok(()) => {} - Err(e) => { - println!("error: {:?}", e); + match await_message() { + Err(send_error) => println!("got SendError: {send_error}"), + Ok(ref message) => match handle_message(&our, message, &mut message_archive) { + Ok(_) => {} + Err(e) => println!("got error while handling message: {e:?}"), } - }; + } } } diff --git a/src/new/templates/rust/no-ui/echo/{package_name}/Cargo.toml_ b/src/new/templates/rust/no-ui/echo/{package_name}/Cargo.toml_ index c73909b5..183d81b8 100644 --- a/src/new/templates/rust/no-ui/echo/{package_name}/Cargo.toml_ +++ b/src/new/templates/rust/no-ui/echo/{package_name}/Cargo.toml_ @@ -7,6 +7,7 @@ edition = "2021" anyhow = "1.0" bincode = "1.3.3" kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.0" } +process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" wit-bindgen = "0.24.0" diff --git a/src/new/templates/rust/no-ui/echo/{package_name}/src/lib.rs b/src/new/templates/rust/no-ui/echo/{package_name}/src/lib.rs index 9b0137fe..f4dd36a3 100644 --- a/src/new/templates/rust/no-ui/echo/{package_name}/src/lib.rs +++ b/src/new/templates/rust/no-ui/echo/{package_name}/src/lib.rs @@ -1,13 +1,11 @@ -use kinode_process_lib::{await_message, call_init, println, Address, Response}; +use kinode_process_lib::{await_message, call_init, println, Address, Message, Response}; wit_bindgen::generate!({ path: "target/wit", world: "process-v0", }); -fn handle_message(_our: &Address) -> anyhow::Result<()> { - let message = await_message()?; - +fn handle_message(message: &Message) -> anyhow::Result<()> { if !message.is_request() { return Err(anyhow::anyhow!("unexpected Response: {:?}", message)); } @@ -22,15 +20,16 @@ fn handle_message(_our: &Address) -> anyhow::Result<()> { } call_init!(init); -fn init(our: Address) { +fn init(_our: Address) { println!("begin"); loop { - match handle_message(&our) { - Ok(()) => {} - Err(e) => { - println!("error: {:?}", e); - } - }; + match await_message() { + Err(send_error) => println!("got SendError: {send_error}"), + Ok(ref message) => match handle_message(message) { + Ok(_) => {} + Err(e) => println!("got error while handling message: {e:?}"), + }, + } } } diff --git a/src/new/templates/rust/no-ui/fibonacci/{package_name}/Cargo.toml_ b/src/new/templates/rust/no-ui/fibonacci/{package_name}/Cargo.toml_ index c73909b5..183d81b8 100644 --- a/src/new/templates/rust/no-ui/fibonacci/{package_name}/Cargo.toml_ +++ b/src/new/templates/rust/no-ui/fibonacci/{package_name}/Cargo.toml_ @@ -7,6 +7,7 @@ edition = "2021" anyhow = "1.0" bincode = "1.3.3" kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.0" } +process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" wit-bindgen = "0.24.0" diff --git a/src/new/templates/rust/no-ui/fibonacci/{package_name}/src/lib.rs b/src/new/templates/rust/no-ui/fibonacci/{package_name}/src/lib.rs index 89b6952c..17cd1cac 100644 --- a/src/new/templates/rust/no-ui/fibonacci/{package_name}/src/lib.rs +++ b/src/new/templates/rust/no-ui/fibonacci/{package_name}/src/lib.rs @@ -1,11 +1,11 @@ use crate::kinode::process::{package_name}::{Request as FibonacciRequest, Response as FibonacciResponse}; -use kinode_process_lib::{await_message, call_init, println, Address, Response}; +use kinode_process_lib::{await_message, call_init, println, Address, Message, Response}; wit_bindgen::generate!({ path: "target/wit", world: "{package_name_kebab}-{publisher_dotted_kebab}-v0", generate_unused_types: true, - additional_derives: [serde::Deserialize, serde::Serialize], + additional_derives: [serde::Deserialize, serde::Serialize, process_macros::SerdeJsonInto], }); /// calculate the nth Fibonacci number @@ -26,14 +26,12 @@ fn fibonacci(n: u32) -> u64 { b } -fn handle_message() -> anyhow::Result<()> { - let message = await_message()?; - +fn handle_message(message: &Message) -> anyhow::Result<()> { if !message.is_request() { return Err(anyhow::anyhow!("expected a request")); } - match serde_json::from_slice(message.body())? { + match message.body().try_into()? { FibonacciRequest::Number(number) => { let start = std::time::Instant::now(); let result = fibonacci(number); @@ -45,7 +43,7 @@ fn handle_message() -> anyhow::Result<()> { duration.as_nanos(), ); Response::new() - .body(serde_json::to_vec(&FibonacciResponse::Number(result)).unwrap()) + .body(FibonacciResponse::Number(result)) .send() .unwrap(); } @@ -73,10 +71,7 @@ fn handle_message() -> anyhow::Result<()> { number, result, mean, absolute_deviation, number_trials, ); Response::new() - .body( - serde_json::to_vec(&FibonacciResponse::Numbers((result, number_trials))) - .unwrap(), - ) + .body(FibonacciResponse::Numbers((result, number_trials))) .send() .unwrap(); } @@ -89,11 +84,12 @@ fn init(_our: Address) { println!("begin"); loop { - match handle_message() { - Ok(()) => {} - Err(e) => { - println!("error: {:?}", e); + match await_message() { + Err(send_error) => println!("got SendError: {send_error}"), + Ok(ref message) => match handle_message(message) { + Ok(_) => {} + Err(e) => println!("got error while handling message: {e:?}"), } - }; + } } } diff --git a/src/new/templates/rust/no-ui/file_transfer/download/Cargo.toml_ b/src/new/templates/rust/no-ui/file_transfer/download/Cargo.toml_ index 9355a413..27e6ffca 100644 --- a/src/new/templates/rust/no-ui/file_transfer/download/Cargo.toml_ +++ b/src/new/templates/rust/no-ui/file_transfer/download/Cargo.toml_ @@ -6,6 +6,7 @@ edition = "2021" [dependencies] anyhow = "1.0" kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.0" } +process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" wit-bindgen = "0.24.0" diff --git a/src/new/templates/rust/no-ui/file_transfer/download/src/lib.rs b/src/new/templates/rust/no-ui/file_transfer/download/src/lib.rs index 5a10f6c4..d26491ce 100644 --- a/src/new/templates/rust/no-ui/file_transfer/download/src/lib.rs +++ b/src/new/templates/rust/no-ui/file_transfer/download/src/lib.rs @@ -8,7 +8,7 @@ wit_bindgen::generate!({ path: "target/wit", world: "{package_name_kebab}-{publisher_dotted_kebab}-v0", generate_unused_types: true, - additional_derives: [serde::Deserialize, serde::Serialize], + additional_derives: [serde::Deserialize, serde::Serialize, process_macros::SerdeJsonInto], }); impl From
for WitAddress { @@ -50,15 +50,10 @@ fn init(our: Address) { .parse() .unwrap(); - let Ok(Ok(Message::Response { .. })) = - Request::to(our) - .body(serde_json::to_vec(&TransferRequest::Download(DownloadRequest { - name: name.into(), - target: target.clone().into(), - })).unwrap()) - .send_and_await_response(5) - else { - println!("download: did not receive expected Response from {target:?}"); - return; - }; + let Ok(_) = Request::to(our) + .body(TransferRequest::Download(DownloadRequest { + name: name.into(), + target: target.clone().into(), + })) + .send(); } diff --git a/src/new/templates/rust/no-ui/file_transfer/list_files/Cargo.toml_ b/src/new/templates/rust/no-ui/file_transfer/list_files/Cargo.toml_ index 68392bdf..0150d382 100644 --- a/src/new/templates/rust/no-ui/file_transfer/list_files/Cargo.toml_ +++ b/src/new/templates/rust/no-ui/file_transfer/list_files/Cargo.toml_ @@ -6,6 +6,7 @@ edition = "2021" [dependencies] anyhow = "1.0" kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.0" } +process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" wit-bindgen = "0.24.0" diff --git a/src/new/templates/rust/no-ui/file_transfer/list_files/src/lib.rs b/src/new/templates/rust/no-ui/file_transfer/list_files/src/lib.rs index 2ac66a02..81ce611e 100644 --- a/src/new/templates/rust/no-ui/file_transfer/list_files/src/lib.rs +++ b/src/new/templates/rust/no-ui/file_transfer/list_files/src/lib.rs @@ -7,7 +7,7 @@ wit_bindgen::generate!({ path: "target/wit", world: "{package_name_kebab}-{publisher_dotted_kebab}-v0", generate_unused_types: true, - additional_derives: [serde::Deserialize, serde::Serialize], + additional_derives: [serde::Deserialize, serde::Serialize, process_macros::SerdeJsonInto], }); call_init!(init); @@ -29,14 +29,14 @@ fn init(_our: Address) { let Ok(Ok(Message::Response { body, .. })) = Request::to(target) - .body(serde_json::to_vec(&TransferRequest::ListFiles).unwrap()) + .body(TransferRequest::ListFiles) .send_and_await_response(5) else { println!("did not receive expected Response from {who}"); return; }; - let Ok(TransferResponse::ListFiles(files)) = serde_json::from_slice(&body) else { + let Ok(TransferResponse::ListFiles(files)) = body.try_into() else { println!("did not receive expected ListFiles from {who}"); return; }; diff --git a/src/new/templates/rust/no-ui/file_transfer/pkg/scripts.json b/src/new/templates/rust/no-ui/file_transfer/pkg/scripts.json index 4f667499..5b67bc76 100644 --- a/src/new/templates/rust/no-ui/file_transfer/pkg/scripts.json +++ b/src/new/templates/rust/no-ui/file_transfer/pkg/scripts.json @@ -8,7 +8,8 @@ ], "grant_capabilities": [ "{package_name}:{package_name}:{publisher}" - ] + ], + "wit_version": 0 }, "list_files.wasm": { "root": false, @@ -19,6 +20,7 @@ ], "grant_capabilities": [ "{package_name}:{package_name}:{publisher}" - ] + ], + "wit_version": 0 } } diff --git a/src/new/templates/rust/no-ui/file_transfer/worker/Cargo.toml_ b/src/new/templates/rust/no-ui/file_transfer/worker/Cargo.toml_ index 65d818ba..b35e48c8 100644 --- a/src/new/templates/rust/no-ui/file_transfer/worker/Cargo.toml_ +++ b/src/new/templates/rust/no-ui/file_transfer/worker/Cargo.toml_ @@ -7,6 +7,7 @@ edition = "2021" anyhow = "1.0" bincode = "1.3.3" kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.0" } +process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" wit-bindgen = "0.24.0" diff --git a/src/new/templates/rust/no-ui/file_transfer/worker/src/lib.rs b/src/new/templates/rust/no-ui/file_transfer/worker/src/lib.rs index 4eb9f0d2..7ffb32c1 100644 --- a/src/new/templates/rust/no-ui/file_transfer/worker/src/lib.rs +++ b/src/new/templates/rust/no-ui/file_transfer/worker/src/lib.rs @@ -1,7 +1,5 @@ -use std::str::FromStr; - use crate::kinode::process::standard::{ProcessId as WitProcessId}; -use crate::kinode::process::{package_name}::{Address as WitAddress, Request as TransferRequest, WorkerRequest, ProgressRequest, InitializeRequest, ChunkRequest}; +use crate::kinode::process::{package_name}::{Address as WitAddress, Request as TransferRequest, Response as TransferResponse, WorkerRequest, ProgressRequest, InitializeRequest, ChunkRequest}; use kinode_process_lib::{ await_message, call_init, get_blob, println, vfs::{open_dir, open_file, Directory, File, SeekFrom}, @@ -12,7 +10,7 @@ wit_bindgen::generate!({ path: "target/wit", world: "{package_name_kebab}-{publisher_dotted_kebab}-v0", generate_unused_types: true, - additional_derives: [serde::Deserialize, serde::Serialize], + additional_derives: [serde::Deserialize, serde::Serialize, process_macros::SerdeJsonInto], }); impl From
for WitAddress { @@ -56,132 +54,121 @@ const CHUNK_SIZE: u64 = 1048576; // 1MB fn handle_message( our: &Address, + message: &Message, file: &mut Option, files_dir: &Directory, size: &mut Option, ) -> anyhow::Result { - let message = await_message()?; - - match message { - Message::Request { - ref body, - .. - } => { - match serde_json::from_slice(body)? { - WorkerRequest::Initialize(InitializeRequest { - name, - target_worker, - }) => { - // initialize command from main process, - // sets up worker, matches on if it's a sender or receiver. - // target_worker = None, we are receiver, else sender. - - // open/create empty file in both cases. - let mut active_file = - open_file(&format!("{}/{}", files_dir.path, &name), true, None)?; - - match target_worker { - Some(target_worker) => { - let target_worker: Address = target_worker.into(); - // we have a target, chunk the data, and send it. - let size = active_file.metadata()?.len; - let num_chunks = (size as f64 / CHUNK_SIZE as f64).ceil() as u64; - - // give the receiving worker a size request so it can track it's progress! - Request::new() - .body(serde_json::to_vec(&WorkerRequest::Size(size))?) - .target(target_worker.clone()) - .send()?; - - active_file.seek(SeekFrom::Start(0))?; - - for i in 0..num_chunks { - let offset = i * CHUNK_SIZE; - let length = CHUNK_SIZE.min(size - offset); - - let mut buffer = vec![0; length as usize]; - active_file.read_at(&mut buffer)?; - - Request::new() - .body(serde_json::to_vec(&WorkerRequest::Chunk(ChunkRequest { - name: name.clone(), - offset, - length, - }))?) - .target(target_worker.clone()) - .blob_bytes(buffer) - .send()?; - } - Response::new().body(serde_json::to_vec(&"Done")?).send()?; - return Ok(true); - } - None => { - // waiting for response, store created empty file. - *file = Some(active_file); - Response::new() - .body(serde_json::to_vec(&"Started")?) - .send()?; - } - } - } - // someone sending a chunk to us! - WorkerRequest::Chunk(ChunkRequest { - name, - offset, - length, - }) => { - let file = match file { - Some(file) => file, - None => { - return Err(anyhow::anyhow!( - "{package_name} worker: receive error: no file initialized" - )); - } - }; - - let bytes = match get_blob() { - Some(blob) => blob.bytes, - None => { - return Err(anyhow::anyhow!("{package_name} worker: receive error: no blob")); - } - }; - - // file.seek(SeekFrom::Start(offset))?; seek not necessary if the sends come in order. - file.write_all(&bytes)?; - // if sender has sent us a size, give a progress update to main transfer! - if let Some(size) = size { - let progress = ((offset + length) as f64 / *size as f64 * 100.0) as u64; - - // send update to main process - let main_app = Address { - node: our.node.clone(), - process: ProcessId::from_str( - "{package_name}:{package_name}:{publisher}", - )?, - }; + if !message.is_request() { + return Err(anyhow::anyhow!("unexpected Response: {:?}", message)); + } + + match message.body().try_into()? { + WorkerRequest::Initialize(InitializeRequest { + name, + target_worker, + }) => { + // initialize command from main process, + // sets up worker, matches on if it's a sender or receiver. + // target_worker = None, we are receiver, else sender. + + // open/create empty file in both cases. + let mut active_file = + open_file(&format!("{}/{}", files_dir.path, &name), true, None)?; + + match target_worker { + Some(target_worker) => { + let target_worker: Address = target_worker.into(); + // we have a target, chunk the data, and send it. + let size = active_file.metadata()?.len; + let num_chunks = (size as f64 / CHUNK_SIZE as f64).ceil() as u64; + + // give the receiving worker a size request so it can track it's progress! + Request::new() + .body(WorkerRequest::Size(size)) + .target(target_worker.clone()) + .send()?; + + active_file.seek(SeekFrom::Start(0))?; + + for i in 0..num_chunks { + let offset = i * CHUNK_SIZE; + let length = CHUNK_SIZE.min(size - offset); + + let mut buffer = vec![0; length as usize]; + active_file.read_at(&mut buffer)?; Request::new() - .body(serde_json::to_vec(&TransferRequest::Progress(ProgressRequest { - name, - progress, - }))?) - .target(&main_app) + .body(WorkerRequest::Chunk(ChunkRequest { + name: name.clone(), + offset, + length, + })) + .target(target_worker.clone()) + .blob_bytes(buffer) .send()?; - - if progress >= 100 { - return Ok(true); - } } + return Ok(true); + } + None => { + // waiting for response, store created empty file. + *file = Some(active_file); + Response::new().body(TransferResponse::Started).send()?; + } + } + } + // someone sending a chunk to us! + WorkerRequest::Chunk(ChunkRequest { + name, + offset, + length, + }) => { + let file = match file { + Some(file) => file, + None => { + return Err(anyhow::anyhow!( + "{package_name} worker: receive error: no file initialized" + )); + } + }; + + let bytes = match get_blob() { + Some(blob) => blob.bytes, + None => { + return Err(anyhow::anyhow!("{package_name} worker: receive error: no blob")); } - WorkerRequest::Size(incoming_size) => { - *size = Some(incoming_size); + }; + + // file.seek(SeekFrom::Start(offset))?; seek not necessary if the sends come in order. + file.write_all(&bytes)?; + // if sender has sent us a size, give a progress update to main transfer! + if let Some(size) = size { + let progress = ((offset + length) as f64 / *size as f64 * 100.0) as u64; + + // send update to main process + let main_app = Address { + node: our.node.clone(), + process: "{package_name}:{package_name}:{publisher}".parse()?, + }; + + Request::new() + .body(TransferRequest::Progress(ProgressRequest { + name, + progress, + })) + .target(&main_app) + .send()?; + + if progress >= 100 { + return Ok(true); } } } - _ => { - println!("worker: got something else than request..."); + WorkerRequest::Size(incoming_size) => { + *size = Some(incoming_size); } } + Ok(false) } @@ -197,19 +184,23 @@ fn init(our: Address) { let mut size: Option = None; loop { - match handle_message(&our, &mut file, &files_dir, &mut size) { - Ok(exit) => { - if exit { - println!( - "worker: done: exiting, took {:?}", - start.elapsed() - ); - break; + match await_message() { + Err(send_error) => println!("worker: got SendError: {send_error}"), + Ok(ref message) => match handle_message( + &our, + message, + &mut file, + &files_dir, + &mut size, + ) { + Ok(exit) => { + if exit { + println!("worker: done: exiting, took {:?}", start.elapsed()); + break; + } } + Err(e) => println!("worker: got error while handling message: {e:?}"), } - Err(e) => { - println!("worker: error: {:?}", e); - } - }; + } } } diff --git a/src/new/templates/rust/no-ui/file_transfer/{package_name}/Cargo.toml_ b/src/new/templates/rust/no-ui/file_transfer/{package_name}/Cargo.toml_ index 660e74db..04bd8918 100644 --- a/src/new/templates/rust/no-ui/file_transfer/{package_name}/Cargo.toml_ +++ b/src/new/templates/rust/no-ui/file_transfer/{package_name}/Cargo.toml_ @@ -5,9 +5,8 @@ edition = "2021" [dependencies] anyhow = "1.0" -bincode = "1.3.3" kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.0" } -multipart = "0.18.0" +process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" wit-bindgen = "0.24.0" diff --git a/src/new/templates/rust/no-ui/file_transfer/{package_name}/src/lib.rs b/src/new/templates/rust/no-ui/file_transfer/{package_name}/src/lib.rs index 06b9b17a..bd19c864 100644 --- a/src/new/templates/rust/no-ui/file_transfer/{package_name}/src/lib.rs +++ b/src/new/templates/rust/no-ui/file_transfer/{package_name}/src/lib.rs @@ -3,14 +3,14 @@ use crate::kinode::process::{package_name}::{Address as WitAddress, Request as T use kinode_process_lib::{ await_message, call_init, our_capabilities, println, spawn, vfs::{create_drive, metadata, open_dir, Directory, FileType}, - Address, OnExit, ProcessId, Request, Response, + Address, Message, OnExit, ProcessId, Request, Response, }; wit_bindgen::generate!({ path: "target/wit", world: "{package_name_kebab}-{publisher_dotted_kebab}-v0", generate_unused_types: true, - additional_derives: [serde::Deserialize, serde::Serialize], + additional_derives: [serde::Deserialize, serde::Serialize, process_macros::SerdeJsonInto], }); impl From
for WitAddress { @@ -71,16 +71,15 @@ fn ls_files(files_dir: &Directory) -> anyhow::Result> { fn handle_transfer_request( our: &Address, - source: &Address, - body: &[u8], + message: &Message, files_dir: &Directory, ) -> anyhow::Result<()> { - match serde_json::from_slice(body)? { + match message.body().try_into()? { TransferRequest::ListFiles => { let files = ls_files(files_dir)?; Response::new() - .body(serde_json::to_vec(&TransferResponse::ListFiles(files))?) + .body(TransferResponse::ListFiles(files)) .send()?; } TransferRequest::Download(DownloadRequest { name, target }) => { @@ -99,31 +98,31 @@ fn handle_transfer_request( process: our_worker, }; - if source.node == our.node { + if message.source().node == our.node { // we want to download a file let _resp = Request::new() - .body(serde_json::to_vec(&WorkerRequest::Initialize(InitializeRequest { + .body(WorkerRequest::Initialize(InitializeRequest { name: name.clone(), target_worker: None, - }))?) + })) .target(&our_worker_address) .send_and_await_response(5)??; // send our initialized worker address to the other node Request::new() - .body(serde_json::to_vec(&TransferRequest::Download(DownloadRequest { + .body(TransferRequest::Download(DownloadRequest { name: name.clone(), target: our_worker_address.into(), - }))?) + })) .target::
(target.clone().into()) .send()?; } else { // they want to download a file Request::new() - .body(serde_json::to_vec(&WorkerRequest::Initialize(InitializeRequest { + .body(WorkerRequest::Initialize(InitializeRequest { name: name.clone(), target_worker: Some(target), - }))?) + })) .target(&our_worker_address) .send()?; } @@ -136,9 +135,12 @@ fn handle_transfer_request( Ok(()) } -fn handle_message(our: &Address, files_dir: &Directory) -> anyhow::Result<()> { - let message = await_message()?; - handle_transfer_request(our, message.source(), message.body(), files_dir) +fn handle_message( + our: &Address, + message: &Message, + files_dir: &Directory, +) -> anyhow::Result<()> { + handle_transfer_request(our, message, files_dir) } call_init!(init); @@ -149,11 +151,12 @@ fn init(our: Address) { let files_dir = open_dir(&drive_path, false, None).unwrap(); loop { - match handle_message(&our, &files_dir) { - Ok(()) => {} - Err(e) => { - println!("error: {:?}", e); + match await_message() { + Err(send_error) => println!("got SendError: {send_error}"), + Ok(ref message) => match handle_message(&our, message, &files_dir) { + Ok(_) => {} + Err(e) => println!("got error while handling message: {e:?}"), } - }; + } } } From a91d68fd9f283cefe7d974dddf22a3a9e2ec2011 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Fri, 12 Jul 2024 15:12:26 -0700 Subject: [PATCH 2/8] add `download_from`: mirror to fetch deps from (default: publisher) --- src/build/mod.rs | 10 ++++++++++ src/build_start_package/mod.rs | 2 ++ src/main.rs | 34 +++++++++++++++++++++++++++++++++- src/run_tests/mod.rs | 3 +++ src/view_api/mod.rs | 8 +++++--- 5 files changed, 53 insertions(+), 4 deletions(-) diff --git a/src/build/mod.rs b/src/build/mod.rs index 2367ddda..806ca51f 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -507,6 +507,7 @@ async fn compile_package_and_ui( features: &str, url: Option, default_world: Option, + download_from: Option<&str>, verbose: bool, ) -> Result<()> { compile_and_copy_ui(package_dir, valid_node, verbose).await?; @@ -516,6 +517,7 @@ async fn compile_package_and_ui( features, url, default_world, + download_from, verbose, ) .await?; @@ -579,6 +581,7 @@ async fn fetch_dependencies( apis: &mut HashMap>, wasm_paths: &mut HashSet, url: String, + download_from: Option<&str>, ) -> Result<()> { for dependency in dependencies { if dependency.parse::().is_err() { @@ -590,6 +593,7 @@ async fn fetch_dependencies( None, Some(dependency), &url, + download_from, false, ).await? else { return Err(eyre!( @@ -735,6 +739,7 @@ async fn compile_package( features: &str, url: Option, default_world: Option, + download_from: Option<&str>, verbose: bool, ) -> Result<()> { let metadata = read_metadata(package_dir)?; @@ -798,6 +803,7 @@ async fn compile_package( &mut apis, &mut wasm_paths, url.clone(), + download_from, ).await?; } } @@ -879,6 +885,7 @@ pub async fn execute( skip_deps_check: bool, features: &str, url: Option, + download_from: Option<&str>, default_world: Option, verbose: bool, ) -> Result<()> { @@ -905,6 +912,7 @@ pub async fn execute( features, url, default_world, + download_from, verbose, ) .await @@ -917,6 +925,7 @@ pub async fn execute( features, url, default_world, + download_from, verbose, ) .await; @@ -936,6 +945,7 @@ pub async fn execute( features, url, default_world, + download_from, verbose, ) .await diff --git a/src/build_start_package/mod.rs b/src/build_start_package/mod.rs index ba0dbd81..4f9ab63e 100644 --- a/src/build_start_package/mod.rs +++ b/src/build_start_package/mod.rs @@ -14,6 +14,7 @@ pub async fn execute( url: &str, skip_deps_check: bool, features: &str, + download_from: Option<&str>, default_world: Option, verbose: bool, ) -> Result<()> { @@ -24,6 +25,7 @@ pub async fn execute( skip_deps_check, features, Some(url.into()), + download_from, default_world, verbose, ) diff --git a/src/main.rs b/src/main.rs index 8410a1cc..0f7c21ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -193,6 +193,9 @@ async fn execute( .get_one::("NODE_PORT") .map(|p| format!("http://localhost:{}", p)), }; + let download_from = build_matches + .get_one::("NODE") + .and_then(|s: &String| Some(s.as_str())); let default_world = build_matches.get_one::("WORLD"); let verbose = build_matches.get_one::("VERBOSE").unwrap(); @@ -203,6 +206,7 @@ async fn execute( *skip_deps_check, &features, url, + download_from, default_world.cloned(), *verbose, ) @@ -228,6 +232,9 @@ async fn execute( Some(f) => f.clone(), None => "".into(), }; + let download_from = build_start_matches + .get_one::("NODE") + .and_then(|s: &String| Some(s.as_str())); let default_world = build_start_matches.get_one::("WORLD"); let verbose = build_start_matches.get_one::("VERBOSE").unwrap(); @@ -238,6 +245,7 @@ async fn execute( &url, *skip_deps_check, &features, + download_from, default_world.cloned(), *verbose, ) @@ -386,8 +394,11 @@ async fn execute( format!("http://localhost:{}", port) } }; + let download_from = view_api_matches + .get_one::("NODE") + .and_then(|s: &String| Some(s.as_str())); - view_api::execute(None, package_id, &url, true).await?; + view_api::execute(None, package_id, &url, download_from, true).await?; Ok(()) } _ => { @@ -622,6 +633,13 @@ async fn make_app(current_dir: &std::ffi::OsString) -> Result { .help("Node URL (overrides NODE_PORT)") .required(false) ) + .arg(Arg::new("NODE") + .action(ArgAction::Set) + .short('d') + .long("download-from") + .help("Download API from this node if not found") + .required(false) + ) .arg(Arg::new("WORLD") .action(ArgAction::Set) .short('w') @@ -659,6 +677,13 @@ async fn make_app(current_dir: &std::ffi::OsString) -> Result { .help("Node URL (overrides NODE_PORT)") .required(false) ) + .arg(Arg::new("NODE") + .action(ArgAction::Set) + .short('d') + .long("download-from") + .help("Download API from this node if not found") + .required(false) + ) .arg(Arg::new("WORLD") .action(ArgAction::Set) .short('w') @@ -998,6 +1023,13 @@ async fn make_app(current_dir: &std::ffi::OsString) -> Result { .help("Node URL (overrides NODE_PORT)") .required(false) ) + .arg(Arg::new("NODE") + .action(ArgAction::Set) + .short('d') + .long("download-from") + .help("Download API from this node if not found") + .required(false) + ) ) ) } diff --git a/src/run_tests/mod.rs b/src/run_tests/mod.rs index d6b80453..4ead8efd 100644 --- a/src/run_tests/mod.rs +++ b/src/run_tests/mod.rs @@ -343,6 +343,7 @@ async fn build_packages( "test", Some(url.clone()), None, + None, false, ).await?; start_package::execute(&path, &url).await?; @@ -357,6 +358,7 @@ async fn build_packages( "test", Some(url.clone()), None, + None, false, ).await?; } @@ -369,6 +371,7 @@ async fn build_packages( "test", Some(url.clone()), None, + None, false, ).await?; } diff --git a/src/view_api/mod.rs b/src/view_api/mod.rs index 91cf407c..e2105bb5 100644 --- a/src/view_api/mod.rs +++ b/src/view_api/mod.rs @@ -191,6 +191,7 @@ async fn get_api( node: Option<&str>, url: &str, package_id: &str, + download_from: Option<&str>, verbose: bool, is_first_call: bool, ) -> Result { @@ -224,8 +225,8 @@ async fn get_api( } else { if is_first_call && body.contains("Failure") { // try to download the package & try again - download(node, url, package_id, None, None).await?; - Box::pin(get_api(node, url, package_id, verbose, false)).await? + download(node, url, package_id, download_from, None).await?; + Box::pin(get_api(node, url, package_id, download_from, verbose, false)).await? } else { // unexpected case let body = serde_json::from_str::(&body)?; @@ -241,10 +242,11 @@ pub async fn execute( node: Option<&str>, package_id: Option<&str>, url: &str, + download_from: Option<&str>, verbose: bool, ) -> Result> { if let Some(package_id) = package_id { - Ok(Some(get_api(node, url, &package_id, verbose, true).await?)) + Ok(Some(get_api(node, url, &package_id, download_from, verbose, true).await?)) } else { list_apis(node, url, verbose).await?; Ok(None) From c98691b6f049c7927349e33327d7a58c06678a2a Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Fri, 12 Jul 2024 15:16:37 -0700 Subject: [PATCH 3/8] main: change all `*_matches` -> `matches` --- src/main.rs | 190 ++++++++++++++++++++++++++-------------------------- 1 file changed, 95 insertions(+), 95 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0f7c21ed..d4db5ada 100644 --- a/src/main.rs +++ b/src/main.rs @@ -118,22 +118,22 @@ async fn execute( matches: Option<(&str, &clap::ArgMatches)>, ) -> Result<()> { match matches { - Some(("boot-fake-node", boot_matches)) => { - let runtime_path = boot_matches + Some(("boot-fake-node", matches)) => { + let runtime_path = matches .get_one::("PATH") .and_then(|p| Some(PathBuf::from(p))); - let version = boot_matches.get_one::("VERSION").unwrap(); - let node_home = PathBuf::from(boot_matches.get_one::("HOME").unwrap()); - let node_port = boot_matches.get_one::("NODE_PORT").unwrap(); - let fakechain_port = boot_matches.get_one::("FAKECHAIN_PORT").unwrap(); - let rpc = boot_matches + let version = matches.get_one::("VERSION").unwrap(); + let node_home = PathBuf::from(matches.get_one::("HOME").unwrap()); + let node_port = matches.get_one::("NODE_PORT").unwrap(); + let fakechain_port = matches.get_one::("FAKECHAIN_PORT").unwrap(); + let rpc = matches .get_one::("RPC_ENDPOINT") .and_then(|s| Some(s.as_str())); - let fake_node_name = boot_matches.get_one::("NODE_NAME").unwrap(); - let password = boot_matches.get_one::("PASSWORD").unwrap(); - let is_persist = boot_matches.get_one::("PERSIST").unwrap(); - let release = boot_matches.get_one::("RELEASE").unwrap(); - let verbosity = boot_matches.get_one::("VERBOSITY").unwrap(); + let fake_node_name = matches.get_one::("NODE_NAME").unwrap(); + let password = matches.get_one::("PASSWORD").unwrap(); + let is_persist = matches.get_one::("PERSIST").unwrap(); + let release = matches.get_one::("RELEASE").unwrap(); + let verbosity = matches.get_one::("VERBOSITY").unwrap(); boot_fake_node::execute( runtime_path, @@ -151,19 +151,19 @@ async fn execute( ) .await } - Some(("boot-real-node", boot_matches)) => { - let runtime_path = boot_matches + Some(("boot-real-node", matches)) => { + let runtime_path = matches .get_one::("PATH") .and_then(|p| Some(PathBuf::from(p))); - let version = boot_matches.get_one::("VERSION").unwrap(); - let node_home = PathBuf::from(boot_matches.get_one::("HOME").unwrap()); - let node_port = boot_matches.get_one::("NODE_PORT").unwrap(); - let rpc = boot_matches + let version = matches.get_one::("VERSION").unwrap(); + let node_home = PathBuf::from(matches.get_one::("HOME").unwrap()); + let node_port = matches.get_one::("NODE_PORT").unwrap(); + let rpc = matches .get_one::("RPC_ENDPOINT") .and_then(|s| Some(s.as_str())); - // let password = boot_matches.get_one::("PASSWORD").unwrap(); // TODO: with develop 0.8.0 - let release = boot_matches.get_one::("RELEASE").unwrap(); - let verbosity = boot_matches.get_one::("VERBOSITY").unwrap(); + // let password = matches.get_one::("PASSWORD").unwrap(); // TODO: with develop 0.8.0 + let release = matches.get_one::("RELEASE").unwrap(); + let verbosity = matches.get_one::("VERBOSITY").unwrap(); boot_real_node::execute( runtime_path, @@ -178,26 +178,26 @@ async fn execute( ) .await } - Some(("build", build_matches)) => { - let package_dir = PathBuf::from(build_matches.get_one::("DIR").unwrap()); - let no_ui = build_matches.get_one::("NO_UI").unwrap(); - let ui_only = build_matches.get_one::("UI_ONLY").unwrap(); - let skip_deps_check = build_matches.get_one::("SKIP_DEPS_CHECK").unwrap(); - let features = match build_matches.get_one::("FEATURES") { + Some(("build", matches)) => { + let package_dir = PathBuf::from(matches.get_one::("DIR").unwrap()); + let no_ui = matches.get_one::("NO_UI").unwrap(); + let ui_only = matches.get_one::("UI_ONLY").unwrap(); + let skip_deps_check = matches.get_one::("SKIP_DEPS_CHECK").unwrap(); + let features = match matches.get_one::("FEATURES") { Some(f) => f.clone(), None => "".into(), }; - let url: Option = match build_matches.get_one::("URL") { + let url: Option = match matches.get_one::("URL") { Some(url) => Some(url.clone()), - None => build_matches + None => matches .get_one::("NODE_PORT") .map(|p| format!("http://localhost:{}", p)), }; - let download_from = build_matches + let download_from = matches .get_one::("NODE") .and_then(|s: &String| Some(s.as_str())); - let default_world = build_matches.get_one::("WORLD"); - let verbose = build_matches.get_one::("VERBOSE").unwrap(); + let default_world = matches.get_one::("WORLD"); + let verbose = matches.get_one::("VERBOSE").unwrap(); build::execute( &package_dir, @@ -212,31 +212,31 @@ async fn execute( ) .await } - Some(("build-start-package", build_start_matches)) => { - let package_dir = PathBuf::from(build_start_matches.get_one::("DIR").unwrap()); - let no_ui = build_start_matches.get_one::("NO_UI").unwrap(); - let ui_only = build_start_matches + Some(("build-start-package", matches)) => { + let package_dir = PathBuf::from(matches.get_one::("DIR").unwrap()); + let no_ui = matches.get_one::("NO_UI").unwrap(); + let ui_only = matches .get_one::("UI_ONLY") .unwrap_or(&false); - let url: String = match build_start_matches.get_one::("URL") { + let url: String = match matches.get_one::("URL") { Some(url) => url.clone(), None => { - let port = build_start_matches.get_one::("NODE_PORT").unwrap(); + let port = matches.get_one::("NODE_PORT").unwrap(); format!("http://localhost:{}", port) } }; - let skip_deps_check = build_start_matches + let skip_deps_check = matches .get_one::("SKIP_DEPS_CHECK") .unwrap(); - let features = match build_start_matches.get_one::("FEATURES") { + let features = match matches.get_one::("FEATURES") { Some(f) => f.clone(), None => "".into(), }; - let download_from = build_start_matches + let download_from = matches .get_one::("NODE") .and_then(|s: &String| Some(s.as_str())); - let default_world = build_start_matches.get_one::("WORLD"); - let verbose = build_start_matches.get_one::("VERBOSE").unwrap(); + let default_world = matches.get_one::("WORLD"); + let verbose = matches.get_one::("VERBOSE").unwrap(); build_start_package::execute( &package_dir, @@ -251,66 +251,66 @@ async fn execute( ) .await } - Some(("chain", chain_matches)) => { - let port = chain_matches.get_one::("PORT").unwrap(); - let verbose = chain_matches.get_one::("VERBOSE").unwrap(); + Some(("chain", matches)) => { + let port = matches.get_one::("PORT").unwrap(); + let verbose = matches.get_one::("VERBOSE").unwrap(); chain::execute(*port, *verbose).await } - Some(("connect", connect_matches)) => { - let local_port = connect_matches.get_one::("LOCAL_PORT").unwrap(); - let disconnect = connect_matches.get_one::("IS_DISCONNECT").unwrap(); - let host = connect_matches + Some(("connect", matches)) => { + let local_port = matches.get_one::("LOCAL_PORT").unwrap(); + let disconnect = matches.get_one::("IS_DISCONNECT").unwrap(); + let host = matches .get_one::("HOST") .map(|s| s.as_ref()); - let host_port = connect_matches + let host_port = matches .get_one::("HOST_PORT") .map(|hp| hp.clone()); connect::execute(*local_port, *disconnect, host, host_port) } - Some(("dev-ui", dev_ui_matches)) => { - let package_dir = PathBuf::from(dev_ui_matches.get_one::("DIR").unwrap()); - let url: String = match dev_ui_matches.get_one::("URL") { + Some(("dev-ui", matches)) => { + let package_dir = PathBuf::from(matches.get_one::("DIR").unwrap()); + let url: String = match matches.get_one::("URL") { Some(url) => url.clone(), None => { - let port = dev_ui_matches.get_one::("NODE_PORT").unwrap(); + let port = matches.get_one::("NODE_PORT").unwrap(); format!("http://localhost:{}", port) } }; - let skip_deps_check = dev_ui_matches.get_one::("SKIP_DEPS_CHECK").unwrap(); - let release = dev_ui_matches.get_one::("RELEASE").unwrap(); + let skip_deps_check = matches.get_one::("SKIP_DEPS_CHECK").unwrap(); + let release = matches.get_one::("RELEASE").unwrap(); dev_ui::execute(&package_dir, &url, *skip_deps_check, *release) } - Some(("inject-message", inject_message_matches)) => { - let url: String = match inject_message_matches.get_one::("URL") { + Some(("inject-message", matches)) => { + let url: String = match matches.get_one::("URL") { Some(url) => url.clone(), None => { - let port = inject_message_matches.get_one::("NODE_PORT").unwrap(); + let port = matches.get_one::("NODE_PORT").unwrap(); format!("http://localhost:{}", port) } }; - let process: &String = inject_message_matches.get_one("PROCESS").unwrap(); - let non_block: &bool = inject_message_matches.get_one("NONBLOCK").unwrap(); - let body: &String = inject_message_matches.get_one("BODY_JSON").unwrap(); - let node: Option<&str> = inject_message_matches + let process: &String = matches.get_one("PROCESS").unwrap(); + let non_block: &bool = matches.get_one("NONBLOCK").unwrap(); + let body: &String = matches.get_one("BODY_JSON").unwrap(); + let node: Option<&str> = matches .get_one("NODE_NAME") .and_then(|s: &String| Some(s.as_str())); - let bytes: Option<&str> = inject_message_matches + let bytes: Option<&str> = matches .get_one("PATH") .and_then(|s: &String| Some(s.as_str())); let expects_response = if *non_block { None } else { Some(15) }; inject_message::execute(&url, process, expects_response, body, node, bytes).await } - Some(("new", new_matches)) => { - let new_dir = PathBuf::from(new_matches.get_one::("DIR").unwrap()); - let package_name = new_matches + Some(("new", matches)) => { + let new_dir = PathBuf::from(matches.get_one::("DIR").unwrap()); + let package_name = matches .get_one::("PACKAGE") .map(|pn| pn.to_string()); - let publisher = new_matches.get_one::("PUBLISHER").unwrap(); - let language: new::Language = new_matches.get_one::("LANGUAGE").unwrap().into(); - let template: new::Template = new_matches.get_one::("TEMPLATE").unwrap().into(); - let ui = new_matches.get_one::("UI").unwrap_or(&false); + let publisher = matches.get_one::("PUBLISHER").unwrap(); + let language: new::Language = matches.get_one::("LANGUAGE").unwrap().into(); + let template: new::Template = matches.get_one::("TEMPLATE").unwrap().into(); + let ui = matches.get_one::("UI").unwrap_or(&false); new::execute( new_dir, @@ -321,27 +321,27 @@ async fn execute( *ui, ) } - Some(("remove-package", remove_package_matches)) => { - let package_name = remove_package_matches + Some(("remove-package", matches)) => { + let package_name = matches .get_one::("PACKAGE") .and_then(|s: &String| Some(s.as_str())); - let publisher = remove_package_matches + let publisher = matches .get_one::("PUBLISHER") .and_then(|s: &String| Some(s.as_str())); let package_dir = - PathBuf::from(remove_package_matches.get_one::("DIR").unwrap()); - let url: String = match remove_package_matches.get_one::("URL") { + PathBuf::from(matches.get_one::("DIR").unwrap()); + let url: String = match matches.get_one::("URL") { Some(url) => url.clone(), None => { - let port = remove_package_matches.get_one::("NODE_PORT").unwrap(); + let port = matches.get_one::("NODE_PORT").unwrap(); format!("http://localhost:{}", port) } }; remove_package::execute(&package_dir, &url, package_name, publisher).await } - Some(("reset-cache", _reset_cache_matches)) => reset_cache::execute(), - Some(("run-tests", run_tests_matches)) => { - let config_path = match run_tests_matches.get_one::("PATH") { + Some(("reset-cache", _matches)) => reset_cache::execute(), + Some(("run-tests", matches)) => { + let config_path = match matches.get_one::("PATH") { Some(path) => PathBuf::from(path), None => std::env::current_dir()?.join("tests.toml"), }; @@ -356,45 +356,45 @@ async fn execute( run_tests::execute(config_path).await } - Some(("setup", setup_matches)) => { - let verbose = setup_matches.get_one::("VERBOSE").unwrap(); + Some(("setup", matches)) => { + let verbose = matches.get_one::("VERBOSE").unwrap(); setup::execute(*verbose) } - Some(("start-package", start_package_matches)) => { + Some(("start-package", matches)) => { let package_dir = - PathBuf::from(start_package_matches.get_one::("DIR").unwrap()); - let url: String = match start_package_matches.get_one::("URL") { + PathBuf::from(matches.get_one::("DIR").unwrap()); + let url: String = match matches.get_one::("URL") { Some(url) => url.clone(), None => { - let port = start_package_matches.get_one::("NODE_PORT").unwrap(); + let port = matches.get_one::("NODE_PORT").unwrap(); format!("http://localhost:{}", port) } }; start_package::execute(&package_dir, &url).await } - Some(("update", update_matches)) => { - let args = update_matches + Some(("update", matches)) => { + let args = matches .get_many::("ARGUMENTS") .unwrap_or_default() .map(|v| v.to_string()) .collect::>(); - let branch = update_matches.get_one::("BRANCH").unwrap(); + let branch = matches.get_one::("BRANCH").unwrap(); update::execute(args, branch) } - Some(("view-api", view_api_matches)) => { - let package_id = view_api_matches + Some(("view-api", matches)) => { + let package_id = matches .get_one::("PACKAGE_ID") .and_then(|s: &String| Some(s.as_str())); - let url: String = match view_api_matches.get_one::("URL") { + let url: String = match matches.get_one::("URL") { Some(url) => url.clone(), None => { - let port = view_api_matches.get_one::("NODE_PORT").unwrap(); + let port = matches.get_one::("NODE_PORT").unwrap(); format!("http://localhost:{}", port) } }; - let download_from = view_api_matches + let download_from = matches .get_one::("NODE") .and_then(|s: &String| Some(s.as_str())); From f592a136a243c8cc6f7a17cc66a3b13b39ca3c2f Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Fri, 12 Jul 2024 15:24:13 -0700 Subject: [PATCH 4/8] remove unused deps --- Cargo.lock | 119 ----------------------------------------------------- Cargo.toml | 6 --- 2 files changed, 125 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6351a3ac..73dff44f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -801,12 +801,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "data-encoding" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" - [[package]] name = "der" version = "0.7.9" @@ -1123,7 +1117,6 @@ checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ "futures-core", "futures-macro", - "futures-sink", "futures-task", "pin-project-lite", "pin-utils", @@ -1530,15 +1523,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "instant" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" -dependencies = [ - "cfg-if", -] - [[package]] name = "ipnet" version = "2.9.0" @@ -1648,22 +1632,17 @@ dependencies = [ "color-eyre", "dirs", "fs-err", - "futures-util", "git2", "hex", "kinode_process_lib", "nix", "regex", "reqwest", - "rmp-serde", "semver 1.0.23", "serde", "serde_json", "sha2", - "ssh2", - "thiserror", "tokio", - "tokio-tungstenite", "toml", "tracing", "tracing-appender", @@ -1760,16 +1739,6 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "643cb0b8d4fcc284004d5fd0d67ccf61dfffadb7f75e1e71bc420f4688a3a704" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "log" version = "0.4.21" @@ -2013,31 +1982,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "parking_lot" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" -dependencies = [ - "instant", - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" -dependencies = [ - "cfg-if", - "instant", - "libc", - "redox_syscall", - "smallvec", - "winapi", -] - [[package]] name = "password-hash" version = "0.4.2" @@ -2277,15 +2221,6 @@ dependencies = [ "rand_core", ] -[[package]] -name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "redox_users" version = "0.4.5" @@ -2541,12 +2476,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "sec1" version = "0.7.3" @@ -2764,18 +2693,6 @@ dependencies = [ "der", ] -[[package]] -name = "ssh2" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7fe461910559f6d5604c3731d00d2aafc4a83d1665922e280f42f9a168d5455" -dependencies = [ - "bitflags 1.3.2", - "libc", - "libssh2-sys", - "parking_lot", -] - [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -3018,18 +2935,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-tungstenite" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "becd34a233e7e31a3dbf7c7241b38320f57393dcae8e7324b0167d21b8e320b0" -dependencies = [ - "futures-util", - "log", - "tokio", - "tungstenite", -] - [[package]] name = "tokio-util" version = "0.7.11" @@ -3218,24 +3123,6 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" -[[package]] -name = "tungstenite" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e2e2ce1e47ed2994fd43b04c8f618008d4cabdd5ee34027cf14f9d918edd9c8" -dependencies = [ - "byteorder", - "bytes", - "data-encoding", - "http 1.1.0", - "httparse", - "log", - "rand", - "sha1", - "thiserror", - "utf-8", -] - [[package]] name = "typenum" version = "1.17.0" @@ -3304,12 +3191,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "utf-8" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" - [[package]] name = "utf16_iter" version = "1.0.5" diff --git a/Cargo.toml b/Cargo.toml index d9b288c9..bbdb49ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,21 +13,16 @@ clap = { version = "4.4", features = ["cargo", "string"] } color-eyre = { version = "0.6", features = ["capture-spantrace"] } dirs = "5.0" fs-err = "2.11" -futures-util = "0.3" hex = "0.4" kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib.git", rev = "7eb3a04" } nix = { version = "0.27", features = ["process", "signal", "term"] } regex = "1" reqwest = { version = "0.11", features = ["json"] } -rmp-serde = "1.1.2" semver = "1.0" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" sha2 = "0.10.8" -ssh2 = "0.9.4" -thiserror = "1.0" tokio = { version = "1.28", features = [ - "fs", "macros", "process", "rt-multi-thread", @@ -35,7 +30,6 @@ tokio = { version = "1.28", features = [ "sync", "time", ] } -tokio-tungstenite = "*" toml = "0.8" tracing = "0.1" tracing-appender = "0.2" From 4816cb544b08c3d62b5da51ef54950a24cb380c1 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Fri, 12 Jul 2024 16:11:47 -0700 Subject: [PATCH 5/8] remove `--url` parameter, since we only allow localhost --- src/main.rs | 139 +++++++++++++--------------------------------------- 1 file changed, 34 insertions(+), 105 deletions(-) diff --git a/src/main.rs b/src/main.rs index d4db5ada..f211b2b5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -187,12 +187,8 @@ async fn execute( Some(f) => f.clone(), None => "".into(), }; - let url: Option = match matches.get_one::("URL") { - Some(url) => Some(url.clone()), - None => matches - .get_one::("NODE_PORT") - .map(|p| format!("http://localhost:{}", p)), - }; + let url = matches.get_one::("NODE_PORT") + .map(|p| format!("http://localhost:{p}")); let download_from = matches .get_one::("NODE") .and_then(|s: &String| Some(s.as_str())); @@ -218,13 +214,10 @@ async fn execute( let ui_only = matches .get_one::("UI_ONLY") .unwrap_or(&false); - let url: String = match matches.get_one::("URL") { - Some(url) => url.clone(), - None => { - let port = matches.get_one::("NODE_PORT").unwrap(); - format!("http://localhost:{}", port) - } - }; + let url = format!( + "http://localhost:{}", + matches.get_one::("NODE_PORT").unwrap(), + ); let skip_deps_check = matches .get_one::("SKIP_DEPS_CHECK") .unwrap(); @@ -269,26 +262,20 @@ async fn execute( } Some(("dev-ui", matches)) => { let package_dir = PathBuf::from(matches.get_one::("DIR").unwrap()); - let url: String = match matches.get_one::("URL") { - Some(url) => url.clone(), - None => { - let port = matches.get_one::("NODE_PORT").unwrap(); - format!("http://localhost:{}", port) - } - }; + let url = format!( + "http://localhost:{}", + matches.get_one::("NODE_PORT").unwrap(), + ); let skip_deps_check = matches.get_one::("SKIP_DEPS_CHECK").unwrap(); let release = matches.get_one::("RELEASE").unwrap(); dev_ui::execute(&package_dir, &url, *skip_deps_check, *release) } Some(("inject-message", matches)) => { - let url: String = match matches.get_one::("URL") { - Some(url) => url.clone(), - None => { - let port = matches.get_one::("NODE_PORT").unwrap(); - format!("http://localhost:{}", port) - } - }; + let url = format!( + "http://localhost:{}", + matches.get_one::("NODE_PORT").unwrap(), + ); let process: &String = matches.get_one("PROCESS").unwrap(); let non_block: &bool = matches.get_one("NONBLOCK").unwrap(); let body: &String = matches.get_one("BODY_JSON").unwrap(); @@ -330,13 +317,10 @@ async fn execute( .and_then(|s: &String| Some(s.as_str())); let package_dir = PathBuf::from(matches.get_one::("DIR").unwrap()); - let url: String = match matches.get_one::("URL") { - Some(url) => url.clone(), - None => { - let port = matches.get_one::("NODE_PORT").unwrap(); - format!("http://localhost:{}", port) - } - }; + let url = format!( + "http://localhost:{}", + matches.get_one::("NODE_PORT").unwrap(), + ); remove_package::execute(&package_dir, &url, package_name, publisher).await } Some(("reset-cache", _matches)) => reset_cache::execute(), @@ -364,13 +348,10 @@ async fn execute( Some(("start-package", matches)) => { let package_dir = PathBuf::from(matches.get_one::("DIR").unwrap()); - let url: String = match matches.get_one::("URL") { - Some(url) => url.clone(), - None => { - let port = matches.get_one::("NODE_PORT").unwrap(); - format!("http://localhost:{}", port) - } - }; + let url = format!( + "http://localhost:{}", + matches.get_one::("NODE_PORT").unwrap(), + ); start_package::execute(&package_dir, &url).await } Some(("update", matches)) => { @@ -387,13 +368,10 @@ async fn execute( let package_id = matches .get_one::("PACKAGE_ID") .and_then(|s: &String| Some(s.as_str())); - let url: String = match matches.get_one::("URL") { - Some(url) => url.clone(), - None => { - let port = matches.get_one::("NODE_PORT").unwrap(); - format!("http://localhost:{}", port) - } - }; + let url = format!( + "http://localhost:{}", + matches.get_one::("NODE_PORT").unwrap(), + ); let download_from = matches .get_one::("NODE") .and_then(|s: &String| Some(s.as_str())); @@ -622,16 +600,9 @@ async fn make_app(current_dir: &std::ffi::OsString) -> Result { .action(ArgAction::Set) .short('p') .long("port") - .help("Node port: for use on localhost (overridden by URL)") + .help("localhost node port; for remote see https://book.kinode.org/hosted-nodes.html#using-kit-with-your-hosted-node") + .default_value("8080") .value_parser(value_parser!(u16)) - .required(false) - ) - .arg(Arg::new("URL") - .action(ArgAction::Set) - .short('u') - .long("url") - .help("Node URL (overrides NODE_PORT)") - .required(false) ) .arg(Arg::new("NODE") .action(ArgAction::Set) @@ -666,17 +637,10 @@ async fn make_app(current_dir: &std::ffi::OsString) -> Result { .action(ArgAction::Set) .short('p') .long("port") - .help("Node port: for use on localhost (overridden by URL)") + .help("localhost node port; for remote see https://book.kinode.org/hosted-nodes.html#using-kit-with-your-hosted-node") .default_value("8080") .value_parser(value_parser!(u16)) ) - .arg(Arg::new("URL") - .action(ArgAction::Set) - .short('u') - .long("url") - .help("Node URL (overrides NODE_PORT)") - .required(false) - ) .arg(Arg::new("NODE") .action(ArgAction::Set) .short('d') @@ -786,17 +750,10 @@ async fn make_app(current_dir: &std::ffi::OsString) -> Result { .action(ArgAction::Set) .short('p') .long("port") - .help("Node port: for use on localhost (overridden by URL)") + .help("localhost node port; for remote see https://book.kinode.org/hosted-nodes.html#using-kit-with-your-hosted-node") .default_value("8080") .value_parser(value_parser!(u16)) ) - .arg(Arg::new("URL") - .action(ArgAction::Set) - .short('u') - .long("url") - .help("Node URL (overrides NODE_PORT)") - .required(false) - ) .arg(Arg::new("RELEASE") .action(ArgAction::SetTrue) .long("release") @@ -827,17 +784,10 @@ async fn make_app(current_dir: &std::ffi::OsString) -> Result { .action(ArgAction::Set) .short('p') .long("port") - .help("Node port: for use on localhost (overridden by URL)") + .help("localhost node port; for remote see https://book.kinode.org/hosted-nodes.html#using-kit-with-your-hosted-node") .default_value("8080") .value_parser(value_parser!(u16)) ) - .arg(Arg::new("URL") - .action(ArgAction::Set) - .short('u') - .long("url") - .help("Node URL (overrides NODE_PORT)") - .required(false) - ) .arg(Arg::new("NODE_NAME") .action(ArgAction::Set) .short('n') @@ -928,17 +878,10 @@ async fn make_app(current_dir: &std::ffi::OsString) -> Result { .action(ArgAction::Set) .short('p') .long("port") - .help("Node port: for use on localhost (overridden by URL)") + .help("localhost node port; for remote see https://book.kinode.org/hosted-nodes.html#using-kit-with-your-hosted-node") .default_value("8080") .value_parser(value_parser!(u16)) ) - .arg(Arg::new("URL") - .action(ArgAction::Set) - .short('u') - .long("url") - .help("Node URL (overrides NODE_PORT)") - .required(false) - ) ) .subcommand(Command::new("reset-cache") .about("Reset kit cache (Kinode core binaries, logs, etc.)") @@ -974,17 +917,10 @@ async fn make_app(current_dir: &std::ffi::OsString) -> Result { .action(ArgAction::Set) .short('p') .long("port") - .help("Node port: for use on localhost (overridden by URL)") + .help("localhost node port; for remote see https://book.kinode.org/hosted-nodes.html#using-kit-with-your-hosted-node") .default_value("8080") .value_parser(value_parser!(u16)) ) - .arg(Arg::new("URL") - .action(ArgAction::Set) - .short('u') - .long("url") - .help("Node URL (overrides NODE_PORT)") - .required(false) - ) ) .subcommand(Command::new("update") .about("Fetch the most recent version of kit") @@ -1012,17 +948,10 @@ async fn make_app(current_dir: &std::ffi::OsString) -> Result { .action(ArgAction::Set) .short('p') .long("port") - .help("Node port: for use on localhost (overridden by URL)") + .help("localhost node port; for remote see https://book.kinode.org/hosted-nodes.html#using-kit-with-your-hosted-node") .default_value("8080") .value_parser(value_parser!(u16)) ) - .arg(Arg::new("URL") - .action(ArgAction::Set) - .short('u') - .long("url") - .help("Node URL (overrides NODE_PORT)") - .required(false) - ) .arg(Arg::new("NODE") .action(ArgAction::Set) .short('d') From 3db383b4c84178d5f5f6cba21e3fe6af376a1b36 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Fri, 12 Jul 2024 16:32:26 -0700 Subject: [PATCH 6/8] setup: dry --- src/setup/mod.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/setup/mod.rs b/src/setup/mod.rs index 7c1e759c..184f2078 100644 --- a/src/setup/mod.rs +++ b/src/setup/mod.rs @@ -162,13 +162,7 @@ pub fn get_newest_valid_node_version( let required_major = required_major.unwrap_or(REQUIRED_NODE_MAJOR); let minimum_minor = minimum_minor.unwrap_or(MINIMUM_NODE_MINOR); - let output = Command::new("bash") - .arg("-c") - .arg("source ~/.nvm/nvm.sh && nvm ls --no-alias") - .output()? - .stdout; - - let nvm_ls = String::from_utf8_lossy(&output); + let nvm_ls = call_with_nvm_output("nvm ls --no-alias")?; let mut versions = Vec::new(); for line in nvm_ls.lines() { From a8457d7179f389195218b67519e70611413b227e Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Fri, 12 Jul 2024 16:48:58 -0700 Subject: [PATCH 7/8] new: fix a bug & bump deps --- src/new/templates/rust/no-ui/chat/send/Cargo.toml_ | 2 +- .../rust/no-ui/chat/{package_name}/Cargo.toml_ | 2 +- .../rust/no-ui/echo/{package_name}/Cargo.toml_ | 2 +- .../templates/rust/no-ui/fibonacci/number/Cargo.toml_ | 2 +- .../rust/no-ui/fibonacci/{package_name}/Cargo.toml_ | 2 +- .../rust/no-ui/file_transfer/download/Cargo.toml_ | 2 +- .../rust/no-ui/file_transfer/download/src/lib.rs | 10 +++++++--- .../rust/no-ui/file_transfer/list_files/Cargo.toml_ | 2 +- .../rust/no-ui/file_transfer/worker/Cargo.toml_ | 2 +- .../no-ui/file_transfer/{package_name}/Cargo.toml_ | 2 +- .../{package_name}_test/Cargo.toml_ | 2 +- .../{package_name}_test/Cargo.toml_ | 2 +- .../{package_name}_test/Cargo.toml_ | 2 +- .../{package_name}_test/Cargo.toml_ | 2 +- 14 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/new/templates/rust/no-ui/chat/send/Cargo.toml_ b/src/new/templates/rust/no-ui/chat/send/Cargo.toml_ index a08adf79..c208c510 100644 --- a/src/new/templates/rust/no-ui/chat/send/Cargo.toml_ +++ b/src/new/templates/rust/no-ui/chat/send/Cargo.toml_ @@ -5,7 +5,7 @@ edition = "2021" [dependencies] anyhow = "1.0" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.0" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.3" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" wit-bindgen = "0.24.0" diff --git a/src/new/templates/rust/no-ui/chat/{package_name}/Cargo.toml_ b/src/new/templates/rust/no-ui/chat/{package_name}/Cargo.toml_ index 04bd8918..eff3bb6a 100644 --- a/src/new/templates/rust/no-ui/chat/{package_name}/Cargo.toml_ +++ b/src/new/templates/rust/no-ui/chat/{package_name}/Cargo.toml_ @@ -5,7 +5,7 @@ edition = "2021" [dependencies] anyhow = "1.0" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.0" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.3" } process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/src/new/templates/rust/no-ui/echo/{package_name}/Cargo.toml_ b/src/new/templates/rust/no-ui/echo/{package_name}/Cargo.toml_ index 183d81b8..e4c3c320 100644 --- a/src/new/templates/rust/no-ui/echo/{package_name}/Cargo.toml_ +++ b/src/new/templates/rust/no-ui/echo/{package_name}/Cargo.toml_ @@ -6,7 +6,7 @@ edition = "2021" [dependencies] anyhow = "1.0" bincode = "1.3.3" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.0" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.3" } process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/src/new/templates/rust/no-ui/fibonacci/number/Cargo.toml_ b/src/new/templates/rust/no-ui/fibonacci/number/Cargo.toml_ index 27b23008..a7313dd9 100644 --- a/src/new/templates/rust/no-ui/fibonacci/number/Cargo.toml_ +++ b/src/new/templates/rust/no-ui/fibonacci/number/Cargo.toml_ @@ -5,7 +5,7 @@ edition = "2021" [dependencies] anyhow = "1.0" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.0" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.3" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" wit-bindgen = "0.24.0" diff --git a/src/new/templates/rust/no-ui/fibonacci/{package_name}/Cargo.toml_ b/src/new/templates/rust/no-ui/fibonacci/{package_name}/Cargo.toml_ index 183d81b8..e4c3c320 100644 --- a/src/new/templates/rust/no-ui/fibonacci/{package_name}/Cargo.toml_ +++ b/src/new/templates/rust/no-ui/fibonacci/{package_name}/Cargo.toml_ @@ -6,7 +6,7 @@ edition = "2021" [dependencies] anyhow = "1.0" bincode = "1.3.3" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.0" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.3" } process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/src/new/templates/rust/no-ui/file_transfer/download/Cargo.toml_ b/src/new/templates/rust/no-ui/file_transfer/download/Cargo.toml_ index 27e6ffca..32567295 100644 --- a/src/new/templates/rust/no-ui/file_transfer/download/Cargo.toml_ +++ b/src/new/templates/rust/no-ui/file_transfer/download/Cargo.toml_ @@ -5,7 +5,7 @@ edition = "2021" [dependencies] anyhow = "1.0" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.0" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.3" } process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/src/new/templates/rust/no-ui/file_transfer/download/src/lib.rs b/src/new/templates/rust/no-ui/file_transfer/download/src/lib.rs index d26491ce..7f35787f 100644 --- a/src/new/templates/rust/no-ui/file_transfer/download/src/lib.rs +++ b/src/new/templates/rust/no-ui/file_transfer/download/src/lib.rs @@ -1,7 +1,7 @@ use crate::kinode::process::standard::{ProcessId as WitProcessId}; use crate::kinode::process::{package_name}::{Address as WitAddress, Request as TransferRequest, DownloadRequest}; use kinode_process_lib::{ - await_next_message_body, call_init, println, Address, Message, ProcessId, Request, + await_next_message_body, call_init, println, Address, ProcessId, Request, }; wit_bindgen::generate!({ @@ -50,10 +50,14 @@ fn init(our: Address) { .parse() .unwrap(); - let Ok(_) = Request::to(our) + match Request::to(our) .body(TransferRequest::Download(DownloadRequest { name: name.into(), target: target.clone().into(), })) - .send(); + .send() + { + Ok(_) => {} + Err(e) => println!("download failed: {e:?}"), + } } diff --git a/src/new/templates/rust/no-ui/file_transfer/list_files/Cargo.toml_ b/src/new/templates/rust/no-ui/file_transfer/list_files/Cargo.toml_ index 0150d382..6c6ca8fb 100644 --- a/src/new/templates/rust/no-ui/file_transfer/list_files/Cargo.toml_ +++ b/src/new/templates/rust/no-ui/file_transfer/list_files/Cargo.toml_ @@ -5,7 +5,7 @@ edition = "2021" [dependencies] anyhow = "1.0" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.0" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.3" } process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/src/new/templates/rust/no-ui/file_transfer/worker/Cargo.toml_ b/src/new/templates/rust/no-ui/file_transfer/worker/Cargo.toml_ index b35e48c8..4145e57d 100644 --- a/src/new/templates/rust/no-ui/file_transfer/worker/Cargo.toml_ +++ b/src/new/templates/rust/no-ui/file_transfer/worker/Cargo.toml_ @@ -6,7 +6,7 @@ edition = "2021" [dependencies] anyhow = "1.0" bincode = "1.3.3" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.0" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.3" } process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/src/new/templates/rust/no-ui/file_transfer/{package_name}/Cargo.toml_ b/src/new/templates/rust/no-ui/file_transfer/{package_name}/Cargo.toml_ index 04bd8918..eff3bb6a 100644 --- a/src/new/templates/rust/no-ui/file_transfer/{package_name}/Cargo.toml_ +++ b/src/new/templates/rust/no-ui/file_transfer/{package_name}/Cargo.toml_ @@ -5,7 +5,7 @@ edition = "2021" [dependencies] anyhow = "1.0" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.0" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.3" } process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/src/new/templates/test/chat/{package_name}_test/{package_name}_test/Cargo.toml_ b/src/new/templates/test/chat/{package_name}_test/{package_name}_test/Cargo.toml_ index 402919e0..c8717be6 100644 --- a/src/new/templates/test/chat/{package_name}_test/{package_name}_test/Cargo.toml_ +++ b/src/new/templates/test/chat/{package_name}_test/{package_name}_test/Cargo.toml_ @@ -6,7 +6,7 @@ edition = "2021" [dependencies] anyhow = "1.0" bincode = "1.3" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "b492f3b" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.3" } process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" } rmp-serde = "1.1" serde = { version = "1.0", features = ["derive"] } diff --git a/src/new/templates/test/echo/{package_name}_test/{package_name}_test/Cargo.toml_ b/src/new/templates/test/echo/{package_name}_test/{package_name}_test/Cargo.toml_ index 402919e0..c8717be6 100644 --- a/src/new/templates/test/echo/{package_name}_test/{package_name}_test/Cargo.toml_ +++ b/src/new/templates/test/echo/{package_name}_test/{package_name}_test/Cargo.toml_ @@ -6,7 +6,7 @@ edition = "2021" [dependencies] anyhow = "1.0" bincode = "1.3" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "b492f3b" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.3" } process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" } rmp-serde = "1.1" serde = { version = "1.0", features = ["derive"] } diff --git a/src/new/templates/test/fibonacci/{package_name}_test/{package_name}_test/Cargo.toml_ b/src/new/templates/test/fibonacci/{package_name}_test/{package_name}_test/Cargo.toml_ index 402919e0..c8717be6 100644 --- a/src/new/templates/test/fibonacci/{package_name}_test/{package_name}_test/Cargo.toml_ +++ b/src/new/templates/test/fibonacci/{package_name}_test/{package_name}_test/Cargo.toml_ @@ -6,7 +6,7 @@ edition = "2021" [dependencies] anyhow = "1.0" bincode = "1.3" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "b492f3b" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.3" } process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" } rmp-serde = "1.1" serde = { version = "1.0", features = ["derive"] } diff --git a/src/new/templates/test/file_transfer/{package_name}_test/{package_name}_test/Cargo.toml_ b/src/new/templates/test/file_transfer/{package_name}_test/{package_name}_test/Cargo.toml_ index 402919e0..c8717be6 100644 --- a/src/new/templates/test/file_transfer/{package_name}_test/{package_name}_test/Cargo.toml_ +++ b/src/new/templates/test/file_transfer/{package_name}_test/{package_name}_test/Cargo.toml_ @@ -6,7 +6,7 @@ edition = "2021" [dependencies] anyhow = "1.0" bincode = "1.3" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "b492f3b" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.8.3" } process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" } rmp-serde = "1.1" serde = { version = "1.0", features = ["derive"] } From dc8bda65cf5149248e8363eb7a0174f18ff47e7e Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Mon, 15 Jul 2024 04:47:49 -0700 Subject: [PATCH 8/8] build: fix regression causing slow rebuild times; dont dirty target/ --- src/build/mod.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/build/mod.rs b/src/build/mod.rs index 806ca51f..7e8243f5 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -537,7 +537,15 @@ async fn build_wit_dir( }; download_file(wit_url, &wit_dir.join("kinode.wit")).await?; for (file_name, contents) in apis { - fs::write(wit_dir.join(file_name), contents)?; + let destination = wit_dir.join(file_name); + if destination.exists() { + // check if contents have not changed -> no-op + let old_contents = fs::read(&destination)?; + if &old_contents == contents { + continue; + } + } + fs::write(&destination, contents)?; } Ok(()) }