mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 18:25:30 +00:00
aquatic_udp: glommio: move update_access_list to new common.rs
This commit is contained in:
parent
bfcdc1c842
commit
02889e1bb8
3 changed files with 38 additions and 27 deletions
35
aquatic_udp/src/lib/glommio/common.rs
Normal file
35
aquatic_udp/src/lib/glommio/common.rs
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
use std::cell::RefCell;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
use futures_lite::{AsyncBufReadExt};
|
||||||
|
use glommio::io::{BufferedFile, StreamReaderBuilder};
|
||||||
|
use glommio::{prelude::*};
|
||||||
|
|
||||||
|
use crate::common::*;
|
||||||
|
use crate::config::Config;
|
||||||
|
|
||||||
|
pub async fn update_access_list(
|
||||||
|
config: Config,
|
||||||
|
access_list: Rc<RefCell<AccessList>>,
|
||||||
|
){
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,9 +3,8 @@ use std::net::{IpAddr, SocketAddr};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use futures_lite::{AsyncBufReadExt, Stream, StreamExt};
|
use futures_lite::{Stream, StreamExt};
|
||||||
use glommio::channels::channel_mesh::{MeshBuilder, Partial, Role, Senders};
|
use glommio::channels::channel_mesh::{MeshBuilder, Partial, Role, Senders};
|
||||||
use glommio::io::{BufferedFile, StreamReaderBuilder};
|
|
||||||
use glommio::timer::TimerActionRepeat;
|
use glommio::timer::TimerActionRepeat;
|
||||||
use glommio::{enclose, prelude::*};
|
use glommio::{enclose, prelude::*};
|
||||||
use rand::prelude::SmallRng;
|
use rand::prelude::SmallRng;
|
||||||
|
|
@ -14,6 +13,7 @@ use rand::SeedableRng;
|
||||||
use crate::common::announce::handle_announce_request;
|
use crate::common::announce::handle_announce_request;
|
||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
|
use crate::glommio::common::update_access_list;
|
||||||
|
|
||||||
pub async fn run_request_worker(
|
pub async fn run_request_worker(
|
||||||
config: Config,
|
config: Config,
|
||||||
|
|
@ -91,28 +91,3 @@ async fn handle_request_stream<S>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_access_list(
|
|
||||||
config: Config,
|
|
||||||
access_list: Rc<RefCell<AccessList>>,
|
|
||||||
){
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use glommio::prelude::*;
|
||||||
|
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
|
|
||||||
|
mod common;
|
||||||
pub mod handlers;
|
pub mod handlers;
|
||||||
pub mod network;
|
pub mod network;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue