mux: add basic version handshake at domain connect time

This commit is contained in:
Wez Furlong committed 2020-01-13 08:10:23 -08:00
1 parent ac32ae19d8
commit c989485a77
4 files changed
+58 -1

No files matched your search

+1
View File
@@ -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);
}
+16
View File
@@ -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)]
+33 -1
View File
@@ -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);
+8
View File
@@ -816,6 +816,13 @@ impl<S: ReadAndWrite> ClientSession<S> {
})
}
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<S: ReadAndWrite> ClientSession<S> {
| Pdu::GetTabRenderChangesResponse { .. }
| Pdu::UnitResponse { .. }
| Pdu::GetLinesResponse { .. }
| Pdu::GetCodecVersionResponse { .. }
| Pdu::ErrorResponse { .. } => {
Future::err(anyhow!("expected a request, got {:?}", pdu))
}