Skip to content

Commit

Permalink
write TcpListenerConfig in protobuf
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed Apr 5, 2023
1 parent a91a576 commit 6daea56
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 65 deletions.
16 changes: 14 additions & 2 deletions command/src/command.proto
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,20 @@ message HttpsListenerConfig {
optional string key = 19;
}



// details of an TCP listener
message TcpListenerConfig {
required string address = 1;
optional string public_address = 2;
required bool expect_proxy = 3 [default = false];
// client inactive time, in seconds
required uint32 front_timeout = 4 [default = 60];
// backend server inactive time, in seconds
required uint32 back_timeout = 5 [default = 30];
// time to connect to the backend, in seconds
required uint32 connect_timeout = 6 [default = 3];
// wether the listener is actively listening on its socket
required bool active = 7 [default = false];
}

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

/// [`DEFAULT_RUSTLS_CIPHER_LIST`] provides all supported cipher suites exported by Rustls TLS
Expand Down
3 changes: 2 additions & 1 deletion command/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ use crate::{
HttpsListenerConfig, LoadBalancingAlgorithms, MetricsConfiguration, PathRuleKind,
QueryClusterByDomain, QueryMetricsOptions, RemoveBackend, RemoveCertificate,
ReplaceCertificate, RequestHttpFrontend, RequestTcpFrontend, RulePosition,
TcpListenerConfig,
},
response::{HttpFrontend, MessageId, TcpListenerConfig},
response::{HttpFrontend, MessageId},
state::ClusterId,
};

Expand Down
24 changes: 3 additions & 21 deletions command/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use crate::{
proto::command::{
AddBackend, AggregatedMetrics, CertificateSummary, Cluster, FilteredTimeSerie,
HttpListenerConfig, HttpsListenerConfig, LoadBalancingParams, PathRule, PathRuleKind,
RequestHttpFrontend, RequestTcpFrontend, RulePosition, RunState, TlsVersion, WorkerInfo,
WorkerMetrics,
RequestHttpFrontend, RequestTcpFrontend, RulePosition, RunState, TcpListenerConfig,
WorkerInfo, WorkerMetrics,
},
request::{default_sticky_name, is_false, PROTOCOL_VERSION},
request::PROTOCOL_VERSION,
state::{ClusterId, ConfigState},
};

Expand Down Expand Up @@ -296,24 +296,6 @@ pub struct ListenersList {
pub tcp_listeners: HashMap<String, TcpListenerConfig>,
}

// TODO: implement Default
/// details of an TCP listener, sent by the main process to the worker
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct TcpListenerConfig {
pub address: String,
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub public_address: Option<String>,
#[serde(default)]
#[serde(skip_serializing_if = "is_false")]
pub expect_proxy: bool,
pub front_timeout: u32,
pub back_timeout: u32,
pub connect_timeout: u32,
/// should default to false
pub active: bool,
}

