diff --git a/src/bmp.rs b/src/bmp.rs index 8e78635..b888a4a 100644 --- a/src/bmp.rs +++ b/src/bmp.rs @@ -50,7 +50,7 @@ pub async fn unmarshal_bmp_packet(socket: &mut TcpStream) -> Result } } -async fn process( +async fn process_bmp_packet( state: AsyncState, tx: Sender>, router_addr: IpAddr, @@ -194,7 +194,7 @@ pub async fn handle(socket: &mut TcpStream, state: AsyncState, tx: Sender Result<(), Box> { // Load the state if enabled if state_config.enable { - state::load(state.clone(), state_config.clone()); + state::load(state.clone()); } // MPSC channel to communicate between BMP tasks and producer task diff --git a/src/state.rs b/src/state.rs index 6e3e5a2..4c4d004 100644 --- a/src/state.rs +++ b/src/state.rs @@ -15,21 +15,21 @@ use crate::update::{format_update, synthesize_withdraw_update, Update}; pub type AsyncState = Arc>; -pub fn new_state(_sc: &StateConfig) -> AsyncState { - Arc::new(Mutex::new(State::new(_sc))) +pub fn new_state(state_config: &StateConfig) -> AsyncState { + Arc::new(Mutex::new(State::new(state_config))) } -pub fn dump(state: AsyncState, cfg: StateConfig) { +pub fn dump(state: AsyncState) { let state = state.lock().unwrap(); - let file = std::fs::File::create(cfg.path).unwrap(); + let file = std::fs::File::create(state.config.path.clone()).unwrap(); let mut writer = std::io::BufWriter::new(file); serde_json::to_writer(&mut writer, &state.store).unwrap(); } -pub fn load(state: AsyncState, cfg: StateConfig) { +pub fn load(state: AsyncState) { let mut state = state.lock().unwrap(); - let file = match std::fs::File::open(cfg.path) { + let file = match std::fs::File::open(state.config.path.clone()) { Ok(file) => file, Err(_) => return, }; @@ -321,7 +321,7 @@ pub async fn dump_handler(state: AsyncState, cfg: StateConfig) { tokio::time::sleep(Duration::from_secs(cfg.interval)).await; if cfg.enable { log::debug!("state - dump handler - dumping state to {}", cfg.path); - dump(state.clone(), cfg.clone()); + dump(state.clone()); } } }