From 1e6792d13621dc0610c8d6cfbb25f5d8dedef4e2 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Mon, 28 Oct 2024 14:44:11 -0700 Subject: [PATCH 1/2] no cab frfr --- src/http/client.rs | 40 ++++++++++++++++++++-------------------- src/http/server.rs | 40 ++++++++++++++++++++-------------------- src/lib.rs | 2 +- 3 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/http/client.rs b/src/http/client.rs index 3fc00a4..c257704 100644 --- a/src/http/client.rs +++ b/src/http/client.rs @@ -6,7 +6,7 @@ use std::collections::HashMap; use std::str::FromStr; use thiserror::Error; -/// Request type sent to the `http_client:distro:sys` service in order to open a +/// Request type sent to the `http-client:distro:sys` service in order to open a /// WebSocket connection, send a WebSocket message on an existing connection, or /// send an HTTP request. /// @@ -31,7 +31,7 @@ pub enum HttpClientAction { } /// HTTP Request type that can be shared over Wasm boundary to apps. -/// This is the one you send to the `http_client:distro:sys` service. +/// This is the one you send to the `http-client:distro:sys` service. /// /// BODY is stored in the lazy_load_blob, as bytes /// @@ -48,7 +48,7 @@ pub struct OutgoingHttpRequest { } /// Request that comes from an open WebSocket client connection in the -/// `http_client:distro:sys` service. Be prepared to receive these after +/// `http-client:distro:sys` service. Be prepared to receive these after /// using a [`HttpClientAction::WebSocketOpen`] to open a connection. #[derive(Clone, Copy, Debug, Serialize, Deserialize)] pub enum HttpClientRequest { @@ -61,7 +61,7 @@ pub enum HttpClientRequest { }, } -/// Response type received from the `http_client:distro:sys` service after +/// Response type received from the `http-client:distro:sys` service after /// sending a successful [`HttpClientAction`] to it. #[derive(Debug, Serialize, Deserialize)] pub enum HttpClientResponse { @@ -72,15 +72,15 @@ pub enum HttpClientResponse { #[derive(Error, Debug, Serialize, Deserialize)] pub enum HttpClientError { // HTTP errors - #[error("http_client: request is not valid HttpClientRequest: {req}.")] + #[error("http-client: request is not valid HttpClientRequest: {req}.")] BadRequest { req: String }, - #[error("http_client: http method not supported: {method}.")] + #[error("http-client: http method not supported: {method}.")] BadMethod { method: String }, - #[error("http_client: url could not be parsed: {url}.")] + #[error("http-client: url could not be parsed: {url}.")] BadUrl { url: String }, - #[error("http_client: http version not supported: {version}.")] + #[error("http-client: http version not supported: {version}.")] BadVersion { version: String }, - #[error("http_client: failed to execute request {error}.")] + #[error("http-client: failed to execute request {error}.")] RequestFailed { error: String }, // WebSocket errors @@ -105,7 +105,7 @@ pub fn send_request( timeout: Option, body: Vec, ) { - let req = KiRequest::to(("our", "http_client", "distro", "sys")) + let req = KiRequest::to(("our", "http-client", "distro", "sys")) .body( serde_json::to_vec(&HttpClientAction::Http(OutgoingHttpRequest { method: method.to_string(), @@ -123,7 +123,7 @@ pub fn send_request( } } -/// Make an HTTP request using http_client and await its response. +/// Make an HTTP request using http-client and await its response. /// /// Returns [`Response`] from the `http` crate if successful, with the body type as bytes. pub fn send_request_await_response( @@ -133,7 +133,7 @@ pub fn send_request_await_response( timeout: u64, body: Vec, ) -> std::result::Result>, HttpClientError> { - let res = KiRequest::to(("our", "http_client", "distro", "sys")) + let res = KiRequest::to(("our", "http-client", "distro", "sys")) .body( serde_json::to_vec(&HttpClientAction::Http(OutgoingHttpRequest { method: method.to_string(), @@ -150,7 +150,7 @@ pub fn send_request_await_response( .unwrap(); let Ok(Message::Response { body, .. }) = res else { return Err(HttpClientError::RequestFailed { - error: "http_client timed out".to_string(), + error: "http-client timed out".to_string(), }); }; let resp = match serde_json::from_slice::< @@ -160,13 +160,13 @@ pub fn send_request_await_response( Ok(Ok(HttpClientResponse::Http(resp))) => resp, Ok(Ok(HttpClientResponse::WebSocketAck)) => { return Err(HttpClientError::RequestFailed { - error: "http_client gave unexpected response".to_string(), + error: "http-client gave unexpected response".to_string(), }) } Ok(Err(e)) => return Err(e), Err(e) => { return Err(HttpClientError::RequestFailed { - error: format!("http_client gave invalid response: {e:?}"), + error: format!("http-client gave invalid response: {e:?}"), }) } }; @@ -176,12 +176,12 @@ pub fn send_request_await_response( for (key, value) in &resp.headers { let Ok(key) = http::header::HeaderName::from_str(key) else { return Err(HttpClientError::RequestFailed { - error: format!("http_client gave invalid header key: {key}"), + error: format!("http-client gave invalid header key: {key}"), }); }; let Ok(value) = http::header::HeaderValue::from_str(value) else { return Err(HttpClientError::RequestFailed { - error: format!("http_client gave invalid header value: {value}"), + error: format!("http-client gave invalid header value: {value}"), }); }; headers.insert(key, value); @@ -197,7 +197,7 @@ pub fn open_ws_connection( channel_id: u32, ) -> std::result::Result<(), HttpClientError> { let Ok(Ok(Message::Response { body, .. })) = - KiRequest::to(("our", "http_client", "distro", "sys")) + KiRequest::to(("our", "http-client", "distro", "sys")) .body( serde_json::to_vec(&HttpClientAction::WebSocketOpen { url: url.clone(), @@ -219,7 +219,7 @@ pub fn open_ws_connection( /// Send a WebSocket push message on an open WebSocket channel. pub fn send_ws_client_push(channel_id: u32, message_type: WsMessageType, blob: KiBlob) { - KiRequest::to(("our", "http_client", "distro", "sys")) + KiRequest::to(("our", "http-client", "distro", "sys")) .body( serde_json::to_vec(&HttpClientAction::WebSocketPush { channel_id, @@ -235,7 +235,7 @@ pub fn send_ws_client_push(channel_id: u32, message_type: WsMessageType, blob: K /// Close a WebSocket connection. pub fn close_ws_connection(channel_id: u32) -> std::result::Result<(), HttpClientError> { let Ok(Ok(Message::Response { body, .. })) = - KiRequest::to(("our", "http_client", "distro", "sys")) + KiRequest::to(("our", "http-client", "distro", "sys")) .body( serde_json::json!(HttpClientAction::WebSocketClose { channel_id }) .to_string() diff --git a/src/http/server.rs b/src/http/server.rs index db470f8..caf4d2c 100644 --- a/src/http/server.rs +++ b/src/http/server.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; use std::collections::{HashMap, HashSet}; use thiserror::Error; -/// HTTP Request received from the `http_server:distro:sys` service as a +/// HTTP Request received from the `http-server:distro:sys` service as a /// result of either an HTTP or WebSocket binding, created via [`HttpServerAction`]. #[derive(Clone, Debug, Serialize, Deserialize)] pub enum HttpServerRequest { @@ -144,7 +144,7 @@ pub enum WsMessageType { Close, } -/// Request type sent to `http_server:distro:sys` in order to configure it. +/// Request type sent to `http-server:distro:sys` in order to configure it. /// /// If a response is expected, all actions will return a Response /// with the shape `Result<(), HttpServerActionError>` serialized to JSON. @@ -213,8 +213,8 @@ pub enum HttpServerAction { desired_reply_type: MessageType, }, /// For communicating with the ext. - /// Kinode's http_server sends this to the ext after receiving `WebSocketExtPushOutgoing`. - /// Upon receiving reply with this type from ext, http_server parses, setting: + /// Kinode's http-server sends this to the ext after receiving `WebSocketExtPushOutgoing`. + /// Upon receiving reply with this type from ext, http-server parses, setting: /// * id as given, /// * message type as given (Request or Response), /// * body as HttpServerRequest::WebSocketPush, @@ -268,7 +268,7 @@ impl HttpResponse { } } -/// Part of the Response type issued by http_server +/// Part of the Response type issued by http-server #[derive(Clone, Debug, Error, Serialize, Deserialize)] pub enum HttpServerError { #[error("request could not be parsed to HttpServerAction: {req}.")] @@ -279,11 +279,11 @@ pub enum HttpServerError { PathBindError { error: String }, #[error("WebSocket error: {error}")] WebSocketPushError { error: String }, - /// Not actually issued by `http_server:distro:sys`, just this library + /// Not actually issued by `http-server:distro:sys`, just this library #[error("timeout")] Timeout, - /// Not actually issued by `http_server:distro:sys`, just this library - #[error("unexpected response from http_server")] + /// Not actually issued by `http-server:distro:sys`, just this library + #[error("unexpected response from http-server")] UnexpectedResponse, } @@ -301,7 +301,7 @@ pub struct HttpServer { ws_paths: HashMap, /// A mapping of WebSocket paths to the channels that are open on them. ws_channels: HashMap>, - /// The timeout given for `http_server:distro:sys` to respond to a configuration request. + /// The timeout given for `http-server:distro:sys` to respond to a configuration request. pub timeout: u64, } @@ -485,7 +485,7 @@ impl HttpServer { { let path: String = path.into(); let cache = config.static_content.is_some(); - let req = KiRequest::to(("our", "http_server", "distro", "sys")).body( + let req = KiRequest::to(("our", "http-server", "distro", "sys")).body( serde_json::to_vec(&if config.secure_subdomain { HttpServerAction::SecureBind { path: path.clone(), @@ -529,7 +529,7 @@ impl HttpServer { T: Into, { let path: String = path.into(); - let res = KiRequest::to(("our", "http_server", "distro", "sys")) + let res = KiRequest::to(("our", "http-server", "distro", "sys")) .body(if config.secure_subdomain { serde_json::to_vec(&HttpServerAction::WebSocketSecureBind { path: path.clone(), @@ -573,7 +573,7 @@ impl HttpServer { T: Into, { let path: String = path.into(); - let res = KiRequest::to(("our", "http_server", "distro", "sys")) + let res = KiRequest::to(("our", "http-server", "distro", "sys")) .body( serde_json::to_vec(&HttpServerAction::Bind { path: path.clone(), @@ -624,7 +624,7 @@ impl HttpServer { T: Into, { let path: String = path.into(); - let res = KiRequest::to(("our", "http_server", "distro", "sys")) + let res = KiRequest::to(("our", "http-server", "distro", "sys")) .body( serde_json::to_vec(&HttpServerAction::SecureBind { path: path.clone(), @@ -666,7 +666,7 @@ impl HttpServer { T: Into, { let path: String = path.into(); - let res = KiRequest::to(("our", "http_server", "distro", "sys")) + let res = KiRequest::to(("our", "http-server", "distro", "sys")) .body( serde_json::to_vec(&HttpServerAction::WebSocketSecureBind { path: path.clone(), @@ -711,7 +711,7 @@ impl HttpServer { .ok_or(HttpServerError::PathBindError { error: "path not found".to_string(), })?; - let res = KiRequest::to(("our", "http_server", "distro", "sys")) + let res = KiRequest::to(("our", "http-server", "distro", "sys")) .body( serde_json::to_vec(&HttpServerAction::Bind { path: path.to_string(), @@ -750,7 +750,7 @@ impl HttpServer { .ok_or(HttpServerError::PathBindError { error: "path not found".to_string(), })?; - let res = KiRequest::to(("our", "http_server", "distro", "sys")) + let res = KiRequest::to(("our", "http-server", "distro", "sys")) .body(if entry.secure_subdomain { serde_json::to_vec(&HttpServerAction::WebSocketSecureBind { path: path.to_string(), @@ -790,7 +790,7 @@ impl HttpServer { T: Into, { let path: String = path.into(); - let res = KiRequest::to(("our", "http_server", "distro", "sys")) + let res = KiRequest::to(("our", "http-server", "distro", "sys")) .body(serde_json::to_vec(&HttpServerAction::Unbind { path: path.clone() }).unwrap()) .send_and_await_response(self.timeout) .unwrap(); @@ -812,7 +812,7 @@ impl HttpServer { T: Into, { let path: String = path.into(); - let res = KiRequest::to(("our", "http_server", "distro", "sys")) + let res = KiRequest::to(("our", "http-server", "distro", "sys")) .body( serde_json::to_vec(&HttpServerAction::WebSocketUnbind { path: path.clone() }) .unwrap(), @@ -909,7 +909,7 @@ impl HttpServer { } /// Serve static files from a given directory by binding all of them - /// in http_server to their filesystem path. + /// in http-server to their filesystem path. /// /// The directory is relative to the `pkg` folder within this package's drive. /// @@ -1065,7 +1065,7 @@ pub fn send_response(status: StatusCode, headers: Option /// Send a WebSocket push message on an open WebSocket channel. pub fn send_ws_push(channel_id: u32, message_type: WsMessageType, blob: KiBlob) { - KiRequest::to(("our", "http_server", "distro", "sys")) + KiRequest::to(("our", "http-server", "distro", "sys")) .body( serde_json::to_vec(&HttpServerRequest::WebSocketPush { channel_id, diff --git a/src/lib.rs b/src/lib.rs index cec9056..eb6e319 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,7 +33,7 @@ pub mod homepage; /// Contains types from the `http` crate to use as well. /// /// Your process must have the capability to message and receive messages from -/// `http_server:distro:sys` and/or `http_client:distro:sys` to use this module. +/// `http-server:distro:sys` and/or `http-client:distro:sys` to use this module. pub mod http; /// The types that the kernel itself uses -- warning -- these will /// be incompatible with WIT types in some cases, leading to annoying errors. From 778457ae52c934fd17e0e846127a9472a8e03170 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Mon, 28 Oct 2024 20:09:56 -0700 Subject: [PATCH 2/2] kns_indexer -> kns-indexer --- src/kimap.rs | 8 ++++---- src/net.rs | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/kimap.rs b/src/kimap.rs index 4a58f21..3375710 100644 --- a/src/kimap.rs +++ b/src/kimap.rs @@ -220,7 +220,7 @@ pub mod contract { } /// A mint log from the kimap, converted to a 'resolved' format using -/// namespace data saved in the kns_indexer. +/// namespace data saved in the kns-indexer. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Mint { pub name: String, @@ -228,7 +228,7 @@ pub struct Mint { } /// A note log from the kimap, converted to a 'resolved' format using -/// namespace data saved in the kns_indexer +/// namespace data saved in the kns-indexer #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Note { pub note: String, @@ -237,7 +237,7 @@ pub struct Note { } /// A fact log from the kimap, converted to a 'resolved' format using -/// namespace data saved in the kns_indexer +/// namespace data saved in the kns-indexer #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Fact { pub fact: String, @@ -255,7 +255,7 @@ pub enum DecodeLogError { InvalidName(String), /// An error occurred while decoding the log. DecodeError(String), - /// The parent name could not be resolved with `kns_indexer`. + /// The parent name could not be resolved with `kns-indexer`. UnresolvedParent(String), } diff --git a/src/net.rs b/src/net.rs index b17cdc0..a26575f 100644 --- a/src/net.rs +++ b/src/net.rs @@ -108,7 +108,7 @@ pub enum NetResponse { Verified(bool), } -/// Request performed to `kns_indexer:kns_indexer:sys`, a userspace process +/// Request performed to `kns-indexer:kns-indexer:sys`, a userspace process /// installed by default. /// /// Other requests exist but are only used internally. @@ -131,7 +131,7 @@ pub struct NamehashToNameRequest { pub block: Option, } -/// Response from `kns_indexer:kns_indexer:sys`. +/// Response from `kns-indexer:kns-indexer:sys`. #[derive(Debug, Serialize, Deserialize)] pub enum IndexerResponses { /// Response to [`IndexerRequests::NamehashToName`]. @@ -222,7 +222,7 @@ pub fn get_name(namehash: T, block: Option, timeout: Option) -> Opt where T: Into, { - let res = Request::to(("our", "kns_indexer", "kns_indexer", "sys")) + let res = Request::to(("our", "kns-indexer", "kns-indexer", "sys")) .body( serde_json::to_vec(&IndexerRequests::NamehashToName(NamehashToNameRequest { hash: namehash.into(),