//! What a device holds beside the database it is in, and how a copy leaves //! it: the held replicas on disk ([`held`]), a leave, an erase and a copy out //! of scope ([`leave`]), the thirty-day Bin ([`bin`]) — and the two halves of //! the flavor rule the signed transport asks of an origin before it signs //! anything there (`SignedHttp::confirm_app`): the relay name an origin //! reaches ([`address`]) and which app its `/health` says it is //! ([`server_flavor_of`]). pub mod address; /// What else this device holds on disk. pub mod held; pub mod leave; pub use address::{origin_refusal, relay_name_reached}; pub use held::{held_workspaces, HeldWorkspace}; pub use leave::{erase_device, leave_server, Erased, Left}; /// What a `/health` ANSWER says about which app the server is: `Ok(None)` for /// a server that answered and said nothing (the frozen real one), and `Err` /// for one that did not answer at all — a relay's `502` while the Mac behind /// it is asleep is not a server saying it is CottonDB, and reading it as one /// would tell a person the wrong thing about their own household. pub fn server_flavor_of( health: &crate::transport::ClientAnswer, ) -> Result, crate::transport::ServerRefusal> { if !(200..300).contains(&health.status) { return Err(crate::transport::ServerRefusal::new( cotton_core::rules::sync_state::silence_words("The Mac"), health.status, )); } Ok(declared_flavor(&health.body)) } /// The `flavor` a `/health` body declares, or `None` when it says none — an /// older server, which is the frozen real one, or a body that is not JSON. pub fn declared_flavor(body: &[u8]) -> Option { let value: serde_json::Value = serde_json::from_slice(body).ok()?; value.get("flavor")?.as_str().map(str::to_string) } #[cfg(test)] #[path = "join_tests.rs"] mod tests; /// The shared purge path for expired database copies. pub mod bin;