mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 10:15:31 +00:00
aquatic_ws: clean torrent state periodically
This commit is contained in:
parent
de06931242
commit
7c9ecda53a
5 changed files with 41 additions and 11 deletions
20
aquatic_ws/src/lib/tasks.rs
Normal file
20
aquatic_ws/src/lib/tasks.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
use std::time::Instant;
|
||||
|
||||
use crate::common::*;
|
||||
|
||||
|
||||
pub fn clean_torrents(state: &State){
|
||||
let mut torrents = state.torrents.lock();
|
||||
|
||||
let now = Instant::now();
|
||||
|
||||
torrents.retain(|_, torrent_data| {
|
||||
torrent_data.peers.retain(|_, peer| {
|
||||
peer.valid_until.0 >= now
|
||||
});
|
||||
|
||||
!torrent_data.peers.is_empty()
|
||||
});
|
||||
|
||||
torrents.shrink_to_fit();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue