mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-18 00:01:24 +01:00
Allow configuring served components per listener
This commit is contained in:
parent
d62d0e2f0e
commit
084d862e51
3 changed files with 89 additions and 27 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use std::{
|
||||
borrow::Cow,
|
||||
collections::BTreeMap,
|
||||
collections::{BTreeMap, HashSet},
|
||||
fmt::{self, Display},
|
||||
net::{IpAddr, Ipv4Addr},
|
||||
path::{Path, PathBuf},
|
||||
|
|
@ -13,6 +13,7 @@ use ruma::{
|
|||
OwnedServerSigningKeyId, RoomVersionId,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use strum::{Display, EnumIter, IntoEnumIterator};
|
||||
|
||||
use crate::error;
|
||||
|
||||
|
|
@ -108,9 +109,27 @@ pub(crate) struct TlsConfig {
|
|||
pub(crate) key: String,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Clone, Copy, PartialEq, Eq, Hash, Deserialize, EnumIter, Display,
|
||||
)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
pub(crate) enum ListenComponent {
|
||||
Client,
|
||||
Federation,
|
||||
Metrics,
|
||||
WellKnown,
|
||||
}
|
||||
|
||||
impl ListenComponent {
|
||||
fn all_components() -> HashSet<Self> {
|
||||
Self::iter().collect()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
#[serde(tag = "type", rename_all = "snake_case")]
|
||||
pub(crate) enum ListenConfig {
|
||||
pub(crate) enum ListenTransport {
|
||||
Tcp {
|
||||
#[serde(default = "default_address")]
|
||||
address: IpAddr,
|
||||
|
|
@ -121,15 +140,15 @@ pub(crate) enum ListenConfig {
|
|||
},
|
||||
}
|
||||
|
||||
impl Display for ListenConfig {
|
||||
impl Display for ListenTransport {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
ListenConfig::Tcp {
|
||||
ListenTransport::Tcp {
|
||||
address,
|
||||
port,
|
||||
tls: false,
|
||||
} => write!(f, "http://{address}:{port}"),
|
||||
ListenConfig::Tcp {
|
||||
ListenTransport::Tcp {
|
||||
address,
|
||||
port,
|
||||
tls: true,
|
||||
|
|
@ -138,6 +157,29 @@ impl Display for ListenConfig {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
pub(crate) struct ListenConfig {
|
||||
#[serde(default = "ListenComponent::all_components")]
|
||||
pub(crate) components: HashSet<ListenComponent>,
|
||||
#[serde(flatten)]
|
||||
pub(crate) transport: ListenTransport,
|
||||
}
|
||||
|
||||
impl Display for ListenConfig {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{} ({})",
|
||||
self.transport,
|
||||
self.components
|
||||
.iter()
|
||||
.map(ListenComponent::to_string)
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Default, Debug, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub(crate) enum LogFormat {
|
||||
|
|
@ -315,10 +357,13 @@ fn true_fn() -> bool {
|
|||
}
|
||||
|
||||
fn default_listen() -> Vec<ListenConfig> {
|
||||
vec![ListenConfig::Tcp {
|
||||
address: default_address(),
|
||||
port: default_port(),
|
||||
tls: false,
|
||||
vec![ListenConfig {
|
||||
components: ListenComponent::all_components(),
|
||||
transport: ListenTransport::Tcp {
|
||||
address: default_address(),
|
||||
port: default_port(),
|
||||
tls: false,
|
||||
},
|
||||
}]
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue