Skip to main content

spoolframe_protocol/
experimental.rs

1//! Experimental features (PX-49): 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 PX-16's 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 (P8): 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/// The most feature names a server keeps of a `Hello`; the rest are
33/// dropped, as each name is cut to `MAX_HELLO_TEXT` characters (PX-10).
34pub const MAX_ASKED: usize = 16;
35
36/// The features of `asked` that are among `on`, each once, in `asked`'s
37/// order: what a server's answer names. A name not among `on` is ignored.
38pub fn turned_on(asked: &[String], on: &[&str]) -> Vec<String> {
39    let mut turned: Vec<String> = Vec::new();
40    for name in asked {
41        if on.contains(&name.as_str()) && !turned.contains(name) {
42            turned.push(name.clone());
43        }
44    }
45    turned
46}
47
48/// Why the server gives no HTTP URL for a playback (`http-playback`).
49#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
50#[serde(rename_all = "snake_case")]
51pub enum HttpPlaybackRefusal {
52    /// The feature is not on for this connection: the server's HTTP
53    /// playback port is off, or the client's `Hello` did not name it.
54    Off,
55    /// The client reached the server through a relay, or over the
56    /// Internet, and the server names no address for that
57    /// (`http_playback.address`): there is no address on the client's
58    /// network to give.
59    RelayOnly,
60    /// No playback of this session's has that handle: it ended, or is
61    /// another's.
62    NoSuchPlayback,
63    /// The playback is planned as something the HTTP side does not serve:
64    /// a conversion read as one growing file rather than HLS.
65    Unsupported,
66    /// The port listens on no address of the family the client's network
67    /// reaches the server by: an IPv4 port and an IPv6 client on an
68    /// interface, and a host, with no IPv4 address on the LAN, or the
69    /// reverse with an IPv6-only port.
70    NoAddress,
71    /// A reason this build does not know.
72    #[serde(other)]
73    Unknown,
74}