pub struct TlsReloader { /* private fields */ }Expand description
Holds the live [rustls::ServerConfig] and swaps it when the files change.
The accept loop reads TlsReloader::current once per connection, so a swap
affects new connections only — established ones finish under the certificate
they started with, which is what makes rotation non-disruptive.
§Failure behaviour
A reload that cannot be built is a non-event: the error is logged and the existing configuration keeps serving. This is deliberate and differs from startup, where bad TLS material is fatal. At startup, continuing would mean silently serving plaintext; here there is already a working configuration in memory, so retaining it is strictly safer than either failing or downgrading.
It also makes non-atomic renewals safe. A poll can easily observe a new certificate alongside a not-yet-replaced key; that pair does not build, the swap is skipped, and the next poll picks up the completed write.
Implementations§
Source§impl TlsReloader
impl TlsReloader
Sourcepub fn new(settings: TlsSettings) -> Result<Self, TlsError>
pub fn new(settings: TlsSettings) -> Result<Self, TlsError>
Build the initial configuration and capture its fingerprint.
§Arguments
settings- resolved TLS settings
§Errors
Propagates any TlsError from build_server_config. Unlike a later
reload, a failure here is fatal: there is no known-good config to
fall back to.
Sourcepub fn current(&self) -> Arc<ServerConfig>
pub fn current(&self) -> Arc<ServerConfig>
The configuration new connections should use.
Cheap: clones an Arc while holding the read lock only for that clone,
never across an await.
Sourcepub fn reloading_enabled(interval_secs: u64) -> bool
pub fn reloading_enabled(interval_secs: u64) -> bool
Whether a reload interval enables reloading at all.
Zero restores the startup-only behaviour of earlier releases.
Sourcepub fn reload_if_changed(&self) -> bool
pub fn reload_if_changed(&self) -> bool
Re-read the files and swap the live config if they changed and still build.
§Returns
true only when a new configuration was actually installed. An unchanged
fingerprint, an unreadable file and a material that fails to build all
return false and leave the current configuration serving.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for TlsReloader
impl RefUnwindSafe for TlsReloader
impl Send for TlsReloader
impl Sync for TlsReloader
impl Unpin for TlsReloader
impl UnwindSafe for TlsReloader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].