From f0846e3128f4331dd65e4235dbef5f5a27847ded Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Fri, 15 Oct 2021 21:55:01 +0200 Subject: [PATCH] aquatic_common: rename AccessListType to AccessListMode --- aquatic_common/src/access_list.rs | 14 +++++++------- aquatic_udp/src/lib/common.rs | 4 ++-- aquatic_udp/src/lib/handlers.rs | 8 ++++---- aquatic_udp/src/lib/lib.rs | 8 ++++---- aquatic_udp/src/lib/tasks.rs | 10 +++++----- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/aquatic_common/src/access_list.rs b/aquatic_common/src/access_list.rs index 377f8eb..ca57155 100644 --- a/aquatic_common/src/access_list.rs +++ b/aquatic_common/src/access_list.rs @@ -6,7 +6,7 @@ use hashbrown::HashSet; use serde::{Deserialize, Serialize}; #[derive(Clone, Copy, Debug, Serialize, Deserialize)] -pub enum AccessListType { +pub enum AccessListMode { Allow, Deny, Ignore, @@ -15,14 +15,14 @@ pub enum AccessListType { #[derive(Clone, Debug, Serialize, Deserialize)] pub struct AccessListConfig { pub path: PathBuf, - pub list_type: AccessListType, + pub mode: AccessListMode, } impl Default for AccessListConfig { fn default() -> Self { Self { path: "".into(), - list_type: AccessListType::Ignore, + mode: AccessListMode::Ignore, } } } @@ -54,11 +54,11 @@ impl AccessList { Ok(()) } - pub fn allows(&self, list_type: AccessListType, info_hash_bytes: &[u8; 20]) -> bool { + pub fn allows(&self, list_type: AccessListMode, 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, + AccessListMode::Allow => self.0.contains(info_hash_bytes), + AccessListMode::Deny => !self.0.contains(info_hash_bytes), + AccessListMode::Ignore => true, } } } diff --git a/aquatic_udp/src/lib/common.rs b/aquatic_udp/src/lib/common.rs index 99a19fc..ec78716 100644 --- a/aquatic_udp/src/lib/common.rs +++ b/aquatic_udp/src/lib/common.rs @@ -3,7 +3,7 @@ use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}; use std::sync::{atomic::AtomicUsize, Arc}; use std::time::Instant; -use aquatic_common::access_list::AccessListType; +use aquatic_common::access_list::AccessListMode; use hashbrown::HashMap; use indexmap::IndexMap; use parking_lot::Mutex; @@ -125,7 +125,7 @@ impl TorrentMaps { /// Remove disallowed and inactive torrents pub fn clean_with_access_list( &mut self, - access_list_type: AccessListType, + access_list_type: AccessListMode, access_list: &AccessList, now: Instant, ) { diff --git a/aquatic_udp/src/lib/handlers.rs b/aquatic_udp/src/lib/handlers.rs index 3a75668..0b93786 100644 --- a/aquatic_udp/src/lib/handlers.rs +++ b/aquatic_udp/src/lib/handlers.rs @@ -9,7 +9,7 @@ use rand::{ Rng, SeedableRng, }; -use aquatic_common::{convert_ipv4_mapped_ipv6, extract_response_peers, access_list::AccessListType}; +use aquatic_common::{convert_ipv4_mapped_ipv6, extract_response_peers, access_list::AccessListMode}; use aquatic_udp_protocol::*; use crate::common::*; @@ -125,8 +125,8 @@ pub fn run_request_worker( // Check announce requests for allowed info hashes - match config.access_list.list_type { - access_list_type @ (AccessListType::Allow | AccessListType::Deny) => { + match config.access_list.mode { + access_list_type @ (AccessListMode::Allow | AccessListMode::Deny) => { let access_list: MutexGuard = state.access_list.lock(); announce_requests.retain(|(request, src)| { @@ -144,7 +144,7 @@ pub fn run_request_worker( true }); } - AccessListType::Ignore => {} + AccessListMode::Ignore => {} }; // Handle announce and scrape requests diff --git a/aquatic_udp/src/lib/lib.rs b/aquatic_udp/src/lib/lib.rs index e406d9a..04383ad 100644 --- a/aquatic_udp/src/lib/lib.rs +++ b/aquatic_udp/src/lib/lib.rs @@ -6,7 +6,7 @@ use std::thread::Builder; use std::time::Duration; use anyhow::Context; -use aquatic_common::access_list::AccessListType; +use aquatic_common::access_list::AccessListMode; use crossbeam_channel::unbounded; use privdrop::PrivDrop; @@ -24,11 +24,11 @@ pub const APP_NAME: &str = "aquatic_udp: UDP BitTorrent tracker"; pub fn run(config: Config) -> ::anyhow::Result<()> { let state = State::default(); - match config.access_list.list_type { - AccessListType::Allow | AccessListType::Deny => { + match config.access_list.mode { + AccessListMode::Allow | AccessListMode::Deny => { state.access_list.lock().update_from_path(&config.access_list.path)?; }, - AccessListType::Ignore => {}, + AccessListMode::Ignore => {}, } let num_bound_sockets = start_workers(config.clone(), state.clone())?; diff --git a/aquatic_udp/src/lib/tasks.rs b/aquatic_udp/src/lib/tasks.rs index e8e1aa1..97df21c 100644 --- a/aquatic_udp/src/lib/tasks.rs +++ b/aquatic_udp/src/lib/tasks.rs @@ -3,7 +3,7 @@ use std::time::Instant; use histogram::Histogram; -use aquatic_common::access_list::AccessListType; +use aquatic_common::access_list::AccessListMode; use crate::common::*; use crate::config::Config; @@ -18,8 +18,8 @@ pub fn clean_connections_and_torrents(config: &Config, state: &State) { connections.shrink_to_fit(); } - match config.access_list.list_type { - AccessListType::Allow | AccessListType::Deny => { + match config.access_list.mode { + AccessListMode::Allow | AccessListMode::Deny => { let mut access_list = state.access_list.lock(); if let Err(err) = access_list.update_from_path(&config.access_list.path) { @@ -27,12 +27,12 @@ pub fn clean_connections_and_torrents(config: &Config, state: &State) { } state.torrents.lock().clean_with_access_list( - config.access_list.list_type, + config.access_list.mode, &access_list, now, ); } - AccessListType::Ignore => { + AccessListMode::Ignore => { state.torrents.lock().clean(now); } }