access list: log when update fails; run cargo fmt

This commit is contained in:
Joakim Frostegård 2021-10-15 02:35:13 +02:00
parent b5a2b81bd7
commit 6cfa220097
4 changed files with 30 additions and 28 deletions

View file

@ -9,7 +9,7 @@ use rand::{
Rng, SeedableRng,
};
use aquatic_common::{AccessListType, convert_ipv4_mapped_ipv6, extract_response_peers};
use aquatic_common::{convert_ipv4_mapped_ipv6, extract_response_peers, AccessListType};
use aquatic_udp_protocol::*;
use crate::common::*;
@ -126,7 +126,7 @@ pub fn run_request_worker(
// Check announce requests for allowed info hashes
match config.access_list.list_type {
access_list_type@(AccessListType::Allow | AccessListType::Deny) => {
access_list_type @ (AccessListType::Allow | AccessListType::Deny) => {
let access_list: MutexGuard<AccessList> = state.access_list.lock();
announce_requests.retain(|(request, src)| {
@ -143,8 +143,8 @@ pub fn run_request_worker(
true
});
},
AccessListType::Ignore => {},
}
AccessListType::Ignore => {}
};
// Handle announce and scrape requests

View file

@ -19,30 +19,38 @@ pub fn clean_connections_and_torrents(config: &Config, state: &State) {
}
match config.access_list.list_type {
access_list_type@(AccessListType::Allow | AccessListType::Deny) => {
access_list_type @ (AccessListType::Allow | AccessListType::Deny) => {
let mut access_list = state.access_list.lock();
access_list.update_from_path(&config.access_list.path);
if let Err(err) = access_list.update_from_path(&config.access_list.path) {
::log::error!("Update access list from path: {:?}", err);
}
let mut torrents = state.torrents.lock();
torrents.ipv4.retain(|info_hash, torrent| {
access_list.allows(access_list_type, &info_hash.0) && clean_torrent_and_peers(now, torrent)
access_list.allows(access_list_type, &info_hash.0)
&& clean_torrent_and_peers(now, torrent)
});
torrents.ipv4.shrink_to_fit();
torrents.ipv6.retain(|info_hash, torrent| {
access_list.allows(access_list_type, &info_hash.0) && clean_torrent_and_peers(now, torrent)
access_list.allows(access_list_type, &info_hash.0)
&& clean_torrent_and_peers(now, torrent)
});
torrents.ipv6.shrink_to_fit();
},
}
AccessListType::Ignore => {
let mut torrents = state.torrents.lock();
torrents.ipv4.retain(|_, torrent| clean_torrent_and_peers(now, torrent));
torrents
.ipv4
.retain(|_, torrent| clean_torrent_and_peers(now, torrent));
torrents.ipv4.shrink_to_fit();
torrents.ipv6.retain(|_, torrent| clean_torrent_and_peers(now, torrent));
torrents
.ipv6
.retain(|_, torrent| clean_torrent_and_peers(now, torrent));
torrents.ipv6.shrink_to_fit();
}
}