From 5d73c9878e4b6b9ef0870e1d6255620d28855ab9 Mon Sep 17 00:00:00 2001 From: Denis Drakhnia Date: Fri, 3 May 2024 09:47:24 +0300 Subject: [PATCH] protocol: add Filter::contains_flags --- master/src/master_server.rs | 6 +++--- protocol/src/filter.rs | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/master/src/master_server.rs b/master/src/master_server.rs index 241eb11..27dbd69 100644 --- a/master/src/master_server.rs +++ b/master/src/master_server.rs @@ -347,9 +347,9 @@ impl MasterServer { self.send_server_list(from, p.filter.key, &self.filtered_servers)?; - if !p.filter.flags_mask.contains(FilterFlags::NAT) - || p.filter.flags.contains(FilterFlags::NAT) - { + // NOTE: If NAT is not set in a filter then by default the client is announced + // to filtered servers behind NAT. + if p.filter.contains_flags(FilterFlags::NAT).unwrap_or(true) { self.send_client_to_nat_servers(from, &self.filtered_servers_nat)?; } diff --git a/protocol/src/filter.rs b/protocol/src/filter.rs index 5c600e8..5194f8f 100644 --- a/protocol/src/filter.rs +++ b/protocol/src/filter.rs @@ -186,6 +186,15 @@ impl Filter<'_> { self.flags_mask.insert(flag); } + /// Test if all `other` flags are set in `flags_mask` and in `flags`. + pub fn contains_flags(&self, other: FilterFlags) -> Option { + if self.flags_mask.contains(other) { + Some(self.flags.contains(other)) + } else { + None + } + } + /// Returns `true` if a server matches the filter. pub fn matches(&self, _addr: SocketAddrV4, info: &ServerInfo) -> bool { !((info.flags & self.flags_mask) != self.flags