From c856a72bca232e021cd97f2eac5eb4361465172c Mon Sep 17 00:00:00 2001 From: Lee Smet Date: Sun, 30 Mar 2025 11:32:46 +0200 Subject: [PATCH] Only return a writeguard for routes if there are routes Return None in case the entry is queried or not existing, as we semantically don't have routes in this case. This matches the implementatin of routes_mut on the WriteGuard Signed-off-by: Lee Smet --- mycelium/src/routing_table.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/mycelium/src/routing_table.rs b/mycelium/src/routing_table.rs index acc487d..c11cdd3 100644 --- a/mycelium/src/routing_table.rs +++ b/mycelium/src/routing_table.rs @@ -201,16 +201,20 @@ impl RoutingTable { .exact_match(subnet_address, subnet.prefix_len().into())? .clone(); - Some(WriteGuard { - routing_table: self, - // If we didn't find a route list in the route table we create a new empty list, - // therefore we immediately own it. - value, - exists: true, - subnet, - expired_route_entry_sink: self.expired_route_entry_sink.clone(), - cancellation_token: self.cancel_token.clone(), - }) + if matches!(*value, SubnetEntry::Exists { .. }) { + Some(WriteGuard { + routing_table: self, + // If we didn't find a route list in the route table we create a new empty list, + // therefore we immediately own it. + value, + exists: true, + subnet, + expired_route_entry_sink: self.expired_route_entry_sink.clone(), + cancellation_token: self.cancel_token.clone(), + }) + } else { + None + } } /// Adds a new [`Subnet`] to the `RoutingTable`. The returned [`WriteGuard`] can be used to