chore(connlib): limit resource_update to resource changes (#5005)

This commit is contained in:
Gabi
2024-05-15 20:42:24 -03:00
committed by GitHub
parent 770bb3432e
commit a6e0cd4fbb
2 changed files with 14 additions and 4 deletions

View File

@@ -856,7 +856,9 @@ impl ClientState {
earliest(self.next_dns_refresh, self.node.poll_timeout())
}
pub fn handle_timeout(&mut self, now: Instant) {
/// Returns whether resources statuses have updated
pub fn handle_timeout(&mut self, now: Instant) -> bool {
let mut resources_updated = false;
self.node.handle_timeout(now);
match self.next_dns_refresh {
@@ -894,6 +896,7 @@ impl ClientState {
match event {
snownet::Event::ConnectionFailed(id) => {
self.cleanup_connected_gateway(&id);
resources_updated = true;
}
snownet::Event::NewIceCandidate {
connection,
@@ -915,9 +918,12 @@ impl ClientState {
}),
snownet::Event::ConnectionEstablished(id) => {
self.update_site_status_by_gateway(&id, Status::Online);
resources_updated = true;
}
}
}
resources_updated
}
fn update_site_status_by_gateway(&mut self, gateway_id: &GatewayId, status: Status) {

View File

@@ -118,9 +118,13 @@ where
self.device_read_buf.as_mut(),
)? {
Poll::Ready(io::Input::Timeout(timeout)) => {
self.role_state.handle_timeout(timeout);
self.callbacks
.on_update_resources(self.role_state.resources());
let resources_updated = self.role_state.handle_timeout(timeout);
if resources_updated {
self.callbacks
.on_update_resources(self.role_state.resources());
}
continue;
}
Poll::Ready(io::Input::Device(packet)) => {