mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
aquatic_common: rename AccessListType to AccessListMode
This commit is contained in:
parent
60d183003d
commit
f0846e3128
5 changed files with 22 additions and 22 deletions
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -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<AccessList> = 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
|
||||
|
|
|
|||
|
|
@ -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())?;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue