diff --git a/veilid-core/src/attachment_manager.rs b/veilid-core/src/attachment_manager.rs index 73e79209..8ff6cf52 100644 --- a/veilid-core/src/attachment_manager.rs +++ b/veilid-core/src/attachment_manager.rs @@ -81,24 +81,22 @@ impl AttachmentManager { health: &RoutingTableHealth, config: &VeilidConfigRoutingTable, ) -> AttachmentState { - if health.reliable_entry_count >= config.limit_over_attached.try_into().unwrap() { - return AttachmentState::OverAttached; + let reliable = health.reliable_entry_count; + let weak_limit = config.limit_attached_weak as usize; + + if reliable >= config.limit_over_attached as usize { + AttachmentState::OverAttached + } else if reliable >= config.limit_fully_attached as usize { + AttachmentState::FullyAttached + } else if reliable >= config.limit_attached_strong as usize { + AttachmentState::AttachedStrong + } else if reliable >= config.limit_attached_good as usize { + AttachmentState::AttachedGood + } else if reliable >= weak_limit || health.unreliable_entry_count >= weak_limit { + AttachmentState::AttachedWeak + } else { + AttachmentState::Attaching } - if health.reliable_entry_count >= config.limit_fully_attached.try_into().unwrap() { - return AttachmentState::FullyAttached; - } - if health.reliable_entry_count >= config.limit_attached_strong.try_into().unwrap() { - return AttachmentState::AttachedStrong; - } - if health.reliable_entry_count >= config.limit_attached_good.try_into().unwrap() { - return AttachmentState::AttachedGood; - } - if health.reliable_entry_count >= config.limit_attached_weak.try_into().unwrap() - || health.unreliable_entry_count >= config.limit_attached_weak.try_into().unwrap() - { - return AttachmentState::AttachedWeak; - } - AttachmentState::Attaching } /// Update attachment and network readiness state