allow listening on multiple ports in config

This is a config compatibility break.

The ability to listen on multiple ports, including both TLS and non-TLS,
is necessary for running complement against grapevine.
This commit is contained in:
Benjamin Lee 2024-06-07 19:49:59 -07:00
parent b7ad00ef6e
commit f7d7952f9b
No known key found for this signature in database
GPG key ID: FB9624E2885D55A4
4 changed files with 99 additions and 45 deletions

View file

@ -25,10 +25,8 @@ pub(crate) static DEFAULT_PATH: Lazy<PathBuf> =
pub(crate) struct Config {
#[serde(default = "false_fn")]
pub(crate) conduit_compat: bool,
#[serde(default = "default_address")]
pub(crate) address: IpAddr,
#[serde(default = "default_port")]
pub(crate) port: u16,
#[serde(default = "default_listen")]
pub(crate) listen: Vec<ListenConfig>,
pub(crate) tls: Option<TlsConfig>,
pub(crate) server_name: OwnedServerName,
@ -98,6 +96,19 @@ pub(crate) struct TlsConfig {
pub(crate) key: String,
}
#[derive(Debug, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub(crate) enum ListenConfig {
Tcp {
#[serde(default = "default_address")]
address: IpAddr,
#[serde(default = "default_port")]
port: u16,
#[serde(default = "false_fn")]
tls: bool,
},
}
fn false_fn() -> bool {
false
}
@ -106,6 +117,14 @@ fn true_fn() -> bool {
true
}
fn default_listen() -> Vec<ListenConfig> {
vec![ListenConfig::Tcp {
address: default_address(),
port: default_port(),
tls: false,
}]
}
fn default_address() -> IpAddr {
Ipv4Addr::LOCALHOST.into()
}