impl fmt::Display for RunState {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{self:?}")
Expand Down
23 changes: 5 additions & 18 deletions command/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ use crate::{
proto::command::{
AddBackend, AddCertificate, CertificateAndKey, Cluster, HttpListenerConfig,
HttpsListenerConfig, PathRule, RemoveBackend, RemoveCertificate, ReplaceCertificate,
RequestHttpFrontend, RequestTcpFrontend,
RequestHttpFrontend, RequestTcpFrontend, TcpListenerConfig,
},
request::{ActivateListener, DeactivateListener, ListenerType, RemoveListener, Request},
response::{Backend, ClusterInformation, HttpFrontend, TcpFrontend, TcpListenerConfig},
response::{Backend, ClusterInformation, HttpFrontend, TcpFrontend},
};

/// To use throughout Sōzu
Expand Down Expand Up @@ -1599,12 +1599,7 @@ mod tests {
state
.dispatch(&Request::AddTcpListener(TcpListenerConfig {
address: "0.0.0.0:1234".parse().unwrap(),
public_address: None,
expect_proxy: false,
front_timeout: 60,
back_timeout: 30,
connect_timeout: 3,
active: false,
..Default::default()
}))
.expect("Could not execute request");
state
Expand Down Expand Up @@ -1641,12 +1636,8 @@ mod tests {
state2
.dispatch(&Request::AddTcpListener(TcpListenerConfig {
address: "0.0.0.0:1234".parse().unwrap(),
public_address: None,
expect_proxy: true,
front_timeout: 60,
back_timeout: 30,
connect_timeout: 3,
active: false,
..Default::default()
}))
.expect("Could not execute request");
state2
Expand Down Expand Up @@ -1687,12 +1678,8 @@ mod tests {
}),
Request::AddTcpListener(TcpListenerConfig {
address: "0.0.0.0:1234".parse().unwrap(),
public_address: None,
expect_proxy: true,
front_timeout: 60,
back_timeout: 30,
connect_timeout: 3,
active: false,
..Default::default()
}),
Request::DeactivateListener(DeactivateListener {
address: "0.0.0.0:1234".parse().unwrap(),
Expand Down
10 changes: 2 additions & 8 deletions lib/examples/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ use anyhow::Context;
use sozu_command::{
channel::Channel,
logging::{Logger, LoggerBackend},
proto::command::{AddBackend, LoadBalancingParams, RequestTcpFrontend},
proto::command::{AddBackend, LoadBalancingParams, RequestTcpFrontend, TcpListenerConfig},
request::{Request, WorkerRequest},
response::TcpListenerConfig,
};

fn main() -> anyhow::Result<()> {
Expand Down Expand Up @@ -41,12 +40,7 @@ fn main() -> anyhow::Result<()> {
let buffer_size = 16384;
let listener = TcpListenerConfig {
address: "127.0.0.1:8080".parse().expect("could not parse address"),
public_address: None,
expect_proxy: false,
front_timeout: 60,
back_timeout: 30,
connect_timeout: 3,
active: false,
..Default::default()
};
Logger::init(
"TCP".to_string(),
Expand Down
7 changes: 2 additions & 5 deletions lib/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@ use sozu_command::{
config::Config,
proto::command::{
AddBackend, Cluster, HttpListenerConfig, HttpsListenerConfig, LoadBalancingAlgorithms,
LoadMetric, RemoveBackend,
LoadMetric, RemoveBackend, TcpListenerConfig as CommandTcpListener,
},
ready::Ready,
request::{ActivateListener, DeactivateListener, ListenerType, Request, WorkerRequest},
response::{
Event, MessageId, ResponseContent, ResponseStatus, TcpListenerConfig as CommandTcpListener,
WorkerResponse,
},
response::{Event, MessageId, ResponseContent, ResponseStatus, WorkerResponse},
scm_socket::{Listeners, ScmSocket},
state::{get_certificate, get_cluster_ids_by_domain, ConfigState},
};
Expand Down
11 changes: 3 additions & 8 deletions lib/src/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ use crate::{
socket::server_bind,
sozu_command::{
logging,
proto::command::{ProxyProtocolConfig, RequestTcpFrontend},
proto::command::{ProxyProtocolConfig, RequestTcpFrontend, TcpListenerConfig},
ready::Ready,
request::{Request, WorkerRequest},
response::{Event, TcpListenerConfig, WorkerResponse},
response::{Event, WorkerResponse},
scm_socket::ScmSocket,
state::ClusterId,
},
Expand Down Expand Up @@ -1802,12 +1802,7 @@ mod tests {
let mut configuration = TcpProxy::new(registry, sessions.clone(), backends.clone());
let listener_config = TcpListenerConfig {
address: "127.0.0.1:1234".to_string(),
public_address: None,
expect_proxy: false,
front_timeout: 60,
back_timeout: 30,
connect_timeout: 3,
active: false,
..Default::default()
};

{
Expand Down

0 comments on commit 6daea56

Please sign in to comment.