From 82055bacf58bf3d64a5cce0514cc6f2fcd849eec Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Sun, 8 Oct 2023 18:57:45 -0400 Subject: [PATCH] delete non-symlinked process_libs --- modules/chess/src/process_lib.rs | 105 -------------- modules/homepage/src/process_lib.rs | 142 ------------------ modules/http_bindings/src/process_lib.rs | 142 ------------------ modules/http_proxy/src/process_lib.rs | 142 ------------------ modules/orgs/src/process_lib.rs | 105 -------------- modules/qns_indexer/src/process_lib.rs | 105 -------------- modules/rpc/src/process_lib.rs | 142 ------------------ modules/terminal/src/process_lib.rs | 1 - src/kernel_types.rs | 175 ++++++++++++----------- src/process_lib.rs | 81 +++++++---- src/types.rs | 29 ++-- src/vfs.rs | 12 +- 12 files changed, 161 insertions(+), 1020 deletions(-) delete mode 100644 modules/chess/src/process_lib.rs delete mode 100644 modules/homepage/src/process_lib.rs delete mode 100644 modules/http_bindings/src/process_lib.rs delete mode 100644 modules/http_proxy/src/process_lib.rs delete mode 100644 modules/orgs/src/process_lib.rs delete mode 100644 modules/qns_indexer/src/process_lib.rs delete mode 100644 modules/rpc/src/process_lib.rs delete mode 120000 modules/terminal/src/process_lib.rs diff --git a/modules/chess/src/process_lib.rs b/modules/chess/src/process_lib.rs deleted file mode 100644 index 2b9f5cd8..00000000 --- a/modules/chess/src/process_lib.rs +++ /dev/null @@ -1,105 +0,0 @@ -use serde::{Deserialize, Serialize}; - -use super::bindings::component::uq_process::types::*; -use super::bindings::{Address, get_payload, Payload, SendError, send_request}; - -impl PartialEq for ProcessId { - fn eq(&self, other: &Self) -> bool { - match (self, other) { - (ProcessId::Id(i1), ProcessId::Id(i2)) => i1 == i2, - (ProcessId::Name(s1), ProcessId::Name(s2)) => s1 == s2, - _ => false, - } - } -} -impl PartialEq<&str> for ProcessId { - fn eq(&self, other: &&str) -> bool { - match self { - ProcessId::Id(_) => false, - ProcessId::Name(s) => s == other, - } - } -} -impl PartialEq for ProcessId { - fn eq(&self, other: &u64) -> bool { - match self { - ProcessId::Id(i) => i == other, - ProcessId::Name(_) => false, - } - } -} - -pub fn send_and_await_response( - target: &Address, - inherit: bool, - ipc: Option, - metadata: Option, - 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 get_state(our: String) -> Option { - match super::bindings::get_state() { - Some(bytes) => Some(Payload { - mime: None, - bytes, - }), - None => None, - } -} - -pub fn set_state(our: String, bytes: Vec) { - super::bindings::set_state(&bytes); -} - -pub fn await_set_state(our: String, state: &T) -where - T: serde::Serialize, -{ - super::bindings::set_state(&bincode::serialize(state).unwrap()); -} - -pub fn parse_message_ipc(json_string: Option) -> anyhow::Result -where - for<'a> T: serde::Deserialize<'a>, -{ - let parsed: T = serde_json::from_str( - json_string - .ok_or(anyhow::anyhow!("json payload empty"))? - .as_str(), - )?; - Ok(parsed) -} - -// move these to better place! -#[derive(Serialize, Deserialize, Debug)] -pub enum FsAction { - Write, - Replace(u128), - Append(Option), - 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, -} diff --git a/modules/homepage/src/process_lib.rs b/modules/homepage/src/process_lib.rs deleted file mode 100644 index 69e4df97..00000000 --- a/modules/homepage/src/process_lib.rs +++ /dev/null @@ -1,142 +0,0 @@ -use serde::{Deserialize, Serialize}; - -use super::bindings::component::uq_process::types::*; -use super::bindings::{get_payload, send_request, Address, Payload}; - -impl PartialEq for ProcessId { - fn eq(&self, other: &Self) -> bool { - match (self, other) { - (ProcessId::Id(i1), ProcessId::Id(i2)) => i1 == i2, - (ProcessId::Name(s1), ProcessId::Name(s2)) => s1 == s2, - _ => false, - } - } -} -impl PartialEq<&str> for ProcessId { - fn eq(&self, other: &&str) -> bool { - match self { - ProcessId::Id(_) => false, - ProcessId::Name(s) => s == other, - } - } -} -impl PartialEq for ProcessId { - fn eq(&self, other: &u64) -> bool { - match self { - ProcessId::Id(i) => i == other, - ProcessId::Name(_) => false, - } - } -} - -pub fn send_and_await_response( - target: &Address, - inherit: bool, - ipc: Option, - metadata: Option, - 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 get_state(our: String) -> Option { - let _ = send_and_await_response( - &Address { - node: our, - process: ProcessId::Name("filesystem".to_string()), - }, - false, - Some(serde_json::to_string(&FsAction::GetState).unwrap()), - None, - None, - 5, // TODO evaluate timeout - ); - get_payload() -} - -pub fn set_state(our: String, bytes: Vec) { - send_request( - &Address { - node: our, - process: ProcessId::Name("filesystem".to_string()), - }, - &Request { - inherit: false, - expects_response: Some(5), // TODO evaluate timeout - ipc: Some(serde_json::to_string(&FsAction::SetState).unwrap()), - metadata: None, - }, - None, - Some(&Payload { mime: None, bytes }), - ); -} - -pub fn await_set_state(our: String, state: &T) -where - T: serde::Serialize, -{ - // Request/Response stays local -> no SendError - let (_, response) = send_and_await_response( - &Address { - node: our, - process: ProcessId::Name("filesystem".to_string()), - }, - false, - Some(serde_json::to_string(&FsAction::SetState).unwrap()), - None, - Some(&Payload { - mime: None, - bytes: bincode::serialize(state).unwrap(), - }), - 5, // TODO evaluate timeout - ) - .unwrap(); - match response { - Message::Request(_) => panic!("got request from filesystem"), - Message::Response((response, _context)) => return, - } -} - -pub fn parse_message_ipc(json_string: Option) -> anyhow::Result -where - for<'a> T: serde::Deserialize<'a>, -{ - let parsed: T = serde_json::from_str( - json_string - .ok_or(anyhow::anyhow!("json payload empty"))? - .as_str(), - )?; - Ok(parsed) -} - -// move these to better place! -#[derive(Serialize, Deserialize, Debug)] -pub enum FsAction { - Write, - Replace(u128), - Append(Option), - 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, -} diff --git a/modules/http_bindings/src/process_lib.rs b/modules/http_bindings/src/process_lib.rs deleted file mode 100644 index 69e4df97..00000000 --- a/modules/http_bindings/src/process_lib.rs +++ /dev/null @@ -1,142 +0,0 @@ -use serde::{Deserialize, Serialize}; - -use super::bindings::component::uq_process::types::*; -use super::bindings::{get_payload, send_request, Address, Payload}; - -impl PartialEq for ProcessId { - fn eq(&self, other: &Self) -> bool { - match (self, other) { - (ProcessId::Id(i1), ProcessId::Id(i2)) => i1 == i2, - (ProcessId::Name(s1), ProcessId::Name(s2)) => s1 == s2, - _ => false, - } - } -} -impl PartialEq<&str> for ProcessId { - fn eq(&self, other: &&str) -> bool { - match self { - ProcessId::Id(_) => false, - ProcessId::Name(s) => s == other, - } - } -} -impl PartialEq for ProcessId { - fn eq(&self, other: &u64) -> bool { - match self { - ProcessId::Id(i) => i == other, - ProcessId::Name(_) => false, - } - } -} - -pub fn send_and_await_response( - target: &Address, - inherit: bool, - ipc: Option, - metadata: Option, - 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 get_state(our: String) -> Option { - let _ = send_and_await_response( - &Address { - node: our, - process: ProcessId::Name("filesystem".to_string()), - }, - false, - Some(serde_json::to_string(&FsAction::GetState).unwrap()), - None, - None, - 5, // TODO evaluate timeout - ); - get_payload() -} - -pub fn set_state(our: String, bytes: Vec) { - send_request( - &Address { - node: our, - process: ProcessId::Name("filesystem".to_string()), - }, - &Request { - inherit: false, - expects_response: Some(5), // TODO evaluate timeout - ipc: Some(serde_json::to_string(&FsAction::SetState).unwrap()), - metadata: None, - }, - None, - Some(&Payload { mime: None, bytes }), - ); -} - -pub fn await_set_state(our: String, state: &T) -where - T: serde::Serialize, -{ - // Request/Response stays local -> no SendError - let (_, response) = send_and_await_response( - &Address { - node: our, - process: ProcessId::Name("filesystem".to_string()), - }, - false, - Some(serde_json::to_string(&FsAction::SetState).unwrap()), - None, - Some(&Payload { - mime: None, - bytes: bincode::serialize(state).unwrap(), - }), - 5, // TODO evaluate timeout - ) - .unwrap(); - match response { - Message::Request(_) => panic!("got request from filesystem"), - Message::Response((response, _context)) => return, - } -} - -pub fn parse_message_ipc(json_string: Option) -> anyhow::Result -where - for<'a> T: serde::Deserialize<'a>, -{ - let parsed: T = serde_json::from_str( - json_string - .ok_or(anyhow::anyhow!("json payload empty"))? - .as_str(), - )?; - Ok(parsed) -} - -// move these to better place! -#[derive(Serialize, Deserialize, Debug)] -pub enum FsAction { - Write, - Replace(u128), - Append(Option), - 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, -} diff --git a/modules/http_proxy/src/process_lib.rs b/modules/http_proxy/src/process_lib.rs deleted file mode 100644 index 69e4df97..00000000 --- a/modules/http_proxy/src/process_lib.rs +++ /dev/null @@ -1,142 +0,0 @@ -use serde::{Deserialize, Serialize}; - -use super::bindings::component::uq_process::types::*; -use super::bindings::{get_payload, send_request, Address, Payload}; - -impl PartialEq for ProcessId { - fn eq(&self, other: &Self) -> bool { - match (self, other) { - (ProcessId::Id(i1), ProcessId::Id(i2)) => i1 == i2, - (ProcessId::Name(s1), ProcessId::Name(s2)) => s1 == s2, - _ => false, - } - } -} -impl PartialEq<&str> for ProcessId { - fn eq(&self, other: &&str) -> bool { - match self { - ProcessId::Id(_) => false, - ProcessId::Name(s) => s == other, - } - } -} -impl PartialEq for ProcessId { - fn eq(&self, other: &u64) -> bool { - match self { - ProcessId::Id(i) => i == other, - ProcessId::Name(_) => false, - } - } -} - -pub fn send_and_await_response( - target: &Address, - inherit: bool, - ipc: Option, - metadata: Option, - 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 get_state(our: String) -> Option { - let _ = send_and_await_response( - &Address { - node: our, - process: ProcessId::Name("filesystem".to_string()), - }, - false, - Some(serde_json::to_string(&FsAction::GetState).unwrap()), - None, - None, - 5, // TODO evaluate timeout - ); - get_payload() -} - -pub fn set_state(our: String, bytes: Vec) { - send_request( - &Address { - node: our, - process: ProcessId::Name("filesystem".to_string()), - }, - &Request { - inherit: false, - expects_response: Some(5), // TODO evaluate timeout - ipc: Some(serde_json::to_string(&FsAction::SetState).unwrap()), - metadata: None, - }, - None, - Some(&Payload { mime: None, bytes }), - ); -} - -pub fn await_set_state(our: String, state: &T) -where - T: serde::Serialize, -{ - // Request/Response stays local -> no SendError - let (_, response) = send_and_await_response( - &Address { - node: our, - process: ProcessId::Name("filesystem".to_string()), - }, - false, - Some(serde_json::to_string(&FsAction::SetState).unwrap()), - None, - Some(&Payload { - mime: None, - bytes: bincode::serialize(state).unwrap(), - }), - 5, // TODO evaluate timeout - ) - .unwrap(); - match response { - Message::Request(_) => panic!("got request from filesystem"), - Message::Response((response, _context)) => return, - } -} - -pub fn parse_message_ipc(json_string: Option) -> anyhow::Result -where - for<'a> T: serde::Deserialize<'a>, -{ - let parsed: T = serde_json::from_str( - json_string - .ok_or(anyhow::anyhow!("json payload empty"))? - .as_str(), - )?; - Ok(parsed) -} - -// move these to better place! -#[derive(Serialize, Deserialize, Debug)] -pub enum FsAction { - Write, - Replace(u128), - Append(Option), - 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, -} diff --git a/modules/orgs/src/process_lib.rs b/modules/orgs/src/process_lib.rs deleted file mode 100644 index 2b9f5cd8..00000000 --- a/modules/orgs/src/process_lib.rs +++ /dev/null @@ -1,105 +0,0 @@ -use serde::{Deserialize, Serialize}; - -use super::bindings::component::uq_process::types::*; -use super::bindings::{Address, get_payload, Payload, SendError, send_request}; - -impl PartialEq for ProcessId { - fn eq(&self, other: &Self) -> bool { - match (self, other) { - (ProcessId::Id(i1), ProcessId::Id(i2)) => i1 == i2, - (ProcessId::Name(s1), ProcessId::Name(s2)) => s1 == s2, - _ => false, - } - } -} -impl PartialEq<&str> for ProcessId { - fn eq(&self, other: &&str) -> bool { - match self { - ProcessId::Id(_) => false, - ProcessId::Name(s) => s == other, - } - } -} -impl PartialEq for ProcessId { - fn eq(&self, other: &u64) -> bool { - match self { - ProcessId::Id(i) => i == other, - ProcessId::Name(_) => false, - } - } -} - -pub fn send_and_await_response( - target: &Address, - inherit: bool, - ipc: Option, - metadata: Option, - 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 get_state(our: String) -> Option { - match super::bindings::get_state() { - Some(bytes) => Some(Payload { - mime: None, - bytes, - }), - None => None, - } -} - -pub fn set_state(our: String, bytes: Vec) { - super::bindings::set_state(&bytes); -} - -pub fn await_set_state(our: String, state: &T) -where - T: serde::Serialize, -{ - super::bindings::set_state(&bincode::serialize(state).unwrap()); -} - -pub fn parse_message_ipc(json_string: Option) -> anyhow::Result -where - for<'a> T: serde::Deserialize<'a>, -{ - let parsed: T = serde_json::from_str( - json_string - .ok_or(anyhow::anyhow!("json payload empty"))? - .as_str(), - )?; - Ok(parsed) -} - -// move these to better place! -#[derive(Serialize, Deserialize, Debug)] -pub enum FsAction { - Write, - Replace(u128), - Append(Option), - 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, -} diff --git a/modules/qns_indexer/src/process_lib.rs b/modules/qns_indexer/src/process_lib.rs deleted file mode 100644 index 2b9f5cd8..00000000 --- a/modules/qns_indexer/src/process_lib.rs +++ /dev/null @@ -1,105 +0,0 @@ -use serde::{Deserialize, Serialize}; - -use super::bindings::component::uq_process::types::*; -use super::bindings::{Address, get_payload, Payload, SendError, send_request}; - -impl PartialEq for ProcessId { - fn eq(&self, other: &Self) -> bool { - match (self, other) { - (ProcessId::Id(i1), ProcessId::Id(i2)) => i1 == i2, - (ProcessId::Name(s1), ProcessId::Name(s2)) => s1 == s2, - _ => false, - } - } -} -impl PartialEq<&str> for ProcessId { - fn eq(&self, other: &&str) -> bool { - match self { - ProcessId::Id(_) => false, - ProcessId::Name(s) => s == other, - } - } -} -impl PartialEq for ProcessId { - fn eq(&self, other: &u64) -> bool { - match self { - ProcessId::Id(i) => i == other, - ProcessId::Name(_) => false, - } - } -} - -pub fn send_and_await_response( - target: &Address, - inherit: bool, - ipc: Option, - metadata: Option, - 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 get_state(our: String) -> Option { - match super::bindings::get_state() { - Some(bytes) => Some(Payload { - mime: None, - bytes, - }), - None => None, - } -} - -pub fn set_state(our: String, bytes: Vec) { - super::bindings::set_state(&bytes); -} - -pub fn await_set_state(our: String, state: &T) -where - T: serde::Serialize, -{ - super::bindings::set_state(&bincode::serialize(state).unwrap()); -} - -pub fn parse_message_ipc(json_string: Option) -> anyhow::Result -where - for<'a> T: serde::Deserialize<'a>, -{ - let parsed: T = serde_json::from_str( - json_string - .ok_or(anyhow::anyhow!("json payload empty"))? - .as_str(), - )?; - Ok(parsed) -} - -// move these to better place! -#[derive(Serialize, Deserialize, Debug)] -pub enum FsAction { - Write, - Replace(u128), - Append(Option), - 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, -} diff --git a/modules/rpc/src/process_lib.rs b/modules/rpc/src/process_lib.rs deleted file mode 100644 index 69e4df97..00000000 --- a/modules/rpc/src/process_lib.rs +++ /dev/null @@ -1,142 +0,0 @@ -use serde::{Deserialize, Serialize}; - -use super::bindings::component::uq_process::types::*; -use super::bindings::{get_payload, send_request, Address, Payload}; - -impl PartialEq for ProcessId { - fn eq(&self, other: &Self) -> bool { - match (self, other) { - (ProcessId::Id(i1), ProcessId::Id(i2)) => i1 == i2, - (ProcessId::Name(s1), ProcessId::Name(s2)) => s1 == s2, - _ => false, - } - } -} -impl PartialEq<&str> for ProcessId { - fn eq(&self, other: &&str) -> bool { - match self { - ProcessId::Id(_) => false, - ProcessId::Name(s) => s == other, - } - } -} -impl PartialEq for ProcessId { - fn eq(&self, other: &u64) -> bool { - match self { - ProcessId::Id(i) => i == other, - ProcessId::Name(_) => false, - } - } -} - -pub fn send_and_await_response( - target: &Address, - inherit: bool, - ipc: Option, - metadata: Option, - 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 get_state(our: String) -> Option { - let _ = send_and_await_response( - &Address { - node: our, - process: ProcessId::Name("filesystem".to_string()), - }, - false, - Some(serde_json::to_string(&FsAction::GetState).unwrap()), - None, - None, - 5, // TODO evaluate timeout - ); - get_payload() -} - -pub fn set_state(our: String, bytes: Vec) { - send_request( - &Address { - node: our, - process: ProcessId::Name("filesystem".to_string()), - }, - &Request { - inherit: false, - expects_response: Some(5), // TODO evaluate timeout - ipc: Some(serde_json::to_string(&FsAction::SetState).unwrap()), - metadata: None, - }, - None, - Some(&Payload { mime: None, bytes }), - ); -} - -pub fn await_set_state(our: String, state: &T) -where - T: serde::Serialize, -{ - // Request/Response stays local -> no SendError - let (_, response) = send_and_await_response( - &Address { - node: our, - process: ProcessId::Name("filesystem".to_string()), - }, - false, - Some(serde_json::to_string(&FsAction::SetState).unwrap()), - None, - Some(&Payload { - mime: None, - bytes: bincode::serialize(state).unwrap(), - }), - 5, // TODO evaluate timeout - ) - .unwrap(); - match response { - Message::Request(_) => panic!("got request from filesystem"), - Message::Response((response, _context)) => return, - } -} - -pub fn parse_message_ipc(json_string: Option) -> anyhow::Result -where - for<'a> T: serde::Deserialize<'a>, -{ - let parsed: T = serde_json::from_str( - json_string - .ok_or(anyhow::anyhow!("json payload empty"))? - .as_str(), - )?; - Ok(parsed) -} - -// move these to better place! -#[derive(Serialize, Deserialize, Debug)] -pub enum FsAction { - Write, - Replace(u128), - Append(Option), - 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, -} diff --git a/modules/terminal/src/process_lib.rs b/modules/terminal/src/process_lib.rs deleted file mode 120000 index 77367fe0..00000000 --- a/modules/terminal/src/process_lib.rs +++ /dev/null @@ -1 +0,0 @@ -../../../src/process_lib.rs \ No newline at end of file diff --git a/src/kernel_types.rs b/src/kernel_types.rs index eb80c31e..ffa63ed0 100644 --- a/src/kernel_types.rs +++ b/src/kernel_types.rs @@ -9,6 +9,7 @@ use std::collections::HashSet; // pub type Context = String; // JSON-string +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. @@ -22,14 +23,12 @@ pub struct ProcessId { 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 { + pub fn new(process_name: &str, package_name: &str, publisher_node: &str) -> Self { ProcessId { - process_name: match process_name { - Some(name) => name.to_string(), - None => rand::random::().to_string(), - }, + process_name: process_name.into(), package_name: package_name.into(), publisher_node: publisher_node.into(), } @@ -75,6 +74,20 @@ impl ProcessId { 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, + } + } } pub enum ProcessIdParseError { @@ -82,44 +95,31 @@ pub enum ProcessIdParseError { MissingField, } -// #[derive(Clone, Debug, Eq, Hash, Serialize, Deserialize)] -// pub enum ProcessId { -// Id(u64), -// Name(String), -// } - -// impl PartialEq for ProcessId { -// fn eq(&self, other: &Self) -> bool { -// match (self, other) { -// (ProcessId::Id(i1), ProcessId::Id(i2)) => i1 == i2, -// (ProcessId::Name(s1), ProcessId::Name(s2)) => s1 == s2, -// _ => false, -// } -// } -// } -// impl PartialEq<&str> for ProcessId { -// fn eq(&self, other: &&str) -> bool { -// match self { -// ProcessId::Id(_) => false, -// ProcessId::Name(s) => s == other, -// } -// } -// } -// impl PartialEq for ProcessId { -// fn eq(&self, other: &u64) -> bool { -// match self { -// ProcessId::Id(i) => i == other, -// ProcessId::Name(_) => false, -// } -// } -// } - #[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, // MIME type @@ -129,9 +129,9 @@ pub struct Payload { #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Request { pub inherit: bool, - pub expects_response: Option, - pub ipc: Option, // JSON-string - pub metadata: Option, // JSON-string + pub expects_response: Option, // number of seconds until timeout + pub ipc: Option, // JSON-string + pub metadata: Option, // JSON-string } #[derive(Clone, Debug, Serialize, Deserialize)] @@ -177,7 +177,17 @@ pub enum SendErrorKind { pub enum OnPanic { None, Restart, - Requests(Vec<(Address, Request)>), + Requests(Vec<(Address, Request, Option)>), +} + +impl OnPanic { + pub fn is_restart(&self) -> bool { + match self { + OnPanic::None => false, + OnPanic::Restart => true, + OnPanic::Requests(_) => false, + } + } } #[derive(Debug, Serialize, Deserialize)] @@ -203,11 +213,21 @@ pub enum KernelCommand { }, } +#[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, + pub public: bool, // marks if a process allows messages from any process } #[derive(Debug, Serialize, Deserialize)] @@ -267,7 +287,8 @@ pub enum VfsResponse { Err(VfsError), GetPath(Option), GetHash(Option), - GetEntry { // file bytes in payload, if entry was a file + GetEntry { + // file bytes in payload, if entry was a file is_file: bool, children: Vec, }, @@ -275,6 +296,14 @@ pub enum VfsResponse { GetEntryLength(u64), } +#[derive(Debug, Serialize, Deserialize)] +pub enum VfsError { + BadDriveName, + BadDescriptor, + NoCap, +} + +#[allow(dead_code)] impl VfsError { pub fn kind(&self) -> &str { match *self { @@ -285,19 +314,20 @@ impl VfsError { } } -#[derive(Debug, Serialize, Deserialize)] -pub enum VfsError { - BadDriveName, - BadDescriptor, - NoCap, -} - #[derive(Debug, Serialize, Deserialize)] pub enum KeyValueMessage { New { drive: String }, Write { drive: String, key: Vec }, Read { drive: String, key: Vec }, } + +#[derive(Debug, Serialize, Deserialize)] +pub enum KeyValueError { + BadDriveName, + NoCap, + NoBytes, +} + impl KeyValueError { pub fn kind(&self) -> &str { match *self { @@ -307,47 +337,11 @@ impl KeyValueError { } } } -#[derive(Debug, Serialize, Deserialize)] -pub enum KeyValueError { - BadDriveName, - NoCap, - NoBytes, -} // // conversions between wit types and kernel types (annoying!) // -pub fn en_wit_process_id(process_id: ProcessId) -> wit::ProcessId { - wit::ProcessId { - process_name: process_id.process().to_string(), - package_name: process_id.package().to_string(), - publisher_node: process_id.publisher().to_string(), - } -} - -pub fn de_wit_process_id(wit: wit::ProcessId) -> ProcessId { - ProcessId { - process_name: wit.process_name, - package_name: wit.package_name, - publisher_node: wit.publisher_node, - } -} - -pub fn en_wit_address(address: Address) -> wit::Address { - wit::Address { - node: address.node, - process: en_wit_process_id(address.process), - } -} - -pub fn de_wit_address(wit: wit::Address) -> Address { - Address { - node: wit.node, - process: de_wit_process_id(wit.process), - } -} - pub fn de_wit_request(wit: wit::Request) -> Request { Request { inherit: wit.inherit, @@ -402,7 +396,14 @@ pub fn en_wit_payload(load: Option) -> Option { pub fn de_wit_signed_capability(wit: wit::SignedCapability) -> SignedCapability { SignedCapability { - issuer: de_wit_address(wit.issuer), + 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, } @@ -410,7 +411,7 @@ pub fn de_wit_signed_capability(wit: wit::SignedCapability) -> SignedCapability pub fn en_wit_signed_capability(cap: SignedCapability) -> wit::SignedCapability { wit::SignedCapability { - issuer: en_wit_address(cap.issuer), + issuer: cap.issuer.en_wit(), params: cap.params, signature: cap.signature, } diff --git a/src/process_lib.rs b/src/process_lib.rs index 2b9f5cd8..68dae299 100644 --- a/src/process_lib.rs +++ b/src/process_lib.rs @@ -1,32 +1,64 @@ use serde::{Deserialize, Serialize}; use super::bindings::component::uq_process::types::*; -use super::bindings::{Address, get_payload, Payload, SendError, send_request}; +use super::bindings::{Address, Payload, SendError}; -impl PartialEq for ProcessId { - fn eq(&self, other: &Self) -> bool { - match (self, other) { - (ProcessId::Id(i1), ProcessId::Id(i2)) => i1 == i2, - (ProcessId::Name(s1), ProcessId::Name(s2)) => s1 == s2, - _ => false, +#[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 { + // 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 PartialEq<&str> for ProcessId { - fn eq(&self, other: &&str) -> bool { - match self { - ProcessId::Id(_) => false, - ProcessId::Name(s) => s == other, - } - } -} -impl PartialEq for ProcessId { - fn eq(&self, other: &u64) -> bool { - match self { - ProcessId::Id(i) => i == other, - ProcessId::Name(_) => false, - } - } + +pub enum ProcessIdParseError { + TooManyColons, + MissingField, } pub fn send_and_await_response( @@ -51,10 +83,7 @@ pub fn send_and_await_response( pub fn get_state(our: String) -> Option { match super::bindings::get_state() { - Some(bytes) => Some(Payload { - mime: None, - bytes, - }), + Some(bytes) => Some(Payload { mime: None, bytes }), None => None, } } diff --git a/src/types.rs b/src/types.rs index 2548f0b8..d1b0470b 100644 --- a/src/types.rs +++ b/src/types.rs @@ -581,13 +581,20 @@ pub enum VfsResponse { GetHash(Option), GetEntry { // file bytes in payload, if entry was a file - exists: bool, + is_file: bool, children: Vec, }, GetFileChunk, // chunk in payload, if file exists GetEntryLength(Option), } +#[derive(Debug, Serialize, Deserialize)] +pub enum VfsError { + BadDriveName, + BadDescriptor, + NoCap, +} + #[allow(dead_code)] impl VfsError { pub fn kind(&self) -> &str { @@ -599,13 +606,6 @@ impl VfsError { } } -#[derive(Debug, Serialize, Deserialize)] -pub enum VfsError { - BadDriveName, - BadDescriptor, - NoCap, -} - #[derive(Debug, Serialize, Deserialize)] pub enum KeyValueMessage { New { drive: String }, @@ -613,6 +613,13 @@ pub enum KeyValueMessage { Read { drive: String, key: Vec }, } +#[derive(Debug, Serialize, Deserialize)] +pub enum KeyValueError { + BadDriveName, + NoCap, + NoBytes, +} + #[allow(dead_code)] impl KeyValueError { pub fn kind(&self) -> &str { @@ -623,12 +630,6 @@ impl KeyValueError { } } } -#[derive(Debug, Serialize, Deserialize)] -pub enum KeyValueError { - BadDriveName, - NoCap, - NoBytes, -} // // http_client.rs types diff --git a/src/vfs.rs b/src/vfs.rs index 77b1a0eb..1924d0d0 100644 --- a/src/vfs.rs +++ b/src/vfs.rs @@ -1255,13 +1255,7 @@ async fn match_request( }; let entry_not_found = ( - Some( - serde_json::to_string(&VfsResponse::GetEntry { - exists: false, - children: vec![], - }) - .unwrap(), - ), + Some(serde_json::to_string(&VfsResponse::Err(VfsError::BadDescriptor)).unwrap()), None, ); match key { @@ -1275,7 +1269,7 @@ async fn match_request( } => ( Some( serde_json::to_string(&VfsResponse::GetEntry { - exists: true, + is_file: false, children: paths, }) .unwrap(), @@ -1337,7 +1331,7 @@ async fn match_request( ( Some( serde_json::to_string(&VfsResponse::GetEntry { - exists: true, + is_file: true, children: vec![], }) .unwrap(),