Skip to content

Commit

Permalink
field active on HttpsListenerConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed Apr 3, 2023
1 parent 8e5e9ce commit 65b01e8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
4 changes: 2 additions & 2 deletions bin/src/ctl/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn print_listeners(listeners_list: ListenersList) {

println!("\nHTTPS LISTENERS\n================");

for (_, (https_listener, activated)) in listeners_list.https_listeners.iter() {
for (_, https_listener) in listeners_list.https_listeners.iter() {
let mut table = Table::new();
table.set_format(*prettytable::format::consts::FORMAT_BOX_CHARS);
let mut tls_versions = String::new();
Expand Down Expand Up @@ -78,7 +78,7 @@ pub fn print_listeners(listeners_list: ListenersList) {
table.add_row(row!["back timeout", https_listener.back_timeout,]);
table.add_row(row!["connect timeout", https_listener.connect_timeout,]);
table.add_row(row!["request timeout", https_listener.request_timeout,]);
table.add_row(row!["activated", activated]);
table.add_row(row!["activated", https_listener.active]);
table.printstd();
}

Expand Down
1 change: 1 addition & 0 deletions command/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ impl ListenerBuilder {
cipher_suites,
signature_algorithms,
groups_list,
active: false,
};

Ok(https_listener_config)
Expand Down
4 changes: 3 additions & 1 deletion command/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ impl Backend {
pub struct ListenersList {
/// address -> (listener_config, activated)
pub http_listeners: HashMap<String, (HttpListenerConfig, bool)>,
pub https_listeners: HashMap<String, (HttpsListenerConfig, bool)>,
pub https_listeners: HashMap<String, HttpsListenerConfig>,
pub tcp_listeners: HashMap<String, TcpListenerConfig>,
}

Expand Down Expand Up @@ -385,6 +385,8 @@ pub struct HttpsListenerConfig {
pub connect_timeout: u32,
/// max time to send a complete request
pub request_timeout: u32,
/// should default to false
pub active: bool,
}

/// details of an TCP listener, sent by the main process to the worker
Expand Down
43 changes: 25 additions & 18 deletions command/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub struct ConfigState {
pub backends: BTreeMap<ClusterId, Vec<Backend>>,
/// the bool indicates if it is active or not
pub http_listeners: HashMap<String, (HttpListenerConfig, bool)>,
pub https_listeners: HashMap<String, (HttpsListenerConfig, bool)>,
pub https_listeners: HashMap<String, HttpsListenerConfig>,
pub tcp_listeners: HashMap<String, TcpListenerConfig>,
/// indexed by (address, hostname, path)
pub http_fronts: BTreeMap<RouteKey, HttpFrontend>,
Expand Down Expand Up @@ -168,7 +168,7 @@ impl ConfigState {

fn add_https_listener(&mut self, listener: &HttpsListenerConfig) -> anyhow::Result<()> {
match self.https_listeners.entry(listener.address.clone()) {
HashMapEntry::Vacant(vacant_entry) => vacant_entry.insert((listener.clone(), false)),
HashMapEntry::Vacant(vacant_entry) => vacant_entry.insert(listener.clone()),
HashMapEntry::Occupied(_) => {
bail!("The entry is occupied for address {}", listener.address)
}
Expand Down Expand Up @@ -231,7 +231,7 @@ impl ConfigState {
if self
.https_listeners
.get_mut(&activate.address)
.map(|t| t.1 = true)
.map(|listener| listener.active = true)
.is_none()
{
bail!("No https listener found with address {}", activate.address)
Expand Down Expand Up @@ -267,7 +267,7 @@ impl ConfigState {
if self
.https_listeners
.get_mut(&deactivate.address)
.map(|t| t.1 = false)
.map(|listener| listener.active = false)
.is_none()
{
bail!(
Expand Down Expand Up @@ -499,9 +499,9 @@ impl ConfigState {
}
}

for &(ref listener, active) in self.https_listeners.values() {
for listener in self.https_listeners.values() {
v.push(Request::AddHttpsListener(listener.clone()));
if active {
if listener.active {
v.push(Request::ActivateListener(ActivateListener {
address: listener.address.clone(),
proxy: ListenerType::HTTPS,
Expand Down Expand Up @@ -577,7 +577,7 @@ impl ConfigState {
for front in self
.https_listeners
.iter()
.filter(|(_, t)| t.1)
.filter(|(_, listener)| listener.active)
.map(|(k, _)| k)
{
v.push(Request::ActivateListener(ActivateListener {
Expand Down Expand Up @@ -680,7 +680,7 @@ impl ConfigState {
}

for address in removed_https_listeners {
if self.https_listeners[*address].1 {
if self.https_listeners[*address].active {
v.push(Request::DeactivateListener(DeactivateListener {
address: address.to_string(),
proxy: ListenerType::HTTPS,
Expand All @@ -696,10 +696,10 @@ impl ConfigState {

for address in added_https_listeners.clone() {
v.push(Request::AddHttpsListener(
other.https_listeners[*address].0.clone(),
other.https_listeners[*address].clone(),
));

if other.https_listeners[*address].1 {
if other.https_listeners[*address].active {
v.push(Request::ActivateListener(ActivateListener {
address: address.to_string(),
proxy: ListenerType::HTTPS,
Expand All @@ -717,8 +717,10 @@ impl ConfigState {
address: addr.to_string(),
proxy: ListenerType::TCP,
}));

v.push(Request::AddTcpListener(their_listener.clone()));
// any added listener should be unactive
let mut listener_to_add = their_listener.clone();
listener_to_add.active = false;
v.push(Request::AddTcpListener(listener_to_add));
}

if my_listener.active && !their_listener.active {
Expand Down Expand Up @@ -769,27 +771,29 @@ impl ConfigState {
}

for addr in my_https_listeners.intersection(&their_https_listeners) {
let (my_listener, my_active) = &self.https_listeners[*addr];
let (their_listener, their_active) = &other.https_listeners[*addr];
let my_listener = &self.https_listeners[*addr];
let their_listener = &other.https_listeners[*addr];

if my_listener != their_listener {
v.push(Request::RemoveListener(RemoveListener {
address: addr.to_string(),
proxy: ListenerType::HTTPS,
}));

v.push(Request::AddHttpsListener(their_listener.clone()));
// any added listener should be unactive
let mut listener_to_add = their_listener.clone();
listener_to_add.active = false;
v.push(Request::AddHttpsListener(listener_to_add));
}

if *my_active && !*their_active {
if my_listener.active && !their_listener.active {
v.push(Request::DeactivateListener(DeactivateListener {
address: addr.to_string(),
proxy: ListenerType::HTTPS,
to_scm: false,
}));
}

if !*my_active && *their_active {
if !my_listener.active && their_listener.active {
v.push(Request::ActivateListener(ActivateListener {
address: addr.to_string(),
proxy: ListenerType::HTTPS,
Expand Down Expand Up @@ -1657,6 +1661,7 @@ mod tests {
request_timeout: 10,
back_timeout: 30,
connect_timeout: 3,
active: false,
}))
.expect("Could not execute request");
state
Expand Down Expand Up @@ -1720,6 +1725,7 @@ mod tests {
request_timeout: 10,
back_timeout: 30,
connect_timeout: 3,
active: false,
}))
.expect("Could not execute request");
state2
Expand Down Expand Up @@ -1793,6 +1799,7 @@ mod tests {
request_timeout: 10,
back_timeout: 30,
connect_timeout: 3,
active: false,
}),
];

Expand Down

0 comments on commit 65b01e8

Please sign in to comment.