praxis_protocol/lib.rs
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2024 Praxis Contributors
3
4#![deny(unreachable_pub)]
5#![expect(
6 clippy::arithmetic_side_effects,
7 clippy::as_conversions,
8 clippy::impl_trait_in_params,
9 clippy::iter_over_hash_type,
10 clippy::min_ident_chars,
11 clippy::mod_module_files,
12 clippy::partial_pub_fields,
13 clippy::pub_underscore_fields,
14 clippy::shadow_unrelated,
15 clippy::single_char_lifetime_names,
16 clippy::wildcard_enum_match_arm,
17 reason = "TODO(conventions-sync): fix violations and remove"
18)]
19
20//! Protocol adapters for Praxis.
21
22use praxis_core::{PingoraServerRuntime, ProxyError, config::Config};
23use tokio::sync::watch;
24
25mod pipelines;
26pub use pipelines::ListenerPipelines;
27
28/// Process-wide connection limit.
29pub mod connections;
30/// HTTP protocol implementations.
31pub mod http;
32/// Raw TCP/L4 forwarding protocol.
33pub mod tcp;
34
35/// Shared TLS settings builder for HTTP and TCP listeners.
36pub(crate) mod tls_setup;
37
38// -----------------------------------------------------------------------------
39// CertWatcherShutdowns
40// -----------------------------------------------------------------------------
41
42/// Collected TLS certificate watcher shutdown senders.
43///
44/// Keeps [`watch::Sender`]s alive so that background [`CertWatcher`]
45/// tasks run until the process exits. Dropping these senders signals
46/// the watchers to stop.
47///
48/// [`watch::Sender`]: tokio::sync::watch::Sender
49/// [`CertWatcher`]: praxis_tls::watcher::CertWatcher
50pub struct CertWatcherShutdowns {
51 /// Shutdown senders kept alive for the server lifetime.
52 _senders: Vec<watch::Sender<bool>>,
53}
54
55impl CertWatcherShutdowns {
56 /// Wrap collected shutdown senders.
57 pub fn new(senders: Vec<watch::Sender<bool>>) -> Self {
58 Self { _senders: senders }
59 }
60}
61
62// -----------------------------------------------------------------------------
63// Protocol
64// -----------------------------------------------------------------------------
65
66/// A protocol implementation that registers services onto a shared server runtime.
67pub trait Protocol: Send {
68 /// Register this protocol's services. Does not block.
69 ///
70 /// Returns any TLS certificate watcher shutdown senders. The
71 /// caller must keep these alive until server shutdown; dropping
72 /// them signals the watcher tasks to stop.
73 ///
74 /// # Errors
75 ///
76 /// Returns [`ProxyError`] if listener binding or setup fails.
77 ///
78 /// [`ProxyError`]: praxis_core::ProxyError
79 fn register(
80 self: Box<Self>,
81 server: &mut PingoraServerRuntime,
82 config: &Config,
83 pipelines: &ListenerPipelines,
84 ) -> Result<Vec<watch::Sender<bool>>, ProxyError>;
85}