mirror of
https://github.com/ZeusWPI/ZNS.git
synced 2024-11-22 05:41:11 +01:00
fixed loop
This commit is contained in:
parent
08b5947fbb
commit
ec0b93e7c0
2 changed files with 21 additions and 21 deletions
18
src/main.rs
18
src/main.rs
|
@ -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 {}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue