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};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
||||||
pub enum AccessListType {
|
pub enum AccessListMode {
|
||||||
Allow,
|
Allow,
|
||||||
Deny,
|
Deny,
|
||||||
Ignore,
|
Ignore,
|
||||||
|
|
@ -15,14 +15,14 @@ pub enum AccessListType {
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct AccessListConfig {
|
pub struct AccessListConfig {
|
||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
pub list_type: AccessListType,
|
pub mode: AccessListMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for AccessListConfig {
|
impl Default for AccessListConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
path: "".into(),
|
path: "".into(),
|
||||||
list_type: AccessListType::Ignore,
|
mode: AccessListMode::Ignore,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -54,11 +54,11 @@ impl AccessList {
|
||||||
Ok(())
|
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 {
|
match list_type {
|
||||||
AccessListType::Allow => self.0.contains(info_hash_bytes),
|
AccessListMode::Allow => self.0.contains(info_hash_bytes),
|
||||||
AccessListType::Deny => !self.0.contains(info_hash_bytes),
|
AccessListMode::Deny => !self.0.contains(info_hash_bytes),
|
||||||
AccessListType::Ignore => true,
|
AccessListMode::Ignore => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
|
||||||
use std::sync::{atomic::AtomicUsize, Arc};
|
use std::sync::{atomic::AtomicUsize, Arc};
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use aquatic_common::access_list::AccessListType;
|
use aquatic_common::access_list::AccessListMode;
|
||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
|
|
@ -125,7 +125,7 @@ impl TorrentMaps {
|
||||||
/// Remove disallowed and inactive torrents
|
/// Remove disallowed and inactive torrents
|
||||||
pub fn clean_with_access_list(
|
pub fn clean_with_access_list(
|
||||||
&mut self,
|
&mut self,
|
||||||
access_list_type: AccessListType,
|
access_list_type: AccessListMode,
|
||||||
access_list: &AccessList,
|
access_list: &AccessList,
|
||||||
now: Instant,
|
now: Instant,
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ use rand::{
|
||||||
Rng, SeedableRng,
|
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 aquatic_udp_protocol::*;
|
||||||
|
|
||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
@ -125,8 +125,8 @@ pub fn run_request_worker(
|
||||||
|
|
||||||
// Check announce requests for allowed info hashes
|
// Check announce requests for allowed info hashes
|
||||||
|
|
||||||
match config.access_list.list_type {
|
match config.access_list.mode {
|
||||||
access_list_type @ (AccessListType::Allow | AccessListType::Deny) => {
|
access_list_type @ (AccessListMode::Allow | AccessListMode::Deny) => {
|
||||||
let access_list: MutexGuard<AccessList> = state.access_list.lock();
|
let access_list: MutexGuard<AccessList> = state.access_list.lock();
|
||||||
|
|
||||||
announce_requests.retain(|(request, src)| {
|
announce_requests.retain(|(request, src)| {
|
||||||
|
|
@ -144,7 +144,7 @@ pub fn run_request_worker(
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
AccessListType::Ignore => {}
|
AccessListMode::Ignore => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle announce and scrape requests
|
// Handle announce and scrape requests
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use std::thread::Builder;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use aquatic_common::access_list::AccessListType;
|
use aquatic_common::access_list::AccessListMode;
|
||||||
use crossbeam_channel::unbounded;
|
use crossbeam_channel::unbounded;
|
||||||
use privdrop::PrivDrop;
|
use privdrop::PrivDrop;
|
||||||
|
|
||||||
|
|
@ -24,11 +24,11 @@ pub const APP_NAME: &str = "aquatic_udp: UDP BitTorrent tracker";
|
||||||
pub fn run(config: Config) -> ::anyhow::Result<()> {
|
pub fn run(config: Config) -> ::anyhow::Result<()> {
|
||||||
let state = State::default();
|
let state = State::default();
|
||||||
|
|
||||||
match config.access_list.list_type {
|
match config.access_list.mode {
|
||||||
AccessListType::Allow | AccessListType::Deny => {
|
AccessListMode::Allow | AccessListMode::Deny => {
|
||||||
state.access_list.lock().update_from_path(&config.access_list.path)?;
|
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())?;
|
let num_bound_sockets = start_workers(config.clone(), state.clone())?;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use std::time::Instant;
|
||||||
|
|
||||||
use histogram::Histogram;
|
use histogram::Histogram;
|
||||||
|
|
||||||
use aquatic_common::access_list::AccessListType;
|
use aquatic_common::access_list::AccessListMode;
|
||||||
|
|
||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
|
|
@ -18,8 +18,8 @@ pub fn clean_connections_and_torrents(config: &Config, state: &State) {
|
||||||
connections.shrink_to_fit();
|
connections.shrink_to_fit();
|
||||||
}
|
}
|
||||||
|
|
||||||
match config.access_list.list_type {
|
match config.access_list.mode {
|
||||||
AccessListType::Allow | AccessListType::Deny => {
|
AccessListMode::Allow | AccessListMode::Deny => {
|
||||||
let mut access_list = state.access_list.lock();
|
let mut access_list = state.access_list.lock();
|
||||||
|
|
||||||
if let Err(err) = access_list.update_from_path(&config.access_list.path) {
|
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(
|
state.torrents.lock().clean_with_access_list(
|
||||||
config.access_list.list_type,
|
config.access_list.mode,
|
||||||
&access_list,
|
&access_list,
|
||||||
now,
|
now,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
AccessListType::Ignore => {
|
AccessListMode::Ignore => {
|
||||||
state.torrents.lock().clean(now);
|
state.torrents.lock().clean(now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue