1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//! What `rho daemon start --json` prints (#1997): the daemon it reached, or
//! the refusal of one that speaks another protocol version. A client that
//! starts a daemon on another machine before it connects, as rho-ui's setup
//! script does over ssh, reads the refusal here, where its own handshake
//! never gets to, to offer the restart the refusal describes.
use rho_protocol::VersionMismatch;
use serde::Serialize;
use super::daemon_cli::Unreachable;
use crate::daemon::Connection;
/// The one JSON object `rho daemon start --json` prints. Clients such as
/// rho-ui parse it, so keep its field names stable.
#[derive(Debug, Serialize)]
#[serde(tag = "outcome", rename_all = "snake_case")]
pub(super) enum StartReport {
/// A daemon runs and answered: one that already did, or one this
/// started.
Running { pid: u32, version: String },
/// The daemon's protocol version and this rho's are incompatible, and
/// the daemon was left running: one newer than this rho, or an older
/// one someone uses. `mismatch` is the refusal's data as this rho read
/// it from `rho/hello`: a field a newer daemon added is left out.
Refused { mismatch: VersionMismatch },
}
impl StartReport {
/// The report of what `rho daemon start` reached, or `None` when it
/// failed some other way, which only its error says.
pub(super) fn of(connected: &Result<Connection, Unreachable>) -> Option<Self> {
match connected {
Ok(connection) => Some(Self::Running {
pid: connection.hello.daemon.pid,
version: connection.hello.daemon.version.clone(),
}),
Err(unreachable) => unreachable
.mismatch()
.map(|mismatch| Self::Refused { mismatch }),
}
}
}
#[cfg(test)]
#[path = "daemon_start_report_tests.rs"]
mod tests;