aquatic_http: parameterise many data structures over peer IP protocol

This commit is contained in:
Joakim Frostegård 2020-07-08 14:12:01 +02:00
parent da4ba14b47
commit 2386dd0e8b
7 changed files with 230 additions and 205 deletions

View file

@ -4,24 +4,26 @@ use crate::common::*;
pub fn clean_torrents(state: &State){
fn clean_torrent_map(
torrent_map: &mut TorrentMap,
){
let now = Instant::now();
torrent_map.retain(|_, torrent_data| {
torrent_data.peers.retain(|_, peer| {
peer.valid_until.0 >= now
});
!torrent_data.peers.is_empty()
});
torrent_map.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);
}
fn clean_torrent_map<I: Eq + ::std::hash::Hash>(
torrent_map: &mut TorrentMap<I>,
){
let now = Instant::now();
torrent_map.retain(|_, torrent_data| {
torrent_data.peers.retain(|_, peer| {
peer.valid_until.0 >= now
});
!torrent_data.peers.is_empty()
});
torrent_map.shrink_to_fit();
}