refactor: make globals simple

This commit is contained in:
Jun Kurihara 2023-07-07 20:24:38 +09:00
commit 80e10d5ccd
No known key found for this signature in database
GPG key ID: 48ADFD173ED22B03
4 changed files with 37 additions and 19 deletions

View file

@ -6,25 +6,24 @@ use std::sync::{
};
use tokio::time::Duration;
/// Global object containing proxy configurations and shared object like counters.
/// But note that in Globals, we do not have Mutex and RwLock. It is indeed, the context shared among async tasks.
pub struct Globals {
pub listen_sockets: Vec<SocketAddr>,
pub http_port: Option<u16>,
pub https_port: Option<u16>,
pub listen_sockets: Vec<SocketAddr>, // when instantiate server
pub http_port: Option<u16>, // when instantiate server
pub https_port: Option<u16>, // when instantiate server
pub proxy_timeout: Duration,
pub upstream_timeout: Duration,
pub proxy_timeout: Duration, // when serving requests at Proxy
pub upstream_timeout: Duration, // when serving requests at Handler
pub max_clients: usize,
pub request_count: RequestCount,
pub max_concurrent_streams: u32,
pub keepalive: bool,
pub runtime_handle: tokio::runtime::Handle,
pub backends: Backends,
pub max_clients: usize, // when serving requests
pub max_concurrent_streams: u32, // when instantiate server
pub keepalive: bool, // when instantiate server
// experimentals
pub sni_consistency: bool,
pub sni_consistency: bool, // Handler
// All need to make packet acceptor
#[cfg(feature = "http3")]
pub http3: bool,
#[cfg(feature = "http3")]
@ -39,9 +38,22 @@ pub struct Globals {
pub h3_max_concurrent_connections: u32,
#[cfg(feature = "http3")]
pub h3_max_idle_timeout: Option<quinn::IdleTimeout>,
// Shared context
// Backend application objects to which http request handler forward incoming requests
pub backends: Backends,
// Counter for serving requests
pub request_count: RequestCount,
// Async task runtime handler
pub runtime_handle: tokio::runtime::Handle,
}
// // TODO: Implement default for default values
// #[derive(Debug, Clone)]
// pub struct ProxyConfig {}
#[derive(Debug, Clone, Default)]
/// Counter for serving requests
pub struct RequestCount(Arc<AtomicUsize>);
impl RequestCount {