Skip to content

Commit

Permalink
move ServerConfig to sozu_command_lib::config
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed Feb 2, 2024
1 parent e382a1c commit 6d160b4
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 48 deletions.
41 changes: 41 additions & 0 deletions command/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1743,6 +1743,47 @@ fn display_toml_error(file: &str, error: &toml::de::Error) {
}
}

/// Used by a worker to start its server loop
pub struct ServerConfig {
pub max_connections: usize,
pub front_timeout: u32,
pub back_timeout: u32,
pub connect_timeout: u32,
pub zombie_check_interval: u32,
pub accept_queue_timeout: u32,
}

impl ServerConfig {
pub fn from_config(config: &Config) -> ServerConfig {
ServerConfig {
max_connections: config.max_connections,
front_timeout: config.front_timeout,
back_timeout: config.back_timeout,
connect_timeout: config.connect_timeout,
zombie_check_interval: config.zombie_check_interval,
accept_queue_timeout: config.accept_queue_timeout,
}
}

/// size of the slab for the Session manager
pub fn slab_capacity(&self) -> usize {
10 + 2 * self.max_connections
}
}

impl Default for ServerConfig {
fn default() -> ServerConfig {
ServerConfig {
max_connections: 10000,
front_timeout: 60,
back_timeout: 30,
connect_timeout: 3,
zombie_check_interval: 30 * 60,
accept_queue_timeout: 60,
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
1 change: 1 addition & 0 deletions lib/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use rusty_ulid::Ulid;
use time::{Duration, Instant};

use sozu_command::{
config::ServerConfig,
logging,
proto::command::{
request::RequestType, Cluster, HttpListenerConfig, ListenerType, RemoveListener,
Expand Down
13 changes: 7 additions & 6 deletions lib/src/https.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ use rustls::{
},
CryptoProvider,
},
CipherSuite, ProtocolVersion, ServerConfig, ServerConnection, SupportedCipherSuite,
CipherSuite, ProtocolVersion, ServerConfig as RustlsServerConfig, ServerConnection,
SupportedCipherSuite,
};
use rusty_ulid::Ulid;
use time::{Duration, Instant};

use sozu_command::{
certificate::Fingerprint,
config::DEFAULT_CIPHER_SUITES,
config::{ServerConfig, DEFAULT_CIPHER_SUITES},
logging,
proto::command::{
request::RequestType, response_content::ContentType, AddCertificate, CertificateSummary,
Expand Down Expand Up @@ -529,7 +530,7 @@ pub struct HttpsListener {
fronts: Router,
listener: Option<MioTcpListener>,
resolver: Arc<MutexWrappedCertificateResolver>,
rustls_details: Arc<ServerConfig>,
rustls_details: Arc<RustlsServerConfig>,
tags: BTreeMap<String, CachedTags>,
token: Token,
}
Expand Down Expand Up @@ -705,7 +706,7 @@ impl HttpsListener {
pub fn create_rustls_context(
config: &HttpsListenerConfig,
resolver: Arc<MutexWrappedCertificateResolver>,
) -> Result<ServerConfig, ListenerError> {
) -> Result<RustlsServerConfig, ListenerError> {
let cipher_names = if config.cipher_list.is_empty() {
DEFAULT_CIPHER_SUITES.to_vec()
} else {
Expand Down Expand Up @@ -758,7 +759,7 @@ impl HttpsListener {
..ring::default_provider()
};

let mut server_config = ServerConfig::builder_with_provider(provider.into())
let mut server_config = RustlsServerConfig::builder_with_provider(provider.into())
.with_protocol_versions(&versions[..])
.map_err(|err| ListenerError::BuildRustls(err.to_string()))?
.with_no_client_auth()
Expand Down Expand Up @@ -1593,7 +1594,7 @@ mod tests {
let address = SocketAddress::new_v4(127, 0, 0, 1, 1032);
let resolver = Arc::new(MutexWrappedCertificateResolver::default());

let server_config = ServerConfig::builder_with_protocol_versions(&[
let server_config = RustlsServerConfig::builder_with_protocol_versions(&[
&rustls::version::TLS12,
&rustls::version::TLS13,
])
Expand Down
3 changes: 2 additions & 1 deletion lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,7 @@ pub mod testing {
pub use mio::{net::UnixStream, Poll, Registry, Token};
pub use slab::Slab;
pub use sozu_command::{
config::ServerConfig,
proto::command::{HttpListenerConfig, HttpsListenerConfig, TcpListenerConfig},
scm_socket::{Listeners, ScmSocket},
};
Expand All @@ -1126,7 +1127,7 @@ pub mod testing {
https::HttpsProxy,
pool::Pool,
server::Server,
server::{ListenSession, ProxyChannel, ServerConfig, SessionManager},
server::{ListenSession, ProxyChannel, SessionManager},
tcp::TcpProxy,
Protocol, ProxySession,
};
Expand Down
41 changes: 1 addition & 40 deletions lib/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use time::{Duration, Instant};

use sozu_command::{
channel::Channel,
config::Config,
config::{Config, ServerConfig},
proto::command::{
request::RequestType, response_content::ContentType, ActivateListener, AddBackend,
CertificatesWithFingerprints, Cluster, ClusterHashes, ClusterInformations,
Expand Down Expand Up @@ -100,45 +100,6 @@ impl From<SessionToken> for usize {
}
}

pub struct ServerConfig {
pub max_connections: usize,
pub front_timeout: u32,
pub back_timeout: u32,
pub connect_timeout: u32,
pub zombie_check_interval: u32,
pub accept_queue_timeout: u32,
}

impl ServerConfig {
pub fn from_config(config: &Config) -> ServerConfig {
ServerConfig {
max_connections: config.max_connections,
front_timeout: config.front_timeout,
back_timeout: config.back_timeout,
connect_timeout: config.connect_timeout,
zombie_check_interval: config.zombie_check_interval,
accept_queue_timeout: config.accept_queue_timeout,
}
}

fn slab_capacity(&self) -> usize {
10 + 2 * self.max_connections
}
}

impl Default for ServerConfig {
fn default() -> ServerConfig {
ServerConfig {
max_connections: 10000,
front_timeout: 60,
back_timeout: 30,
connect_timeout: 3,
zombie_check_interval: 30 * 60,
accept_queue_timeout: 60,
}
}
}

pub struct SessionManager {
pub max_connections: usize,
pub nb_connections: usize,
Expand Down
5 changes: 4 additions & 1 deletion lib/src/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ use mio::{
use rusty_ulid::Ulid;
use time::{Duration, Instant};

use sozu_command::{config::MAX_LOOP_ITERATIONS, proto::command::request::RequestType, ObjectKind};
use sozu_command::{
config::ServerConfig, config::MAX_LOOP_ITERATIONS, proto::command::request::RequestType,
ObjectKind,
};

use crate::{
backends::{Backend, BackendMap},
Expand Down

0 comments on commit 6d160b4

Please sign in to comment.