Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::collections::HashMap;
use std::str::FromStr;
use thiserror::Error;

/// [`crate::Request`] type sent to the `http_client:distro:sys` service in order to open a
/// [`crate::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.
///
Expand All @@ -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
///
Expand All @@ -48,7 +48,7 @@ pub struct OutgoingHttpRequest {
}

/// [`crate::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 {
Expand All @@ -61,7 +61,7 @@ pub enum HttpClientRequest {
},
}

/// [`crate::Response`] type received from the `http_client:distro:sys` service after
/// [`crate::Response`] type received from the `http-client:distro:sys` service after
/// sending a successful [`HttpClientAction`] to it.
#[derive(Debug, Serialize, Deserialize)]
pub enum HttpClientResponse {
Expand All @@ -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
Expand All @@ -105,7 +105,7 @@ pub fn send_request(
timeout: Option<u64>,
body: Vec<u8>,
) {
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(),
Expand All @@ -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 HTTP response from the `http` crate if successful, with the body type as bytes.
pub fn send_request_await_response(
Expand All @@ -133,7 +133,7 @@ pub fn send_request_await_response(
timeout: u64,
body: Vec<u8>,
) -> std::result::Result<http::Response<Vec<u8>>, 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(),
Expand All @@ -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::<
Expand All @@ -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:?}"),
})
}
};
Expand All @@ -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);
Expand All @@ -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(),
Expand All @@ -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,
Expand All @@ -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()
Expand Down
40 changes: 20 additions & 20 deletions src/http/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
use thiserror::Error;

/// [`crate::Request`] received from the `http_server:distro:sys` service as a
/// [`crate::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 {
Expand Down Expand Up @@ -145,7 +145,7 @@ pub enum WsMessageType {
Close,
}

/// [`crate::Request`] type sent to `http_server:distro:sys` in order to configure it.
/// [`crate::Request`] type sent to `http-server:distro:sys` in order to configure it.
///
/// If a [`crate::Response`] is expected, all actions will return a [`crate::Response`]
/// with the shape `Result<(), HttpServerActionError>` serialized to JSON.
Expand Down Expand Up @@ -209,8 +209,8 @@ pub enum HttpServerAction {
desired_reply_type: MessageType,
},
/// For communicating with the ext.
/// Kinode's http_server sends this to the ext after receiving [`HttpServerAction::WebSocketExtPushOutgoing`].
/// Upon receiving reply with this type from ext, http_server parses, setting:
/// Kinode's http-server sends this to the ext after receiving [`HttpServerAction::WebSocketExtPushOutgoing`].
/// Upon receiving reply with this type from ext, http-server parses, setting:
/// * id as given,
/// * message type as given ([`crate::Request`] or [`crate::Response`]),
/// * body as [`HttpServerRequest::WebSocketPush`],
Expand Down Expand Up @@ -265,7 +265,7 @@ impl HttpResponse {
}
}

/// Part of the [`crate::Response`] type issued by http_server
/// Part of the [`crate::Response`] type issued by http-server
#[derive(Clone, Debug, Error, Serialize, Deserialize)]
pub enum HttpServerError {
#[error("request could not be parsed to HttpServerAction: {req}.")]
Expand All @@ -276,11 +276,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,
}

Expand All @@ -298,7 +298,7 @@ pub struct HttpServer {
ws_paths: HashMap<String, WsBindingConfig>,
/// A mapping of WebSocket paths to the channels that are open on them.
ws_channels: HashMap<String, HashSet<u32>>,
/// 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,
}

Expand Down Expand Up @@ -471,7 +471,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(),
Expand Down Expand Up @@ -515,7 +515,7 @@ impl HttpServer {
T: Into<String>,
{
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(),
Expand Down Expand Up @@ -557,7 +557,7 @@ impl HttpServer {
T: Into<String>,
{
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(),
Expand Down Expand Up @@ -608,7 +608,7 @@ impl HttpServer {
T: Into<String>,
{
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(),
Expand Down Expand Up @@ -650,7 +650,7 @@ impl HttpServer {
T: Into<String>,
{
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(),
Expand Down Expand Up @@ -693,7 +693,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(),
Expand Down Expand Up @@ -732,7 +732,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(),
Expand Down Expand Up @@ -770,7 +770,7 @@ impl HttpServer {
T: Into<String>,
{
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();
Expand All @@ -792,7 +792,7 @@ impl HttpServer {
T: Into<String>,
{
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(),
Expand Down Expand Up @@ -889,7 +889,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.
///
Expand Down Expand Up @@ -1045,7 +1045,7 @@ pub fn send_response(status: StatusCode, headers: Option<HashMap<String, String>

/// 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,
Expand Down
8 changes: 4 additions & 4 deletions src/kimap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,15 @@ 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,
pub parent_path: String,
}

/// 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,
Expand All @@ -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,
Expand All @@ -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),
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -131,7 +131,7 @@ pub struct NamehashToNameRequest {
pub block: Option<u64>,
}

/// 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`].
Expand Down Expand Up @@ -222,7 +222,7 @@ pub fn get_name<T>(namehash: T, block: Option<u64>, timeout: Option<u64>) -> Opt
where
T: Into<String>,
{
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(),
Expand Down
Loading