This commit is contained in:
2026-04-25 18:10:40 +02:00
parent f90ca40202
commit b034fdf1c4
16 changed files with 1088 additions and 52 deletions

View File

@@ -139,11 +139,14 @@ impl WsManager {
let endpoint_names = self.endpoint_names_for_role(role).await;
let mut started_count = 0_usize;
for endpoint_name in endpoint_names {
let start_result = self.start_endpoint(endpoint_name.as_str()).await;
if let Err(error) = start_result {
return Err(error);
let start_result = self.start_endpoint_inner(endpoint_name.as_str()).await;
let started = match start_result {
Ok(started) => started,
Err(error) => return Err(error),
};
if started {
started_count += 1;
}
started_count += 1;
}
Ok(started_count)
}
@@ -153,11 +156,14 @@ impl WsManager {
let endpoint_names = self.endpoint_names_for_role(role).await;
let mut stopped_count = 0_usize;
for endpoint_name in endpoint_names {
let stop_result = self.stop_endpoint(endpoint_name.as_str()).await;
if let Err(error) = stop_result {
return Err(error);
let stop_result = self.stop_endpoint_inner(endpoint_name.as_str()).await;
let stopped = match stop_result {
Ok(stopped) => stopped,
Err(error) => return Err(error),
};
if stopped {
stopped_count += 1;
}
stopped_count += 1;
}
Ok(stopped_count)
}
@@ -172,8 +178,7 @@ impl WsManager {
}
}
/// Starts one managed endpoint.
pub async fn start_endpoint(&self, endpoint_name: &str) -> Result<(), crate::KbError> {
async fn start_endpoint_inner(&self, endpoint_name: &str) -> Result<bool, crate::KbError> {
let client_option = self.client(endpoint_name).await;
let client = match client_option {
Some(client) => client,
@@ -184,6 +189,12 @@ impl WsManager {
)));
}
};
let state = client.connection_state().await;
if state == crate::KbConnectionState::Connected
|| state == crate::KbConnectionState::Connecting
{
return Ok(false);
}
let sender_option = {
let sender_guard = self.detection_relay_sender.lock().await;
sender_guard.clone()
@@ -195,11 +206,19 @@ impl WsManager {
if let Err(error) = connect_result {
return Err(error);
}
Ok(())
Ok(true)
}
/// Stops one managed endpoint.
pub async fn stop_endpoint(&self, endpoint_name: &str) -> Result<(), crate::KbError> {
/// Starts one managed endpoint.
pub async fn start_endpoint(&self, endpoint_name: &str) -> Result<(), crate::KbError> {
let start_result = self.start_endpoint_inner(endpoint_name).await;
match start_result {
Ok(_) => Ok(()),
Err(error) => Err(error),
}
}
async fn stop_endpoint_inner(&self, endpoint_name: &str) -> Result<bool, crate::KbError> {
let client_option = self.client(endpoint_name).await;
let client = match client_option {
Some(client) => client,
@@ -210,12 +229,27 @@ impl WsManager {
)));
}
};
let state = client.connection_state().await;
if state == crate::KbConnectionState::Disconnected
|| state == crate::KbConnectionState::Disconnecting
{
return Ok(false);
}
client.clear_detection_notification_forwarder().await;
let disconnect_result = client.disconnect().await;
if let Err(error) = disconnect_result {
return Err(error);
}
Ok(())
Ok(true)
}
/// Stops one managed endpoint.
pub async fn stop_endpoint(&self, endpoint_name: &str) -> Result<(), crate::KbError> {
let stop_result = self.stop_endpoint_inner(endpoint_name).await;
match stop_result {
Ok(_) => Ok(()),
Err(error) => Err(error),
}
}
/// Starts all managed endpoints.
@@ -223,11 +257,14 @@ impl WsManager {
let endpoint_names = self.endpoint_names().await;
let mut started_count = 0_usize;
for endpoint_name in endpoint_names {
let start_result = self.start_endpoint(endpoint_name.as_str()).await;
if let Err(error) = start_result {
return Err(error);
let start_result = self.start_endpoint_inner(endpoint_name.as_str()).await;
let started = match start_result {
Ok(started) => started,
Err(error) => return Err(error),
};
if started {
started_count += 1;
}
started_count += 1;
}
Ok(started_count)
}
@@ -237,11 +274,14 @@ impl WsManager {
let endpoint_names = self.endpoint_names().await;
let mut stopped_count = 0_usize;
for endpoint_name in endpoint_names {
let stop_result = self.stop_endpoint(endpoint_name.as_str()).await;
if let Err(error) = stop_result {
return Err(error);
let stop_result = self.stop_endpoint_inner(endpoint_name.as_str()).await;
let stopped = match stop_result {
Ok(stopped) => stopped,
Err(error) => return Err(error),
};
if stopped {
stopped_count += 1;
}
stopped_count += 1;
}
Ok(stopped_count)
}