Skip to content

Commit 7cc27de

Browse files
committed
misc: improve error message when remote uses the old protocol
1 parent abac087 commit 7cc27de

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/client/control.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use tracing::{debug, trace, warn};
1717
use crate::protocol::common::ProtocolMessage as _;
1818
use crate::protocol::control::{
1919
ClientMessage, ClosedownReport, ClosedownReportV1, CompatibilityLevel, ConnectionType,
20-
ServerMessage, ServerMessageV1, BANNER,
20+
ServerMessage, ServerMessageV1, BANNER, OLD_BANNER,
2121
};
2222
use crate::{config::Configuration, util::Credentials};
2323

@@ -226,7 +226,16 @@ impl Channel {
226226
.with_context(|| "error reading control channel")?;
227227

228228
let read_banner = std::str::from_utf8(&buf).with_context(|| "garbage server banner")?;
229-
anyhow::ensure!(BANNER == read_banner, "incompatible server banner");
229+
match read_banner {
230+
BANNER => (),
231+
OLD_BANNER => {
232+
anyhow::bail!("unsupported protocol version (upgrade server to qcp 0.3.0 or later)")
233+
}
234+
b => anyhow::bail!(
235+
"unsupported protocol version (unrecognised server banner `{}'; may be too new for me?)",
236+
&b[0..b.len()-1]
237+
),
238+
}
230239
Ok(())
231240
}
232241

src/protocol/control.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ use super::common::ProtocolMessage;
3636
/// Server banner message, sent on stdout and checked by the client
3737
pub const BANNER: &str = "qcp-server-2\n";
3838

39+
/// The banner for the initial protocol version (pre-v0.3) that we don't support any more.
40+
/// Note that it is the same size as the current [`BANNER`].
41+
pub const OLD_BANNER: &str = "qcp-server-1\n";
42+
3943
/// Protocol sub-version compatibility identifier
4044
///
4145
/// This forms part of the negotiation between client and server.

0 commit comments

Comments
 (0)