aquatic_udp: simplify access list logic

This commit is contained in:
Joakim Frostegård 2021-10-15 02:30:49 +02:00
parent 8639f380f4
commit b5a2b81bd7
3 changed files with 59 additions and 75 deletions

View file

@ -9,7 +9,7 @@ use indexmap::IndexMap;
use rand::Rng;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub enum AccessListType {
Allow,
Deny,
@ -65,8 +65,18 @@ impl AccessList {
Ok(())
}
pub fn contains(&self, info_hash_bytes: &[u8; 20]) -> bool {
self.0.contains(info_hash_bytes)
pub fn allows(&self, list_type: AccessListType, info_hash_bytes: &[u8; 20]) -> bool {
match list_type {
AccessListType::Allow => {
self.0.contains(info_hash_bytes)
}
AccessListType::Deny => {
!self.0.contains(info_hash_bytes)
}
AccessListType::Ignore => {
true
}
}
}
}