mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 02:35:31 +00:00
aquatic_udp: split cleaning interval for connections and torrents
This commit is contained in:
parent
5f10e5e7f4
commit
afe3e2465f
5 changed files with 20 additions and 13 deletions
|
|
@ -91,12 +91,14 @@ pub struct StatisticsConfig {
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct CleaningConfig {
|
pub struct CleaningConfig {
|
||||||
/// Update access list and clean torrents this often (seconds)
|
/// Clean connections this often (seconds)
|
||||||
pub interval: u64,
|
pub connection_cleaning_interval: u64,
|
||||||
/// Remove peers that haven't announced for this long (seconds)
|
/// Clean torrents this often (seconds)
|
||||||
pub max_peer_age: u64,
|
pub torrent_cleaning_interval: u64,
|
||||||
/// Remove connections that are older than this (seconds)
|
/// Remove connections that are older than this (seconds)
|
||||||
pub max_connection_age: u64,
|
pub max_connection_age: u64,
|
||||||
|
/// Remove peers that haven't announced for this long (seconds)
|
||||||
|
pub max_peer_age: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
|
|
@ -160,9 +162,10 @@ impl Default for StatisticsConfig {
|
||||||
impl Default for CleaningConfig {
|
impl Default for CleaningConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
interval: 30,
|
connection_cleaning_interval: 60,
|
||||||
max_peer_age: 60 * 20,
|
torrent_cleaning_interval: 60 * 2,
|
||||||
max_connection_age: 60 * 5,
|
max_connection_age: 60 * 5,
|
||||||
|
max_peer_age: 60 * 20,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ pub async fn run_request_worker(
|
||||||
enclose!((config, torrents, state) move || async move {
|
enclose!((config, torrents, state) move || async move {
|
||||||
torrents.borrow_mut().clean(&config, &state.access_list);
|
torrents.borrow_mut().clean(&config, &state.access_list);
|
||||||
|
|
||||||
Some(Duration::from_secs(config.cleaning.interval))
|
Some(Duration::from_secs(config.cleaning.torrent_cleaning_interval))
|
||||||
})()
|
})()
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -127,11 +127,11 @@ pub async fn run_socket_worker(
|
||||||
let pending_scrape_responses = Rc::new(RefCell::new(PendingScrapeResponses::default()));
|
let pending_scrape_responses = Rc::new(RefCell::new(PendingScrapeResponses::default()));
|
||||||
|
|
||||||
// Periodically clean pending_scrape_responses
|
// Periodically clean pending_scrape_responses
|
||||||
TimerActionRepeat::repeat(enclose!((config, pending_scrape_responses) move || {
|
TimerActionRepeat::repeat(enclose!((pending_scrape_responses) move || {
|
||||||
enclose!((config, pending_scrape_responses) move || async move {
|
enclose!((pending_scrape_responses) move || async move {
|
||||||
pending_scrape_responses.borrow_mut().clean();
|
pending_scrape_responses.borrow_mut().clean();
|
||||||
|
|
||||||
Some(Duration::from_secs(config.cleaning.interval))
|
Some(Duration::from_secs(120))
|
||||||
})()
|
})()
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
@ -201,7 +201,7 @@ async fn read_requests(
|
||||||
enclose!((config, connections) move || async move {
|
enclose!((config, connections) move || async move {
|
||||||
connections.borrow_mut().clean();
|
connections.borrow_mut().clean();
|
||||||
|
|
||||||
Some(Duration::from_secs(config.cleaning.interval))
|
Some(Duration::from_secs(config.cleaning.connection_cleaning_interval))
|
||||||
})()
|
})()
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -141,7 +141,9 @@ pub fn run_inner(config: Config, state: State) -> ::anyhow::Result<()> {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
::std::thread::sleep(Duration::from_secs(config.cleaning.interval));
|
::std::thread::sleep(Duration::from_secs(
|
||||||
|
config.cleaning.torrent_cleaning_interval,
|
||||||
|
));
|
||||||
|
|
||||||
state.torrents.lock().clean(&config, &state.access_list);
|
state.torrents.lock().clean(&config, &state.access_list);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,9 @@ pub fn run_socket_worker(
|
||||||
if iter_counter % 32 == 0 {
|
if iter_counter % 32 == 0 {
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
|
|
||||||
if last_cleaning + Duration::from_secs(config.cleaning.interval) > now {
|
if last_cleaning + Duration::from_secs(config.cleaning.connection_cleaning_interval)
|
||||||
|
> now
|
||||||
|
{
|
||||||
connections.clean();
|
connections.clean();
|
||||||
|
|
||||||
last_cleaning = now;
|
last_cleaning = now;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue