protocol: add Filter::contains_flags

This commit is contained in:
Denis Drakhnia 2024-05-03 09:47:24 +03:00
parent c0ea55511a
commit 5d73c9878e
2 changed files with 12 additions and 3 deletions

View File

@ -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)?;
}

View File

@ -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<bool> {
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