From bfcdc1c842353d4ffe74e9269984e5abc85e535a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Tue, 19 Oct 2021 22:58:59 +0200 Subject: [PATCH] aquatic_udp glommio: improve AccessList update code --- aquatic_udp/src/lib/glommio/handlers.rs | 46 +++++++++++++++---------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/aquatic_udp/src/lib/glommio/handlers.rs b/aquatic_udp/src/lib/glommio/handlers.rs index a6770a6..6b341b9 100644 --- a/aquatic_udp/src/lib/glommio/handlers.rs +++ b/aquatic_udp/src/lib/glommio/handlers.rs @@ -28,26 +28,10 @@ pub async fn run_request_worker( let torrents = Rc::new(RefCell::new(TorrentMaps::default())); let access_list = Rc::new(RefCell::new(AccessList::default())); + // Periodically clean torrents and update access list TimerActionRepeat::repeat(enclose!((config, torrents, access_list) move || { enclose!((config, torrents, access_list) move || async move { - if config.access_list.mode.is_on(){ - let access_list_file = BufferedFile::open(config.access_list.path).await.unwrap(); - - let mut reader = StreamReaderBuilder::new(access_list_file).build(); - - loop { - let mut buf = String::with_capacity(42); - - match reader.read_line(&mut buf).await { - Ok(_) => { - access_list.borrow_mut().insert_from_line(&buf).unwrap() // FIXME - }, - Err(err) => { - - } - } - } - } + update_access_list(config.clone(), access_list.clone()).await; torrents.borrow_mut().clean(&config, &*access_list.borrow()); @@ -106,3 +90,29 @@ async fn handle_request_stream( yield_if_needed().await; } } + +pub async fn update_access_list( + config: Config, + access_list: Rc>, +){ + if config.access_list.mode.is_on(){ + let access_list_file = BufferedFile::open(config.access_list.path).await.unwrap(); + + let mut reader = StreamReaderBuilder::new(access_list_file).build(); + + loop { + let mut buf = String::with_capacity(42); + + match reader.read_line(&mut buf).await { + Ok(_) => { + access_list.borrow_mut().insert_from_line(&buf); + }, + Err(err) => { + break; + } + } + + yield_if_needed().await; + } + } +}