use super::{Config, Millis, Setting};
pub const TRANSPORT_INSECURE_WS: Setting<bool> = crate::setting!(
"transport.insecure_ws",
default = false,
reload = Live,
sensitivity = Public,
scope = Service,
critical = true,
doc = "plain ws:// to a peer beyond loopback (a test network's); read at every dial"
);
pub const TRANSPORT_TLS_ROOTS: Setting<Option<String>> = crate::setting!(
"transport.tls_roots",
default = None,
reload = Live,
remote = false,
doc = "a PEM file of extra CAs a wss:// peer may chain to; read at every dial; the host's alone"
);
pub const CHILD_LEGACY_UPCALLS: Setting<bool> = crate::setting!(
"child.legacy_upcalls",
default = false,
critical = true,
doc = "a child declaring no needs calls up anything its caller could (NEST-11's rule); read at each mount"
);
pub const CHILD_TIMEOUT: Setting<Millis> = crate::setting!("child.timeout", default = Millis::secs(5), doc = "a child's answer to _info and each call's open; read at each mount");
pub const CHILD_MAX_CALLS: Setting<usize> = crate::setting!("child.max_calls", default = 1024, doc = "calls open on one child at once; read at each mount");
pub const CHILD_BACKOFF: Setting<Backoff> = crate::setting!("child.backoff", default = Backoff::DEFAULT, doc = "restarting a child that died: initial, max, per_minute; read at each mount");
pub const LOG_REDACT_KEYS: Setting<Vec<String>> = crate::setting!(
"log.redact.keys",
default = Vec::new(),
scope = Process,
doc = "keys whose values the log redacts, beside the fixed credential keys"
);
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
pub struct Backoff {
pub initial: Millis,
pub max: Millis,
pub per_minute: usize,
}
impl Backoff {
pub const DEFAULT: Backoff = Backoff { initial: Millis::ms(500), max: Millis::secs(30), per_minute: 5 };
}
pub(crate) fn declare_core(c: &Config) {
c.declare(&TRANSPORT_INSECURE_WS);
c.declare(&TRANSPORT_TLS_ROOTS);
c.declare(&CHILD_LEGACY_UPCALLS);
c.declare(&CHILD_TIMEOUT);
c.declare(&CHILD_MAX_CALLS);
c.declare(&CHILD_BACKOFF);
c.declare(&LOG_REDACT_KEYS);
let first = std::sync::atomic::AtomicBool::new(true);
c.on_change(&LOG_REDACT_KEYS, move |keys| {
if first.swap(false, std::sync::atomic::Ordering::SeqCst) && keys.is_empty() {
return;
}
crate::plexus::redact::set_extra_keys(&keys);
});
}
#[cfg(not(target_arch = "wasm32"))]
impl crate::plexus::ChildOptions {
pub fn configured(mut self, c: &Config) -> Self {
use super::Source;
if c.source(&CHILD_TIMEOUT) != Source::Default {
self.timeout = c.get(&CHILD_TIMEOUT).0;
}
if c.source(&CHILD_MAX_CALLS) != Source::Default {
self.max_calls = c.get(&CHILD_MAX_CALLS);
}
if c.source(&CHILD_BACKOFF) != Source::Default {
let b = c.get(&CHILD_BACKOFF);
self.backoff = crate::plexus::Backoff { initial: b.initial.0, max: b.max.0, per_minute: b.per_minute };
}
if c.source(&CHILD_LEGACY_UPCALLS) != Source::Default {
self.legacy_upcalls = c.get(&CHILD_LEGACY_UPCALLS);
}
if c.source(&TRANSPORT_TLS_ROOTS) != Source::Default {
self.tls_roots = c.get(&TRANSPORT_TLS_ROOTS).map(Into::into);
}
if c.source(&TRANSPORT_INSECURE_WS) != Source::Default {
self.insecure_ws = c.get(&TRANSPORT_INSECURE_WS);
}
self
}
pub fn seed(&self, c: &Config) {
use super::Source;
let d = Self::default();
if self.timeout != d.timeout {
c.seed(&CHILD_TIMEOUT, Source::Flag, Some(Millis(self.timeout)));
}
if self.max_calls != d.max_calls {
c.seed(&CHILD_MAX_CALLS, Source::Flag, Some(self.max_calls));
}
if (self.backoff.initial, self.backoff.max, self.backoff.per_minute) != (d.backoff.initial, d.backoff.max, d.backoff.per_minute) {
c.seed(&CHILD_BACKOFF, Source::Flag, Some(Backoff { initial: Millis(self.backoff.initial), max: Millis(self.backoff.max), per_minute: self.backoff.per_minute }));
}
if self.legacy_upcalls != d.legacy_upcalls {
c.seed(&CHILD_LEGACY_UPCALLS, Source::Flag, Some(self.legacy_upcalls));
}
if let Some(r) = &self.tls_roots {
c.seed(&TRANSPORT_TLS_ROOTS, Source::Flag, Some(Some(r.display().to_string())));
}
if self.insecure_ws != d.insecure_ws {
c.seed(&TRANSPORT_INSECURE_WS, Source::Flag, Some(self.insecure_ws));
}
}
}