mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
aquatic_udp: mio: update access list on SIGHUP instead of regularly
This commit is contained in:
parent
e332ac3052
commit
d922e5e680
5 changed files with 92 additions and 46 deletions
|
|
@ -9,15 +9,17 @@ use anyhow::Context;
|
|||
use aquatic_common::privileges::drop_privileges_after_socket_binding;
|
||||
use crossbeam_channel::unbounded;
|
||||
|
||||
use aquatic_common::access_list::AccessListQuery;
|
||||
use signal_hook::consts::SIGHUP;
|
||||
use signal_hook::iterator::Signals;
|
||||
|
||||
use crate::config::Config;
|
||||
|
||||
pub mod common;
|
||||
pub mod handlers;
|
||||
pub mod network;
|
||||
pub mod tasks;
|
||||
|
||||
use aquatic_common::access_list::{AccessListArcSwap, AccessListMode, AccessListQuery};
|
||||
|
||||
use crate::config::Config;
|
||||
|
||||
use common::State;
|
||||
|
||||
pub fn run(config: Config) -> ::anyhow::Result<()> {
|
||||
|
|
@ -27,38 +29,42 @@ pub fn run(config: Config) -> ::anyhow::Result<()> {
|
|||
});
|
||||
}
|
||||
|
||||
let mut signals = Signals::new(::std::iter::once(SIGHUP))?;
|
||||
|
||||
let state = State::default();
|
||||
|
||||
update_access_list(&config, &state.access_list);
|
||||
{
|
||||
let config = config.clone();
|
||||
let state = state.clone();
|
||||
|
||||
::std::thread::spawn(move || run_inner(config, state));
|
||||
}
|
||||
|
||||
for signal in &mut signals {
|
||||
match signal {
|
||||
SIGHUP => {
|
||||
::log::info!("Updating access list");
|
||||
|
||||
state.access_list.update(&config.access_list);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn run_inner(config: Config, state: State) -> ::anyhow::Result<()> {
|
||||
if config.cpu_pinning.active {
|
||||
core_affinity::set_for_current(core_affinity::CoreId {
|
||||
id: config.cpu_pinning.offset,
|
||||
});
|
||||
}
|
||||
|
||||
state.access_list.update(&config.access_list);
|
||||
|
||||
let num_bound_sockets = Arc::new(AtomicUsize::new(0));
|
||||
|
||||
start_workers(config.clone(), state.clone(), num_bound_sockets.clone())?;
|
||||
|
||||
drop_privileges_after_socket_binding(
|
||||
&config.privileges,
|
||||
num_bound_sockets,
|
||||
config.socket_workers,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
loop {
|
||||
::std::thread::sleep(Duration::from_secs(config.cleaning.interval));
|
||||
|
||||
update_access_list(&config, &state.access_list);
|
||||
|
||||
state
|
||||
.torrents
|
||||
.lock()
|
||||
.clean(&config, state.access_list.load_full().deref());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn start_workers(
|
||||
config: Config,
|
||||
state: State,
|
||||
num_bound_sockets: Arc<AtomicUsize>,
|
||||
) -> ::anyhow::Result<()> {
|
||||
let (request_sender, request_receiver) = unbounded();
|
||||
let (response_sender, response_receiver) = unbounded();
|
||||
|
||||
|
|
@ -132,16 +138,19 @@ pub fn start_workers(
|
|||
.with_context(|| "spawn statistics worker")?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
drop_privileges_after_socket_binding(
|
||||
&config.privileges,
|
||||
num_bound_sockets,
|
||||
config.socket_workers,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
pub fn update_access_list(config: &Config, access_list: &Arc<AccessListArcSwap>) {
|
||||
match config.access_list.mode {
|
||||
AccessListMode::White | AccessListMode::Black => {
|
||||
if let Err(err) = access_list.update_from_path(&config.access_list.path) {
|
||||
::log::error!("Update access list from path: {:?}", err);
|
||||
}
|
||||
}
|
||||
AccessListMode::Off => {}
|
||||
loop {
|
||||
::std::thread::sleep(Duration::from_secs(config.cleaning.interval));
|
||||
|
||||
state
|
||||
.torrents
|
||||
.lock()
|
||||
.clean(&config, state.access_list.load_full().deref());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue