diff --git a/aquatic_common/src/lib.rs b/aquatic_common/src/lib.rs index ae39748..b419138 100644 --- a/aquatic_common/src/lib.rs +++ b/aquatic_common/src/lib.rs @@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize}; pub enum AccessListType { Allow, Deny, - Ignore + Ignore, } #[derive(Clone, Debug, Serialize, Deserialize)] @@ -47,7 +47,11 @@ impl AccessList { if count == 20 { Ok(bytes) } else { - Err(anyhow::anyhow!("Info hash length only {} bytes: {}", count, line)) + Err(anyhow::anyhow!( + "Info hash length only {} bytes: {}", + count, + line + )) } } @@ -61,21 +65,14 @@ impl AccessList { self.0.insert(Self::parse_line_to_info_hash(line?)?); } - Ok(()) } pub fn allows(&self, list_type: AccessListType, info_hash_bytes: &[u8; 20]) -> bool { match list_type { - AccessListType::Allow => { - self.0.contains(info_hash_bytes) - } - AccessListType::Deny => { - !self.0.contains(info_hash_bytes) - } - AccessListType::Ignore => { - true - } + AccessListType::Allow => self.0.contains(info_hash_bytes), + AccessListType::Deny => !self.0.contains(info_hash_bytes), + AccessListType::Ignore => true, } } } diff --git a/aquatic_udp/src/lib/handlers.rs b/aquatic_udp/src/lib/handlers.rs index d6cf58a..a5b21d7 100644 --- a/aquatic_udp/src/lib/handlers.rs +++ b/aquatic_udp/src/lib/handlers.rs @@ -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 = 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 diff --git a/aquatic_udp/src/lib/tasks.rs b/aquatic_udp/src/lib/tasks.rs index 43e1711..391038d 100644 --- a/aquatic_udp/src/lib/tasks.rs +++ b/aquatic_udp/src/lib/tasks.rs @@ -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(); } } diff --git a/aquatic_ws/src/lib/network/connection.rs b/aquatic_ws/src/lib/network/connection.rs index fbaf299..8873509 100644 --- a/aquatic_ws/src/lib/network/connection.rs +++ b/aquatic_ws/src/lib/network/connection.rs @@ -145,7 +145,7 @@ impl HandshakeMachine { ); (Some(Either::Right(Self::TlsStream(stream))), false) - }, + } Err(native_tls::HandshakeError::WouldBlock(handshake)) => { (Some(Either::Right(Self::TlsMidHandshake(handshake))), true) } @@ -170,10 +170,7 @@ impl HandshakeMachine { peer_addr ); - let established_ws = EstablishedWs { - ws, - peer_addr, - }; + let established_ws = EstablishedWs { ws, peer_addr }; (Some(Either::Left(established_ws)), false) }