Browse Source

protocol: add Filter::contains_flags

ipv6
Denis Drakhnia 7 months ago
parent
commit
5d73c9878e
  1. 6
      master/src/master_server.rs
  2. 9
      protocol/src/filter.rs

6
master/src/master_server.rs

@ -347,9 +347,9 @@ impl MasterServer {
self.send_server_list(from, p.filter.key, &self.filtered_servers)?; self.send_server_list(from, p.filter.key, &self.filtered_servers)?;
if !p.filter.flags_mask.contains(FilterFlags::NAT) // NOTE: If NAT is not set in a filter then by default the client is announced
|| p.filter.flags.contains(FilterFlags::NAT) // 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)?; self.send_client_to_nat_servers(from, &self.filtered_servers_nat)?;
} }

9
protocol/src/filter.rs

@ -186,6 +186,15 @@ impl Filter<'_> {
self.flags_mask.insert(flag); 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. /// Returns `true` if a server matches the filter.
pub fn matches(&self, _addr: SocketAddrV4, info: &ServerInfo) -> bool { pub fn matches(&self, _addr: SocketAddrV4, info: &ServerInfo) -> bool {
!((info.flags & self.flags_mask) != self.flags !((info.flags & self.flags_mask) != self.flags

Loading…
Cancel
Save