mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
Move fn update_access_list to aquatic_common
This commit is contained in:
parent
446fd0b1f4
commit
fa3b6bb259
5 changed files with 32 additions and 80 deletions
|
|
@ -107,6 +107,26 @@ pub fn create_access_list_cache(arc_swap: &Arc<AccessListArcSwap>) -> AccessList
|
|||
Cache::from(Arc::clone(arc_swap))
|
||||
}
|
||||
|
||||
pub fn update_access_list(
|
||||
config: &AccessListConfig,
|
||||
access_list: &Arc<AccessListArcSwap>,
|
||||
) -> anyhow::Result<()> {
|
||||
if config.mode.is_on() {
|
||||
match access_list.update(config) {
|
||||
Ok(()) => {
|
||||
::log::info!("Access list updated")
|
||||
}
|
||||
Err(err) => {
|
||||
::log::error!("Updating access list failed: {:#}", err);
|
||||
|
||||
return Err(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn parse_info_hash(line: &str) -> anyhow::Result<[u8; 20]> {
|
||||
let mut bytes = [0u8; 20];
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use std::{
|
|||
};
|
||||
|
||||
use aquatic_common::{
|
||||
access_list::AccessListQuery, privileges::drop_privileges_after_socket_binding,
|
||||
access_list::update_access_list, privileges::drop_privileges_after_socket_binding,
|
||||
};
|
||||
use common::{State, TlsConfig};
|
||||
use glommio::{channels::channel_mesh::MeshBuilder, prelude::*};
|
||||
|
|
@ -31,7 +31,7 @@ pub fn run(config: Config) -> ::anyhow::Result<()> {
|
|||
|
||||
let state = State::default();
|
||||
|
||||
update_access_list(&config, &state)?;
|
||||
update_access_list(&config.access_list, &state.access_list)?;
|
||||
|
||||
let mut signals = Signals::new(::std::iter::once(SIGUSR1))?;
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ pub fn run(config: Config) -> ::anyhow::Result<()> {
|
|||
for signal in &mut signals {
|
||||
match signal {
|
||||
SIGUSR1 => {
|
||||
let _ = update_access_list(&config, &state);
|
||||
let _ = update_access_list(&config.access_list, &state.access_list);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
|
@ -166,20 +166,3 @@ fn create_tls_config(config: &Config) -> anyhow::Result<TlsConfig> {
|
|||
|
||||
Ok(tls_config)
|
||||
}
|
||||
|
||||
fn update_access_list(config: &Config, state: &State) -> anyhow::Result<()> {
|
||||
if config.access_list.mode.is_on() {
|
||||
match state.access_list.update(&config.access_list) {
|
||||
Ok(()) => {
|
||||
::log::info!("Access list updated")
|
||||
}
|
||||
Err(err) => {
|
||||
::log::error!("Updating access list failed: {:#}", err);
|
||||
|
||||
return Err(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use std::sync::{atomic::AtomicUsize, Arc};
|
||||
|
||||
use aquatic_common::access_list::AccessListQuery;
|
||||
use aquatic_common::access_list::update_access_list;
|
||||
use aquatic_common::privileges::drop_privileges_after_socket_binding;
|
||||
use glommio::channels::channel_mesh::MeshBuilder;
|
||||
use glommio::prelude::*;
|
||||
|
|
@ -26,7 +26,7 @@ pub fn run(config: Config) -> ::anyhow::Result<()> {
|
|||
|
||||
let state = State::default();
|
||||
|
||||
update_access_list(&config, &state)?;
|
||||
update_access_list(&config.access_list, &state.access_list)?;
|
||||
|
||||
let mut signals = Signals::new(::std::iter::once(SIGUSR1))?;
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ pub fn run(config: Config) -> ::anyhow::Result<()> {
|
|||
for signal in &mut signals {
|
||||
match signal {
|
||||
SIGUSR1 => {
|
||||
let _ = update_access_list(&config, &state);
|
||||
let _ = update_access_list(&config.access_list, &state.access_list);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
|
@ -128,20 +128,3 @@ pub fn run_inner(config: Config, state: State) -> anyhow::Result<()> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update_access_list(config: &Config, state: &State) -> anyhow::Result<()> {
|
||||
if config.access_list.mode.is_on() {
|
||||
match state.access_list.update(&config.access_list) {
|
||||
Ok(()) => {
|
||||
::log::info!("Access list updated")
|
||||
}
|
||||
Err(err) => {
|
||||
::log::error!("Updating access list failed: {:#}", err);
|
||||
|
||||
return Err(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use anyhow::Context;
|
|||
use aquatic_common::privileges::drop_privileges_after_socket_binding;
|
||||
use crossbeam_channel::unbounded;
|
||||
|
||||
use aquatic_common::access_list::AccessListQuery;
|
||||
use aquatic_common::access_list::update_access_list;
|
||||
use signal_hook::consts::SIGUSR1;
|
||||
use signal_hook::iterator::Signals;
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ pub fn run(config: Config) -> ::anyhow::Result<()> {
|
|||
|
||||
let state = State::default();
|
||||
|
||||
update_access_list(&config, &state)?;
|
||||
update_access_list(&config.access_list, &state.access_list)?;
|
||||
|
||||
let mut signals = Signals::new(::std::iter::once(SIGUSR1))?;
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ pub fn run(config: Config) -> ::anyhow::Result<()> {
|
|||
for signal in &mut signals {
|
||||
match signal {
|
||||
SIGUSR1 => {
|
||||
let _ = update_access_list(&config, &state);
|
||||
let _ = update_access_list(&config.access_list, &state.access_list);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
|
@ -146,20 +146,3 @@ pub fn run_inner(config: Config, state: State) -> ::anyhow::Result<()> {
|
|||
state.torrents.lock().clean(&config, &state.access_list);
|
||||
}
|
||||
}
|
||||
|
||||
fn update_access_list(config: &Config, state: &State) -> anyhow::Result<()> {
|
||||
if config.access_list.mode.is_on() {
|
||||
match state.access_list.update(&config.access_list) {
|
||||
Ok(()) => {
|
||||
::log::info!("Access list updated")
|
||||
}
|
||||
Err(err) => {
|
||||
::log::error!("Updating access list failed: {:#}", err);
|
||||
|
||||
return Err(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use std::{
|
|||
};
|
||||
|
||||
use aquatic_common::{
|
||||
access_list::AccessListQuery, privileges::drop_privileges_after_socket_binding,
|
||||
access_list::update_access_list, privileges::drop_privileges_after_socket_binding,
|
||||
};
|
||||
use common::{State, TlsConfig};
|
||||
use glommio::{channels::channel_mesh::MeshBuilder, prelude::*};
|
||||
|
|
@ -31,7 +31,7 @@ pub fn run(config: Config) -> ::anyhow::Result<()> {
|
|||
|
||||
let state = State::default();
|
||||
|
||||
update_access_list(&config, &state)?;
|
||||
update_access_list(&config.access_list, &state.access_list)?;
|
||||
|
||||
let mut signals = Signals::new(::std::iter::once(SIGUSR1))?;
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ pub fn run(config: Config) -> ::anyhow::Result<()> {
|
|||
for signal in &mut signals {
|
||||
match signal {
|
||||
SIGUSR1 => {
|
||||
let _ = update_access_list(&config, &state);
|
||||
let _ = update_access_list(&config.access_list, &state.access_list);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
|
@ -166,20 +166,3 @@ fn create_tls_config(config: &Config) -> anyhow::Result<TlsConfig> {
|
|||
|
||||
Ok(tls_config)
|
||||
}
|
||||
|
||||
fn update_access_list(config: &Config, state: &State) -> anyhow::Result<()> {
|
||||
if config.access_list.mode.is_on() {
|
||||
match state.access_list.update(&config.access_list) {
|
||||
Ok(()) => {
|
||||
::log::info!("Access list updated")
|
||||
}
|
||||
Err(err) => {
|
||||
::log::error!("Updating access list failed: {:#}", err);
|
||||
|
||||
return Err(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue