mod faucet; mod new_tx; mod cipher; mod commit; mod unknown; mod sync; use std::net::SocketAddr; use sdk_common::network::{AnkFlag, Envelope}; use crate::peers; use super::cache::MESSAGECACHE; pub(crate) fn process_message(raw_msg: &str, addr: SocketAddr) { let cache = MESSAGECACHE.get().expect("Cache should be initialized"); if cache.contains(raw_msg) { log::debug!("Message already processed, dropping"); return; } else { cache.insert(raw_msg.to_owned()); } match serde_json::from_str::(raw_msg) { Ok(ank_msg) => match ank_msg.flag { AnkFlag::Faucet => faucet::handle_faucet(ank_msg, addr), AnkFlag::NewTx => new_tx::handle_new_tx(ank_msg, addr), AnkFlag::Cipher => cipher::handle_cipher(ank_msg, addr), AnkFlag::Commit => commit::handle_commit(ank_msg, addr), AnkFlag::Unknown => unknown::handle_unknown(ank_msg, addr), AnkFlag::Sync => sync::handle_sync(ank_msg), AnkFlag::Handshake => log::debug!("Received init message from {}", addr), }, Err(e) => { log::warn!("Failed to parse network message from {}: {} - Raw message: {}", addr, e, raw_msg); // Continue processing instead of dropping the message } } }