aquatic_ws: clean torrent state periodically

This commit is contained in:
Joakim Frostegård 2020-05-12 15:45:28 +02:00
parent de06931242
commit 7c9ecda53a
5 changed files with 41 additions and 11 deletions

View 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();
}