Skip to content

Commit

Permalink
replace SocketAddr type with String in Listeners
Browse files Browse the repository at this point in the history
HttpListenerConfig, HttpsListenerConfig, TcpListenerConfig
parse String to SocketAddr everywhere but transmit String only between
services
  • Loading branch information
Keksoj committed Apr 3, 2023
1 parent e2788c9 commit 8d6eb42
Show file tree
Hide file tree
Showing 12 changed files with 268 additions and 183 deletions.
44 changes: 34 additions & 10 deletions command/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,17 @@ impl ListenerBuilder {
.get_404_503_answers()
.with_context(|| "Could not get 404 and 503 answers from file system")?;

let _address = self
.parse_address()
.with_context(|| "wrong socket address")?;

let _public_address = self
.parse_public_address()
.with_context(|| "wrong public address")?;

let configuration = HttpListenerConfig {
address: self.parse_address()?,
public_address: self.parse_public_address()?,
address: self.address.clone(),
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),
Expand Down Expand Up @@ -362,10 +370,18 @@ impl ListenerBuilder {
.get_404_503_answers()
.with_context(|| "Could not get 404 and 503 answers from file system")?;

let _address = self
.parse_address()
.with_context(|| "wrong socket address")?;

let _public_address = self
.parse_public_address()
.with_context(|| "wrong public address")?;

let https_listener_config = HttpsListenerConfig {
address: self.parse_address()?,
address: self.address.clone(),
sticky_name: self.sticky_name.clone(),
public_address: self.parse_public_address()?,
public_address: self.public_address.clone(),
cipher_list,
versions,
expect_proxy: self.expect_proxy.unwrap_or(false),
Expand Down Expand Up @@ -395,9 +411,17 @@ impl ListenerBuilder {
));
}

let _address = self
.parse_address()
.with_context(|| "wrong socket address")?;

let _public_address = self
.parse_public_address()
.with_context(|| "wrong public address")?;

Ok(TcpListenerConfig {
address: self.parse_address()?,
public_address: self.parse_public_address()?,
address: self.address.clone(),
public_address: self.public_address.clone(),
expect_proxy: self.expect_proxy.unwrap_or(false),
front_timeout: self.front_timeout.unwrap_or(DEFAULT_FRONT_TIMEOUT),
back_timeout: self.back_timeout.unwrap_or(DEFAULT_BACK_TIMEOUT),
Expand Down Expand Up @@ -1078,7 +1102,7 @@ impl ConfigBuilder {
if frontend.certificate.is_none() {
if let Some(https_listener) =
self.built.https_listeners.iter().find(|listener| {
listener.address == frontend.address
listener.address == frontend.address.to_string()
&& listener.certificate.is_some()
})
{
Expand Down Expand Up @@ -1341,7 +1365,7 @@ impl Config {
v.push(WorkerRequest {
id: format!("CONFIG-{count}"),
content: Request::ActivateListener(ActivateListener {
address: listener.address,
address: listener.address.clone(),
proxy: ListenerType::HTTP,
from_scm: false,
}),
Expand All @@ -1353,7 +1377,7 @@ impl Config {
v.push(WorkerRequest {
id: format!("CONFIG-{count}"),
content: Request::ActivateListener(ActivateListener {
address: listener.address,
address: listener.address.clone(),
proxy: ListenerType::HTTPS,
from_scm: false,
}),
Expand All @@ -1365,7 +1389,7 @@ impl Config {
v.push(WorkerRequest {
id: format!("CONFIG-{count}"),
content: Request::ActivateListener(ActivateListener {
address: listener.address,
address: listener.address.clone(),
proxy: ListenerType::TCP,
from_scm: false,
}),
Expand Down
6 changes: 3 additions & 3 deletions command/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,20 +249,20 @@ pub enum ListenerType {

#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct RemoveListener {
pub address: SocketAddr,
pub address: String,
pub proxy: ListenerType,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct ActivateListener {
pub address: SocketAddr,
pub address: String,
pub proxy: ListenerType,
pub from_scm: bool,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct DeactivateListener {
pub address: SocketAddr,
pub address: String,
pub proxy: ListenerType,
pub to_scm: bool,
}
Expand Down
19 changes: 10 additions & 9 deletions command/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,16 +326,17 @@ impl Backend {
/// the bool indicates if it is active or not
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
pub struct ListenersList {
pub http_listeners: HashMap<SocketAddr, (HttpListenerConfig, bool)>,
pub https_listeners: HashMap<SocketAddr, (HttpsListenerConfig, bool)>,
pub tcp_listeners: HashMap<SocketAddr, (TcpListenerConfig, bool)>,
/// address -> (listener_config, activated)
pub http_listeners: HashMap<String, (HttpListenerConfig, bool)>,
pub https_listeners: HashMap<String, (HttpsListenerConfig, bool)>,
pub tcp_listeners: HashMap<String, (TcpListenerConfig, bool)>,
}

/// 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: SocketAddr,
pub public_address: Option<SocketAddr>,
pub address: String,
pub public_address: Option<String>,
pub answer_404: String,
pub answer_503: String,
#[serde(default)]
Expand All @@ -357,8 +358,8 @@ pub struct HttpListenerConfig {
/// details of an HTTPS listener, sent by the main process to the worker
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct HttpsListenerConfig {
pub address: SocketAddr,
pub public_address: Option<SocketAddr>,
pub address: String,
pub public_address: Option<String>,
pub answer_404: String,
pub answer_503: String,
pub versions: Vec<TlsVersion>,
Expand Down Expand Up @@ -389,10 +390,10 @@ pub struct HttpsListenerConfig {
/// 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: SocketAddr,
pub address: String,
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub public_address: Option<SocketAddr>,
pub public_address: Option<String>,
#[serde(default)]
#[serde(skip_serializing_if = "is_false")]
pub expect_proxy: bool,
Expand Down

0 comments on commit 8d6eb42

Please sign in to comment.