aquatic_ws: split torrent state by ipv4/ipv6

This commit is contained in:
Joakim Frostegård 2020-05-23 15:15:01 +02:00
parent 7430c23ccc
commit 416d61a2b2
4 changed files with 42 additions and 19 deletions

View file

@ -4,17 +4,24 @@ use crate::common::*;
pub fn clean_torrents(state: &State){
let mut torrents = state.torrents.lock();
fn clean_torrent_map(
torrent_map: &mut TorrentMap,
){
let now = Instant::now();
let now = Instant::now();
torrent_map.retain(|_, torrent_data| {
torrent_data.peers.retain(|_, peer| {
peer.valid_until.0 >= now
});
torrents.retain(|_, torrent_data| {
torrent_data.peers.retain(|_, peer| {
peer.valid_until.0 >= now
!torrent_data.peers.is_empty()
});
!torrent_data.peers.is_empty()
});
torrent_map.shrink_to_fit();
}
torrents.shrink_to_fit();
let mut torrent_maps = state.torrent_maps.lock();
clean_torrent_map(&mut torrent_maps.ipv4);
clean_torrent_map(&mut torrent_maps.ipv6);
}