diff --git a/src/server/client.rs b/src/server/client.rs index 7d47eca24..25dfb1167 100644 --- a/src/server/client.rs +++ b/src/server/client.rs @@ -631,4 +631,5 @@ impl Client { rpc!(resize, Resize, UnitResponse); rpc!(get_tab_render_changes, GetTabRenderChanges, UnitResponse); rpc!(get_lines, GetLines, GetLinesResponse); + rpc!(get_codec_version, GetCodecVersion, GetCodecVersionResponse); } diff --git a/src/server/codec.rs b/src/server/codec.rs index 35c0a445f..67be7bf30 100644 --- a/src/server/codec.rs +++ b/src/server/codec.rs @@ -234,6 +234,11 @@ macro_rules! pdu { } } +/// The overall version of the codec. +/// This must be bumped when backwards incompatible changes +/// are made to the types and protocol. +pub const CODEC_VERSION: usize = 1; + // Defines the Pdu enum. // Each struct has an explicit identifying number. // This allows removal of obsolete structs, @@ -257,6 +262,8 @@ pdu! { GetLinesResponse: 23, GetTabRenderChanges: 24, GetTabRenderChangesResponse: 25, + GetCodecVersion: 26, + GetCodecVersionResponse: 27, } impl Pdu { @@ -341,6 +348,15 @@ pub struct ErrorResponse { pub reason: String, } +#[derive(Deserialize, Serialize, PartialEq, Debug)] +pub struct GetCodecVersion {} + +#[derive(Deserialize, Serialize, PartialEq, Debug)] +pub struct GetCodecVersionResponse { + pub codec_vers: usize, + pub version_string: String, +} + #[derive(Deserialize, Serialize, PartialEq, Debug)] pub struct Ping {} #[derive(Deserialize, Serialize, PartialEq, Debug)] diff --git a/src/server/domain.rs b/src/server/domain.rs index e7776c357..ad9219d66 100644 --- a/src/server/domain.rs +++ b/src/server/domain.rs @@ -6,7 +6,7 @@ use crate::mux::tab::{Tab, TabId}; use crate::mux::window::WindowId; use crate::mux::Mux; use crate::server::client::Client; -use crate::server::codec::Spawn; +use crate::server::codec::{GetCodecVersion, Spawn, CODEC_VERSION}; use crate::server::tab::ClientTab; use anyhow::{anyhow, bail}; use portable_pty::{CommandBuilder, PtySize}; @@ -264,6 +264,38 @@ impl Domain for ClientDomain { match client { Err(err) => promise.result(Err(err)), Ok(client) => { + match client.get_codec_version(GetCodecVersion {}).wait() { + Ok(info) if info.codec_vers == CODEC_VERSION => log::info!( + "Server version is {} (codec version {})", + info.version_string, + info.codec_vers + ), + Ok(info) => { + promise.result(Err(anyhow!( + "Please install the same version of wezterm on both \ + the client and server! \ + The server verson is {} (codec version {}), which is not \ + compatible with our version {} (codec version {}).", + info.version_string, + info.codec_vers, + crate::wezterm_version(), + CODEC_VERSION + ))); + return; + } + Err(err) => { + promise.result(Err(anyhow!( + "Please install the same version of wezterm on both \ + the client and server! \ + The server reported error {} while being asked for its \ + version. This likely means that the server is older \ + than the client.", + err + ))); + return; + } + }; + Future::with_executor(executor(), move || { promise.result(ClientDomain::finish_attach(domain_id, client)); drop(activity); diff --git a/src/server/listener.rs b/src/server/listener.rs index 777d5c1b2..5c68acbce 100644 --- a/src/server/listener.rs +++ b/src/server/listener.rs @@ -816,6 +816,13 @@ impl ClientSession { }) } + Pdu::GetCodecVersion(_) => { + Future::ok(Pdu::GetCodecVersionResponse(GetCodecVersionResponse { + codec_vers: CODEC_VERSION, + version_string: crate::wezterm_version().to_owned(), + })) + } + Pdu::Invalid { .. } => Future::err(anyhow!("invalid PDU {:?}", pdu)), Pdu::Pong { .. } | Pdu::ListTabsResponse { .. } @@ -824,6 +831,7 @@ impl ClientSession { | Pdu::GetTabRenderChangesResponse { .. } | Pdu::UnitResponse { .. } | Pdu::GetLinesResponse { .. } + | Pdu::GetCodecVersionResponse { .. } | Pdu::ErrorResponse { .. } => { Future::err(anyhow!("expected a request, got {:?}", pdu)) }