aboutsummaryrefslogtreecommitdiff
path: root/src/client/endpoint/control.rs
diff options
context:
space:
mode:
authorCan Celik <ogulcancelik@gmail.com>2026-09-06 02:27:06 +0300
committerGitHub <noreply@github.com>2026-09-06 02:27:06 +0300
commit9e9bc8a144667a6b7debfd4f0c7a31ff0e11493a (patch)
tree03f1259f91fd9edeacfd4b904f2e84d4acf25232 /src/client/endpoint/control.rs
parent35b0dff96579f099e0436290085024424ffb289c (diff)
feat: manage multiple ssh machines from one client (#3670)
Diffstat (limited to 'src/client/endpoint/control.rs')
-rw-r--r--src/client/endpoint/control.rs63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/client/endpoint/control.rs b/src/client/endpoint/control.rs
new file mode 100644
index 00000000..7cf1159f
--- /dev/null
+++ b/src/client/endpoint/control.rs
@@ -0,0 +1,63 @@
+use super::ClientEndpointId;
+
+pub(crate) enum EndpointControlMessage {
+ HealthPong,
+ Snapshot(Box<crate::protocol::ClientShellSnapshot>),
+ Ignored,
+}
+
+pub(crate) fn decode_endpoint_control(
+ kind: &str,
+ data: &str,
+) -> Result<EndpointControlMessage, String> {
+ if kind == crate::protocol::endpoint::HEALTH_PONG_KIND {
+ return Ok(EndpointControlMessage::HealthPong);
+ }
+ if kind == crate::protocol::endpoint::ENDPOINT_SNAPSHOT_KIND {
+ let snapshot = serde_json::from_str(data)
+ .map_err(|error| format!("invalid endpoint snapshot: {error}"))?;
+ return Ok(EndpointControlMessage::Snapshot(Box::new(snapshot)));
+ }
+ if kind.starts_with("shell.snapshot.") {
+ return Err(format!(
+ "unsupported mandatory endpoint snapshot codec {kind:?}"
+ ));
+ }
+ Ok(EndpointControlMessage::Ignored)
+}
+
+pub(crate) fn protocol_failure_is_fatal(endpoint_id: &ClientEndpointId) -> bool {
+ endpoint_id.is_local()
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::client::endpoint::ProfileId;
+
+ #[test]
+ fn unknown_optional_controls_are_ignored() {
+ assert!(matches!(
+ decode_endpoint_control("future.optional", "not json").unwrap(),
+ EndpointControlMessage::Ignored
+ ));
+ }
+
+ #[test]
+ fn unknown_snapshot_codecs_are_rejected() {
+ assert_eq!(
+ decode_endpoint_control("shell.snapshot.v2", "{}")
+ .err()
+ .as_deref(),
+ Some("unsupported mandatory endpoint snapshot codec \"shell.snapshot.v2\"")
+ );
+ }
+
+ #[test]
+ fn only_local_protocol_failures_end_the_client() {
+ let remote =
+ ClientEndpointId::Ssh(ProfileId::parse("0123456789abcdef0123456789abcdef").unwrap());
+ assert!(protocol_failure_is_fatal(&ClientEndpointId::Local));
+ assert!(!protocol_failure_is_fatal(&remote));
+ }
+}