Skip to content

Commit 6d3e977

Browse files
authored
Merge pull request #102 from kinode-dao/develop
Develop 0.9.4
2 parents db9753a + 4489de7 commit 6d3e977

File tree

6 files changed

+49
-17
lines changed

6 files changed

+49
-17
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "kinode_process_lib"
33
description = "A library for writing Kinode processes in Rust."
4-
version = "0.9.3"
4+
version = "0.9.4"
55
edition = "2021"
66
license-file = "LICENSE"
77
homepage = "https://kinode.org"

src/http/server.rs

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,10 @@ impl HttpBindingConfig {
403403
/// not use the WebSocket extension protocol to connect with a runtime extension.
404404
#[derive(Clone, Copy, Debug)]
405405
pub struct WsBindingConfig {
406-
pub authenticated: bool,
407-
pub encrypted: bool,
408-
pub extension: bool,
406+
authenticated: bool,
407+
secure_subdomain: bool,
408+
encrypted: bool,
409+
extension: bool,
409410
}
410411

411412
impl WsBindingConfig {
@@ -415,15 +416,22 @@ impl WsBindingConfig {
415416
pub fn default() -> Self {
416417
Self {
417418
authenticated: true,
419+
secure_subdomain: false,
418420
encrypted: false,
419421
extension: false,
420422
}
421423
}
422424

423425
/// Create a new WsBindingConfig with the given values.
424-
pub fn new(authenticated: bool, encrypted: bool, extension: bool) -> Self {
426+
pub fn new(
427+
authenticated: bool,
428+
secure_subdomain: bool,
429+
encrypted: bool,
430+
extension: bool,
431+
) -> Self {
425432
Self {
426433
authenticated,
434+
secure_subdomain,
427435
encrypted,
428436
extension,
429437
}
@@ -435,6 +443,12 @@ impl WsBindingConfig {
435443
self
436444
}
437445

446+
/// Set whether the WebSocket server will be bound on a secure subdomain.
447+
pub fn secure_subdomain(mut self, secure_subdomain: bool) -> Self {
448+
self.secure_subdomain = secure_subdomain;
449+
self
450+
}
451+
438452
/// Set whether the WebSocket server will apply a custom encryption to the WebSocket
439453
/// connection using the login cookie.
440454
pub fn encrypted(mut self, encrypted: bool) -> Self {
@@ -516,22 +530,32 @@ impl HttpServer {
516530
{
517531
let path: String = path.into();
518532
let res = KiRequest::to(("our", "http_server", "distro", "sys"))
519-
.body(
533+
.body(if config.secure_subdomain {
534+
serde_json::to_vec(&HttpServerAction::WebSocketSecureBind {
535+
path: path.clone(),
536+
encrypted: config.encrypted,
537+
extension: config.extension,
538+
})
539+
.unwrap()
540+
} else {
520541
serde_json::to_vec(&HttpServerAction::WebSocketBind {
521542
path: path.clone(),
522543
authenticated: config.authenticated,
523544
encrypted: config.encrypted,
524545
extension: config.extension,
525546
})
526-
.unwrap(),
527-
)
547+
.unwrap()
548+
})
528549
.send_and_await_response(self.timeout);
529550
let Ok(Message::Response { body, .. }) = res.unwrap() else {
530551
return Err(HttpServerError::Timeout);
531552
};
532553
let Ok(resp) = serde_json::from_slice::<Result<(), HttpServerError>>(&body) else {
533554
return Err(HttpServerError::UnexpectedResponse);
534555
};
556+
if resp.is_ok() {
557+
self.ws_paths.insert(path, config);
558+
}
535559
resp
536560
}
537561

@@ -644,9 +668,8 @@ impl HttpServer {
644668
let path: String = path.into();
645669
let res = KiRequest::to(("our", "http_server", "distro", "sys"))
646670
.body(
647-
serde_json::to_vec(&HttpServerAction::WebSocketBind {
671+
serde_json::to_vec(&HttpServerAction::WebSocketSecureBind {
648672
path: path.clone(),
649-
authenticated: true,
650673
encrypted: false,
651674
extension: false,
652675
})
@@ -664,6 +687,7 @@ impl HttpServer {
664687
path,
665688
WsBindingConfig {
666689
authenticated: true,
690+
secure_subdomain: true,
667691
encrypted: false,
668692
extension: false,
669693
},
@@ -727,15 +751,22 @@ impl HttpServer {
727751
error: "path not found".to_string(),
728752
})?;
729753
let res = KiRequest::to(("our", "http_server", "distro", "sys"))
730-
.body(
754+
.body(if entry.secure_subdomain {
755+
serde_json::to_vec(&HttpServerAction::WebSocketSecureBind {
756+
path: path.to_string(),
757+
encrypted: config.encrypted,
758+
extension: config.extension,
759+
})
760+
.unwrap()
761+
} else {
731762
serde_json::to_vec(&HttpServerAction::WebSocketBind {
732763
path: path.to_string(),
733764
authenticated: config.authenticated,
734765
encrypted: config.encrypted,
735766
extension: config.extension,
736767
})
737-
.unwrap(),
738-
)
768+
.unwrap()
769+
})
739770
.send_and_await_response(self.timeout)
740771
.unwrap();
741772
let Ok(Message::Response { body, .. }) = res else {
@@ -746,6 +777,7 @@ impl HttpServer {
746777
};
747778
if resp.is_ok() {
748779
entry.authenticated = config.authenticated;
780+
entry.secure_subdomain = config.secure_subdomain;
749781
entry.encrypted = config.encrypted;
750782
entry.extension = config.extension;
751783
}

src/types/capability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::hash::{Hash, Hasher};
99
/// that capability with the receiving process, or to prove that a process has
1010
/// authority to perform a certain action.
1111
impl Capability {
12-
/// Create a new `Capability`. Takes a node ID and a process ID.
12+
/// Create a new [`Capability`]. Takes an [`Address`] and a parameter, which is a JSON string.
1313
pub fn new<T, U>(address: T, params: U) -> Capability
1414
where
1515
T: Into<Address>,

src/types/request.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl Request {
118118
self.body = Some(body.try_into()?);
119119
Ok(self)
120120
}
121-
/// Set the metdata field for this request. Metadata is simply a [`String`].
121+
/// Set the metadata field for this request. Metadata is simply a [`String`].
122122
/// Metadata should usually be used for middleware and other message-passing
123123
/// situations that require the original IPC body and blob to be preserved.
124124
/// As such, metadata should not always be expected to reach the final destination

src/types/response.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl Response {
6060
self.body = Some(body.try_into()?);
6161
Ok(self)
6262
}
63-
/// Set the metdata field for this response. Metadata is simply a [`String`].
63+
/// Set the metadata field for this response. Metadata is simply a [`String`].
6464
/// Metadata should usually be used for middleware and other message-passing
6565
/// situations that require the original IPC body and blob to be preserved.
6666
/// As such, metadata should not always be expected to reach the final destination

0 commit comments

Comments
 (0)