Skip to content

Commit

Permalink
write HttpFrontendConfig in protobuf
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed Apr 5, 2023
1 parent 19d2915 commit 50b1a2e
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 71 deletions.
20 changes: 20 additions & 0 deletions command/src/command.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
syntax = "proto2";
package command;

// details of an HTTP listener
message HttpListenerConfig {
required string address = 1;
optional string public_address = 2;
required string answer_404 = 3;
required string answer_503 = 4;
required bool expect_proxy = 5 [default = false];
required string sticky_name = 6;
// client inactive time, in seconds
required uint32 front_timeout = 7 [default = 60];
// backend server inactive time, in seconds
required uint32 back_timeout = 8 [default = 30];
// time to connect to the backend, in seconds
required uint32 connect_timeout = 9 [default = 3];
// max time to send a complete request, in seconds
required uint32 request_timeout = 10 [default = 10];
// wether the listener is actively listening on its socket
required bool active = 11 [default = false];
}

message RequestHttpFrontend {
optional string cluster_id = 1;
required string address = 2;
Expand Down
14 changes: 5 additions & 9 deletions command/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ use toml;
use crate::{
certificate::split_certificate_chain,
proto::command::{
AddBackend, AddCertificate, CertificateAndKey, Cluster, LoadBalancingAlgorithms,
LoadBalancingParams, LoadMetric, PathRule, ProxyProtocolConfig, RequestHttpFrontend,
RequestTcpFrontend, RulePosition, TlsVersion,
AddBackend, AddCertificate, CertificateAndKey, Cluster, HttpListenerConfig,
LoadBalancingAlgorithms, LoadBalancingParams, LoadMetric, PathRule, ProxyProtocolConfig,
RequestHttpFrontend, RequestTcpFrontend, RulePosition, TlsVersion,
},
request::{ActivateListener, ListenerType, Request, WorkerRequest},
response::{HttpListenerConfig, HttpsListenerConfig, TcpListenerConfig},
response::{HttpsListenerConfig, TcpListenerConfig},
};

/// [`DEFAULT_RUSTLS_CIPHER_LIST`] provides all supported cipher suites exported by Rustls TLS
Expand Down Expand Up @@ -289,13 +289,9 @@ impl ListenerBuilder {
public_address: self.public_address.clone(),
expect_proxy: self.expect_proxy.unwrap_or(false),
sticky_name: self.sticky_name.clone(),
front_timeout: self.front_timeout.unwrap_or(DEFAULT_FRONT_TIMEOUT),
back_timeout: self.back_timeout.unwrap_or(DEFAULT_BACK_TIMEOUT),
connect_timeout: self.connect_timeout.unwrap_or(DEFAULT_CONNECT_TIMEOUT),
request_timeout: self.request_timeout.unwrap_or(DEFAULT_REQUEST_TIMEOUT),
answer_404,
answer_503,
active: false,
..Default::default()
};

Ok(configuration)
Expand Down
11 changes: 5 additions & 6 deletions command/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ use anyhow::Context;
use crate::{
certificate::Fingerprint,
proto::command::{
AddBackend, AddCertificate, Cluster, FrontendFilters, LoadBalancingAlgorithms,
PathRuleKind, QueryClusterByDomain, QueryMetricsOptions, RemoveBackend, RemoveCertificate,
ReplaceCertificate, RequestHttpFrontend, RequestTcpFrontend, RulePosition,MetricsConfiguration
},
response::{
HttpFrontend, HttpListenerConfig, HttpsListenerConfig, MessageId, TcpListenerConfig,
AddBackend, AddCertificate, Cluster, FrontendFilters, HttpListenerConfig,
LoadBalancingAlgorithms, MetricsConfiguration, PathRuleKind, QueryClusterByDomain,
QueryMetricsOptions, RemoveBackend, RemoveCertificate, ReplaceCertificate,
RequestHttpFrontend, RequestTcpFrontend, RulePosition,
},
response::{HttpFrontend, HttpsListenerConfig, MessageId, TcpListenerConfig},
state::ClusterId,
};

Expand Down
28 changes: 1 addition & 27 deletions command/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
proto::command::{
AddBackend, AggregatedMetrics, CertificateSummary, Cluster, FilteredTimeSerie,
LoadBalancingParams, PathRule, PathRuleKind, RequestHttpFrontend, RequestTcpFrontend,
RulePosition, RunState, TlsVersion, WorkerInfo, WorkerMetrics,
RulePosition, RunState, TlsVersion, WorkerInfo, WorkerMetrics, HttpListenerConfig,
},
request::{default_sticky_name, is_false, PROTOCOL_VERSION},
state::{ClusterId, ConfigState},
Expand Down Expand Up @@ -295,32 +295,6 @@ pub struct ListenersList {
pub tcp_listeners: HashMap<String, TcpListenerConfig>,
}

// TODO: implement Default
/// details of an HTTP listener, sent by the main process to the worker
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct HttpListenerConfig {
pub address: String,
pub public_address: Option<String>,
pub answer_404: String,
pub answer_503: String,
#[serde(default)]
#[serde(skip_serializing_if = "is_false")]
pub expect_proxy: bool,
/// identifies sticky sessions
#[serde(default = "default_sticky_name")]
pub sticky_name: String,
/// client inactive time
pub front_timeout: u32,
/// backend server inactive time
pub back_timeout: u32,
/// time to connect to the backend
pub connect_timeout: u32,
/// max time to send a complete request
pub request_timeout: u32,
/// should default to false
pub active: bool,
}

// TODO: implement Default
/// details of an HTTPS listener, sent by the main process to the worker
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
Expand Down
33 changes: 8 additions & 25 deletions command/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ use anyhow::{bail, Context};
use crate::{
certificate::{calculate_fingerprint, Fingerprint},
proto::command::{
AddBackend, AddCertificate, CertificateAndKey, Cluster, PathRule, RemoveBackend,
RemoveCertificate, ReplaceCertificate, RequestHttpFrontend, RequestTcpFrontend,
AddBackend, AddCertificate, CertificateAndKey, Cluster, HttpListenerConfig, PathRule,
RemoveBackend, RemoveCertificate, ReplaceCertificate, RequestHttpFrontend,
RequestTcpFrontend,
},
request::{ActivateListener, DeactivateListener, ListenerType, RemoveListener, Request},
response::{
Backend, ClusterInformation, HttpFrontend, HttpListenerConfig, HttpsListenerConfig,
TcpFrontend, TcpListenerConfig,
Backend, ClusterInformation, HttpFrontend, HttpsListenerConfig, TcpFrontend,
TcpListenerConfig,
},
};

Expand Down Expand Up @@ -1619,16 +1620,10 @@ mod tests {
state
.dispatch(&Request::AddHttpListener(HttpListenerConfig {
address: "0.0.0.0:8080".parse().unwrap(),
public_address: None,
expect_proxy: false,
answer_404: String::new(),
answer_503: String::new(),
sticky_name: String::new(),
front_timeout: 60,
request_timeout: 10,
back_timeout: 30,
connect_timeout: 3,
active: false,
..Default::default()
}))
.expect("Could not execute request");
state
Expand Down Expand Up @@ -1677,16 +1672,10 @@ mod tests {
state2
.dispatch(&Request::AddHttpListener(HttpListenerConfig {
address: "0.0.0.0:8080".parse().unwrap(),
public_address: None,
expect_proxy: false,
answer_404: "test".to_string(),
answer_503: String::new(),
sticky_name: String::new(),
front_timeout: 60,
request_timeout: 10,
back_timeout: 30,
connect_timeout: 3,
active: false,
..Default::default()
}))
.expect("Could not execute request");
state2
Expand Down Expand Up @@ -1752,16 +1741,10 @@ mod tests {
}),
Request::AddHttpListener(HttpListenerConfig {
address: "0.0.0.0:8080".parse().unwrap(),
public_address: None,
expect_proxy: false,
answer_404: String::from("test"),
answer_503: String::new(),
sticky_name: String::new(),
front_timeout: 60,
request_timeout: 10,
back_timeout: 30,
connect_timeout: 3,
active: false,
..Default::default()
}),
Request::ActivateListener(ActivateListener {
address: "0.0.0.0:8080".parse().unwrap(),
Expand Down
4 changes: 2 additions & 2 deletions lib/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ use time::{Duration, Instant};

use sozu_command::{
logging,
proto::command::{Cluster, RequestHttpFrontend},
proto::command::{Cluster, HttpListenerConfig, RequestHttpFrontend},
ready::Ready,
request::{RemoveListener, Request, WorkerRequest},
response::{HttpFrontend, HttpListenerConfig, WorkerResponse},
response::{HttpFrontend, WorkerResponse},
scm_socket::{Listeners, ScmSocket},
};

Expand Down
6 changes: 4 additions & 2 deletions lib/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ use slab::Slab;
use sozu_command::{
channel::Channel,
config::Config,
proto::command::{AddBackend, Cluster, LoadBalancingAlgorithms, LoadMetric, RemoveBackend},
proto::command::{
AddBackend, Cluster, HttpListenerConfig, LoadBalancingAlgorithms, LoadMetric, RemoveBackend,
},
ready::Ready,
request::{ActivateListener, DeactivateListener, ListenerType, Request, WorkerRequest},
response::{
Event, HttpListenerConfig, HttpsListenerConfig, MessageId, ResponseContent, ResponseStatus,
Event, HttpsListenerConfig, MessageId, ResponseContent, ResponseStatus,
TcpListenerConfig as CommandTcpListener, WorkerResponse,
},
scm_socket::{Listeners, ScmSocket},
Expand Down

0 comments on commit 50b1a2e

Please sign in to comment.