Skip to main content

hyperlane_core/config/
struct.rs

1use super::*;
2
3/// TLS material a server needs to terminate a connection.
4///
5/// The certificate and key are stored as filesystem paths and only read when a
6/// listener is created, so a configuration can be deserialized, compared and
7/// cloned without touching the disk.
8///
9/// The two path fields are part of the public surface: `TlsConfig::new` is the
10/// documented constructor and applications read back what they configured.
11#[derive(Clone, CustomDebug, Data, Deserialize, DisplayDebug, Eq, New, PartialEq, Serialize)]
12pub struct TlsConfig {
13    /// Path to the PEM encoded certificate chain presented to clients.
14    pub certificate_path: String,
15    /// Path to the PEM encoded private key matching the leaf certificate.
16    pub private_key_path: String,
17}
18
19/// Represents the server configuration.
20///
21/// This structure holds all the settings for the HTTP and WebSocket server,
22/// including network parameters and buffer sizes.
23#[derive(Clone, CustomDebug, Data, Deserialize, DisplayDebug, Eq, New, PartialEq, Serialize)]
24pub struct ServerConfig {
25    /// The address the server will bind to.
26    #[set(type(AsRef<str>))]
27    pub address: String,
28    /// The `TCP_NODELAY` option for sockets.
29    #[get(type(copy))]
30    pub nodelay: Option<bool>,
31    /// The `IP_TTL` option for sockets.
32    #[get(type(copy))]
33    pub ttl: Option<u32>,
34    /// The wire protocol the listener speaks, defaulting to HTTP/1.
35    ///
36    /// Skipped by `new` so the three argument constructor keeps its signature;
37    /// a configuration built that way speaks HTTP/1 until a setter changes it.
38    #[get(type(copy))]
39    #[new(skip)]
40    #[serde(default)]
41    pub protocol: ServerProtocol,
42    /// TLS material used to terminate connections, or `None` for plaintext.
43    ///
44    /// Skipped by `new` for the same reason as `protocol`; the setters take an
45    /// `Option`, so `set_tls(None)` restores plaintext without a separate call.
46    #[get(type(clone))]
47    #[new(skip)]
48    #[serde(default)]
49    pub tls: Option<TlsConfig>,
50}