spoolframe_protocol/experimental.rs
1//! Experimental features: messages a client and server use only
2//! when both said so in `Hello`.
3//!
4//! A client names the features it wants in [`Hello::experimental`]; the
5//! server's answer, [`ServerInfo::experimental`], names those it turned on
6//! for the connection: the ones it knows and has on. Neither side assumes
7//! a feature the other did not name, and a name either does not know is
8//! ignored, never an error. An older server ignores the field, and its
9//! answer names none.
10//!
11//! An experimental feature's messages are outside the protocol's
12//! stability: they may change or go away without [`PROTOCOL_VERSION`]
13//! moving, and protocol version 1 does not promise them. One graduates by
14//! becoming an ordinary message of a protocol version, and its name goes.
15//!
16//! [`Hello::experimental`]: crate::Hello::experimental
17//! [`ServerInfo::experimental`]: crate::ServerInfo::experimental
18//! [`PROTOCOL_VERSION`]: crate::PROTOCOL_VERSION
19
20use serde::{Deserialize, Serialize};
21
22/// A playback's HLS over plain HTTP, from the server's own port, for a
23/// player with no Iroh (AirPlay first): `Request::HttpPlaybackUrl`.
24pub const HTTP_PLAYBACK: &str = "http-playback";
25
26/// Server-to-server federation: the client protocol's `PairServer`
27/// and a `federation` invite. The server's own side, the
28/// `spoolframe/federation/1` ALPN ([`crate::federation`]), is open only
29/// while its `experimental.federation` is on.
30pub const FEDERATION: &str = "federation";
31
32/// Faces in backdrops, so that a wide hero's crop keeps the heads: an
33/// artwork reply's `faces`, left out for a connection without the feature.
34/// On while the server's `experimental.smart_crop` is.
35pub const SMART_CROP: &str = "smart-crop";
36
37/// The most feature names a server keeps of a `Hello`; the rest are
38/// dropped, as each name is cut to `MAX_HELLO_TEXT` characters.
39pub const MAX_ASKED: usize = 16;
40
41/// The features of `asked` that are among `on`, each once, in `asked`'s
42/// order: what a server's answer names. A name not among `on` is ignored.
43pub fn turned_on(asked: &[String], on: &[&str]) -> Vec<String> {
44 let mut turned: Vec<String> = Vec::new();
45 for name in asked {
46 if on.contains(&name.as_str()) && !turned.contains(name) {
47 turned.push(name.clone());
48 }
49 }
50 turned
51}
52
53/// Why the server gives no HTTP URL for a playback (`http-playback`).
54#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
55#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
56#[serde(rename_all = "snake_case")]
57pub enum HttpPlaybackRefusal {
58 /// The feature is not on for this connection: the server's HTTP
59 /// playback port is off, or the client's `Hello` did not name it.
60 Off,
61 /// The client reached the server through a relay, or over the
62 /// Internet, and the server names no address for that
63 /// (`http_playback.address`): there is no address on the client's
64 /// network to give.
65 RelayOnly,
66 /// No playback of this session's has that handle: it ended, or is
67 /// another's.
68 NoSuchPlayback,
69 /// The playback is planned as something the HTTP side does not serve:
70 /// a conversion read as one growing file rather than HLS.
71 Unsupported,
72 /// The port listens on no address of the family the client's network
73 /// reaches the server by: an IPv4 port and an IPv6 client on an
74 /// interface, and a host, with no IPv4 address on the LAN, or the
75 /// reverse with an IPv6-only port.
76 NoAddress,
77 /// A reason this build does not know.
78 #[serde(other)]
79 Unknown,
80}