10
0
Fork 0
mirror of https://github.com/ZeusWPI/ZNS.git synced 2024-11-22 05:41:11 +01:00

fixed loop

This commit is contained in:
Xander Bil 2024-03-03 22:52:36 +01:00
parent 08b5947fbb
commit ec0b93e7c0
No known key found for this signature in database
GPG key ID: EC9706B54A278598
2 changed files with 21 additions and 21 deletions

View file

@ -1,4 +1,4 @@
use std::{error::Error, net::SocketAddr}; use std::{error::Error, net::SocketAddr, sync::Arc};
use parser::FromBytes; use parser::FromBytes;
use structs::Message; use structs::Message;
@ -37,22 +37,22 @@ async fn create_query(message: Message) -> Message {
async fn main() -> Result<(), Box<dyn Error>> { async fn main() -> Result<(), Box<dyn Error>> {
let local_addr: SocketAddr = "127.0.0.1:8080".parse()?; let local_addr: SocketAddr = "127.0.0.1:8080".parse()?;
let socket = UdpSocket::bind(local_addr).await?; let socket_shared = Arc::new(UdpSocket::bind(local_addr).await?);
loop {
let mut data = vec![0u8; MAX_DATAGRAM_SIZE]; let mut data = vec![0u8; MAX_DATAGRAM_SIZE];
let (len,addr) = socket.recv_from(&mut data).await?; let (len, addr) = socket_shared.recv_from(&mut data).await?;
match Message::from_bytes(&data[..len]) { match Message::from_bytes(&data[..len]) {
Ok(message) => { Ok(message) => {
let socket = socket_shared.clone();
tokio::spawn(async move { tokio::spawn(async move {
let response = create_query(message).await; let response = create_query(message).await;
println!("{:?}",response); let _ = socket
let vec = Message::to_bytes(response); .send_to(Message::to_bytes(response).as_slice(), addr)
let decoded = Message::from_bytes(vec.as_slice()); .await;
println!("{:?}",decoded);
let _ = socket.send_to(vec.as_slice(),addr).await;
}); });
} }
Err(err) => println!("{}", err), Err(err) => println!("{}", err),
}; };
loop {} }
} }

View file

@ -12,7 +12,7 @@ pub enum Class {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Question { pub struct Question {
pub qname: Vec<String>, // TODO: not padded pub qname: Vec<String>,
pub qtype: Type, // NOTE: should be QTYPE, right now not really needed pub qtype: Type, // NOTE: should be QTYPE, right now not really needed
pub qclass: Class, //NOTE: should be QCLASS, right now not really needed pub qclass: Class, //NOTE: should be QCLASS, right now not really needed
} }