mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 18:55:32 +00:00
aquatic_http: parameterise many data structures over peer IP protocol
This commit is contained in:
parent
da4ba14b47
commit
2386dd0e8b
7 changed files with 230 additions and 205 deletions
|
|
@ -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();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue