mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 02:35:31 +00:00
aquatic_http access list: use in torrent cleaning, do periodic updates
This commit is contained in:
parent
7fec41099b
commit
10fe014c03
3 changed files with 29 additions and 9 deletions
|
|
@ -40,7 +40,7 @@ pub fn run(config: Config) -> anyhow::Result<()> {
|
||||||
loop {
|
loop {
|
||||||
::std::thread::sleep(Duration::from_secs(config.cleaning.interval));
|
::std::thread::sleep(Duration::from_secs(config.cleaning.interval));
|
||||||
|
|
||||||
tasks::clean_torrents(&state);
|
tasks::clean_torrents(&config, &state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,40 @@
|
||||||
use std::time::Instant;
|
use std::{ops::DerefMut, time::Instant};
|
||||||
|
|
||||||
use histogram::Histogram;
|
use histogram::Histogram;
|
||||||
|
|
||||||
use crate::common::*;
|
use aquatic_common::access_list::{AccessList, AccessListMode};
|
||||||
|
|
||||||
pub fn clean_torrents(state: &State) {
|
use crate::{common::*, config::Config};
|
||||||
|
|
||||||
|
pub fn clean_torrents(config: &Config, state: &State) {
|
||||||
let mut torrent_maps = state.torrent_maps.lock();
|
let mut torrent_maps = state.torrent_maps.lock();
|
||||||
|
let torrent_maps = torrent_maps.deref_mut();
|
||||||
|
|
||||||
clean_torrent_map(&mut torrent_maps.ipv4);
|
match config.access_list.mode {
|
||||||
clean_torrent_map(&mut torrent_maps.ipv6);
|
AccessListMode::Require | AccessListMode::Forbid => {
|
||||||
|
if let Err(err) = torrent_maps.access_list.update_from_path(&config.access_list.path) {
|
||||||
|
::log::error!("Couldn't update access list: {:?}", err);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
AccessListMode::Ignore => { }
|
||||||
|
}
|
||||||
|
|
||||||
|
clean_torrent_map(config, &torrent_maps.access_list, &mut torrent_maps.ipv4);
|
||||||
|
clean_torrent_map(config, &torrent_maps.access_list, &mut torrent_maps.ipv6);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clean_torrent_map<I: Ip>(torrent_map: &mut TorrentMap<I>) {
|
fn clean_torrent_map<I: Ip>(
|
||||||
|
config: &Config,
|
||||||
|
access_list: &AccessList,
|
||||||
|
torrent_map: &mut TorrentMap<I>,
|
||||||
|
) {
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
|
|
||||||
torrent_map.retain(|_, torrent_data| {
|
torrent_map.retain(|info_hash, torrent_data| {
|
||||||
|
if !access_list.allows(config.access_list.mode, &info_hash.0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
let num_seeders = &mut torrent_data.num_seeders;
|
let num_seeders = &mut torrent_data.num_seeders;
|
||||||
let num_leechers = &mut torrent_data.num_leechers;
|
let num_leechers = &mut torrent_data.num_leechers;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ pub struct FailureResponse {
|
||||||
impl FailureResponse {
|
impl FailureResponse {
|
||||||
pub fn new(reason: &str) -> Self {
|
pub fn new(reason: &str) -> Self {
|
||||||
Self {
|
Self {
|
||||||
failure_reason: reason.into()
|
failure_reason: reason.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue