aquatic_udp: mio: update access list on SIGHUP instead of regularly

This commit is contained in:
Joakim Frostegård 2021-11-02 20:32:13 +01:00
parent e332ac3052
commit d922e5e680
5 changed files with 92 additions and 46 deletions

View file

@ -16,6 +16,7 @@ arc-swap = "1"
hashbrown = "0.11.2"
hex = "0.4"
indexmap = "1"
log = "0.4"
privdrop = "0.5"
rand = { version = "0.8", features = ["small_rng"] }
serde = { version = "1", features = ["derive"] }

View file

@ -75,17 +75,31 @@ impl AccessList {
}
pub trait AccessListQuery {
fn update_from_path(&self, path: &PathBuf) -> anyhow::Result<()>;
fn update(&self, config: &AccessListConfig);
fn allows(&self, list_mode: AccessListMode, info_hash_bytes: &[u8; 20]) -> bool;
}
pub type AccessListArcSwap = ArcSwap<AccessList>;
impl AccessListQuery for AccessListArcSwap {
fn update_from_path(&self, path: &PathBuf) -> anyhow::Result<()> {
self.store(Arc::new(AccessList::create_from_path(path)?));
Ok(())
fn update(&self, config: &AccessListConfig) {
match config.mode {
AccessListMode::White | AccessListMode::Black => {
match AccessList::create_from_path(&config.path) {
Ok(new) => {
self.store(Arc::new(new));
}
Err(err) => {
::log::error!("Updating access list failed: {:?}", err);
}
}
}
AccessListMode::Off => {
::log::error!(
"AccessListQuery::update_from_path called, but AccessListMode is Off"
);
}
}
}
fn allows(&self, mode: AccessListMode, info_hash_bytes: &[u8; 20]) -> bool {