use indexmap::IndexSet;
use super::*;
#[viewit::viewit(getters(vis_all = "pub"), setters(vis_all = "pub", prefix = "with"))]
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
feature = "serde",
serde(bound(
serialize = "I: serde::Serialize, A: AddressResolver, A::Address: serde::Serialize, A::ResolvedAddress: serde::Serialize",
deserialize = "I: for<'a> serde::Deserialize<'a>, A: AddressResolver, A::Address: for<'a> serde::Deserialize<'a>, A::ResolvedAddress: for<'a> serde::Deserialize<'a>"
))
)]
pub struct QuicTransportOptions<I, A: AddressResolver<ResolvedAddress = SocketAddr>> {
#[viewit(
getter(const, style = "ref", attrs(doc = "Get the id of the node."),),
setter(attrs(doc = "Set the id of the node. (Builder pattern)"),)
)]
id: I,
#[viewit(
getter(
style = "ref",
const,
attrs(doc = "Get a list of addresses to bind to for QUIC communications."),
),
setter(attrs(
doc = "Set the list of addresses to bind to for QUIC communications. (Builder pattern)"
),)
)]
bind_addresses: IndexSet<A::Address>,
#[viewit(
getter(const, style = "ref", attrs(doc = "Get the label of the node."),),
setter(attrs(doc = "Set the label of the node. (Builder pattern)"),)
)]
label: Label,
#[viewit(
getter(
const,
attrs(
doc = "Get if the check that inbound packets and gossip streams need to be label prefixed."
),
),
setter(attrs(
doc = "Set if the check that inbound packets and gossip streams need to be label prefixed. (Builder pattern)"
),)
)]
skip_inbound_label_check: bool,
#[cfg_attr(feature = "serde", serde(with = "humantime_serde::option"))]
#[viewit(
getter(const, attrs(doc = "Get timeout used for I/O."),),
setter(attrs(doc = "Set timeout used for I/O. (Builder pattern)"),)
)]
timeout: Option<Duration>,
#[cfg_attr(
feature = "serde",
serde(
with = "humantime_serde",
default = "default_connection_pool_cleanup_period"
)
)]
#[viewit(
getter(const, attrs(doc = "Get the cleanup period for the connection pool."),),
setter(attrs(doc = "Set the cleanup period for the connection pool"),)
)]
connection_pool_cleanup_period: Duration,
#[cfg_attr(feature = "serde", serde(default))]
#[viewit(
getter(
const,
style = "ref",
attrs(doc = "Get the policy for Classless Inter-Domain Routing (CIDR)."),
),
setter(attrs(
doc = "Set the policy for Classless Inter-Domain Routing (CIDR). (Builder pattern)"
),)
)]
cidrs_policy: CIDRsPolicy,
#[cfg(feature = "compression")]
#[cfg_attr(docsrs, doc(cfg(feature = "compression")))]
#[viewit(
getter(
const,
attrs(
doc = "Get the compression algorithm used for outgoing.",
cfg(feature = "compression"),
cfg_attr(docsrs, doc(cfg(feature = "compression")))
),
),
setter(attrs(
doc = "Set the compression algorithm used for outgoing. (Builder pattern)",
cfg(feature = "compression"),
cfg_attr(docsrs, doc(cfg(feature = "compression")))
),)
)]
compressor: Option<Compressor>,
#[cfg(feature = "compression")]
#[cfg_attr(docsrs, doc(cfg(feature = "compression")))]
#[viewit(
getter(
const,
attrs(
doc = "Get the size of a message that should be offload to [`rayon`] thread pool for encryption or compression.",
cfg(feature = "compression"),
cfg_attr(docsrs, doc(cfg(feature = "compression")))
),
),
setter(attrs(
doc = "Set the size of a message that should be offload to [`rayon`] thread pool for encryption or compression. (Builder pattern)",
cfg(feature = "compression"),
cfg_attr(docsrs, doc(cfg(feature = "compression")))
),)
)]
offload_size: usize,
#[cfg(feature = "metrics")]
#[cfg_attr(docsrs, doc(cfg(feature = "metrics")))]
#[viewit(
getter(
style = "ref",
result(
converter(fn = "Option::as_deref"),
type = "Option<&memberlist_core::types::MetricLabels>"
),
attrs(
doc = "Get the metrics labels.",
cfg(feature = "metrics"),
cfg_attr(docsrs, doc(cfg(feature = "metrics")))
),
),
setter(attrs(
doc = "Set the metrics labels. (Builder pattern)",
cfg(feature = "metrics"),
cfg_attr(docsrs, doc(cfg(feature = "metrics")))
))
)]
metric_labels: Option<Arc<memberlist_core::types::MetricLabels>>,
}
impl<I, A: AddressResolver<ResolvedAddress = SocketAddr>> QuicTransportOptions<I, A> {
pub fn new(id: I) -> Self {
Self {
id,
timeout: None,
bind_addresses: IndexSet::new(),
label: Label::empty(),
skip_inbound_label_check: false,
cidrs_policy: CIDRsPolicy::allow_all(),
connection_pool_cleanup_period: default_connection_pool_cleanup_period(),
#[cfg(feature = "compression")]
compressor: None,
#[cfg(feature = "compression")]
offload_size: 1024,
#[cfg(feature = "metrics")]
metric_labels: None,
}
}
pub fn add_bind_address(&mut self, addr: A::Address) -> &mut Self {
self.bind_addresses.insert(addr);
self
}
}
#[inline(always)]
const fn default_connection_pool_cleanup_period() -> Duration {
Duration::from_secs(60)
}