mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 10:45:30 +00:00
access list: log when update fails; run cargo fmt
This commit is contained in:
parent
b5a2b81bd7
commit
6cfa220097
4 changed files with 30 additions and 28 deletions
|
|
@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize};
|
||||||
pub enum AccessListType {
|
pub enum AccessListType {
|
||||||
Allow,
|
Allow,
|
||||||
Deny,
|
Deny,
|
||||||
Ignore
|
Ignore,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
|
@ -47,7 +47,11 @@ impl AccessList {
|
||||||
if count == 20 {
|
if count == 20 {
|
||||||
Ok(bytes)
|
Ok(bytes)
|
||||||
} else {
|
} 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?)?);
|
self.0.insert(Self::parse_line_to_info_hash(line?)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn allows(&self, list_type: AccessListType, info_hash_bytes: &[u8; 20]) -> bool {
|
pub fn allows(&self, list_type: AccessListType, info_hash_bytes: &[u8; 20]) -> bool {
|
||||||
match list_type {
|
match list_type {
|
||||||
AccessListType::Allow => {
|
AccessListType::Allow => self.0.contains(info_hash_bytes),
|
||||||
self.0.contains(info_hash_bytes)
|
AccessListType::Deny => !self.0.contains(info_hash_bytes),
|
||||||
}
|
AccessListType::Ignore => true,
|
||||||
AccessListType::Deny => {
|
|
||||||
!self.0.contains(info_hash_bytes)
|
|
||||||
}
|
|
||||||
AccessListType::Ignore => {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ use rand::{
|
||||||
Rng, SeedableRng,
|
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 aquatic_udp_protocol::*;
|
||||||
|
|
||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
@ -143,8 +143,8 @@ pub fn run_request_worker(
|
||||||
|
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
AccessListType::Ignore => {},
|
AccessListType::Ignore => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle announce and scrape requests
|
// Handle announce and scrape requests
|
||||||
|
|
|
||||||
|
|
@ -22,27 +22,35 @@ pub fn clean_connections_and_torrents(config: &Config, state: &State) {
|
||||||
access_list_type @ (AccessListType::Allow | AccessListType::Deny) => {
|
access_list_type @ (AccessListType::Allow | AccessListType::Deny) => {
|
||||||
let mut access_list = state.access_list.lock();
|
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();
|
let mut torrents = state.torrents.lock();
|
||||||
|
|
||||||
torrents.ipv4.retain(|info_hash, torrent| {
|
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.ipv4.shrink_to_fit();
|
||||||
|
|
||||||
torrents.ipv6.retain(|info_hash, torrent| {
|
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();
|
torrents.ipv6.shrink_to_fit();
|
||||||
},
|
}
|
||||||
AccessListType::Ignore => {
|
AccessListType::Ignore => {
|
||||||
let mut torrents = state.torrents.lock();
|
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.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();
|
torrents.ipv6.shrink_to_fit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -145,7 +145,7 @@ impl HandshakeMachine {
|
||||||
);
|
);
|
||||||
|
|
||||||
(Some(Either::Right(Self::TlsStream(stream))), false)
|
(Some(Either::Right(Self::TlsStream(stream))), false)
|
||||||
},
|
}
|
||||||
Err(native_tls::HandshakeError::WouldBlock(handshake)) => {
|
Err(native_tls::HandshakeError::WouldBlock(handshake)) => {
|
||||||
(Some(Either::Right(Self::TlsMidHandshake(handshake))), true)
|
(Some(Either::Right(Self::TlsMidHandshake(handshake))), true)
|
||||||
}
|
}
|
||||||
|
|
@ -170,10 +170,7 @@ impl HandshakeMachine {
|
||||||
peer_addr
|
peer_addr
|
||||||
);
|
);
|
||||||
|
|
||||||
let established_ws = EstablishedWs {
|
let established_ws = EstablishedWs { ws, peer_addr };
|
||||||
ws,
|
|
||||||
peer_addr,
|
|
||||||
};
|
|
||||||
|
|
||||||
(Some(Either::Left(established_ws)), false)
|
(Some(Either::Left(established_ws)), false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue