mod dictionary;
mod packet;
mod handler;
use crate::dictionary::Dictionary;
use crate::packet::RadiusPacket;
use tokio::net::UdpSocket;
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let dict_path = "dictionaries/dictionary"; let dictionary = Dictionary::load_from_file(dict_path)?;
let dictionary = Arc::new(dictionary);
let socket = UdpSocket::bind("0.0.0.0:1812").await?;
let mut buf = [0u8; 1024];
loop {
let (len, addr) = socket.recv_from(&mut buf).await?;
let packet = RadiusPacket::from_bytes(&buf[..len])?;
let response = handler::handle(packet, Arc::clone(&dictionary))?;
socket.send_to(&response.to_bytes(), addr).await?;
}
}