Skip to content

Commit

Permalink
use listen_address
Browse files Browse the repository at this point in the history
  • Loading branch information
denisu committed Nov 5, 2024
1 parent 6b61c38 commit 89452f7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
9 changes: 4 additions & 5 deletions src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,13 @@ impl Authority for RandomizedAuthority {

pub async fn start_dns_server(
catalog: Catalog,
address: String,
port: u16,
listen_address: SocketAddr,
) -> anyhow::Result<tokio::task::JoinHandle<()>> {
let mut server = ServerFuture::new(catalog);
let udp_socket = UdpSocket::bind(format!("{address}:{port}")).await?;
let tcp_listener = TcpListener::bind(format!("{address}:{port}")).await?;
let udp_socket = UdpSocket::bind(listen_address).await?;
let tcp_listener = TcpListener::bind(listen_address).await?;

println!("Starting DNS server on {}:{}", address, port);
println!("Starting DNS server on {}", listen_address);

Ok(tokio::spawn(async move {
server.register_socket(udp_socket);
Expand Down
17 changes: 4 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,11 @@ struct Opt {
#[clap(
long,
short,
value_name = "ip",
value_name = "ip:port",
help = "Set listen address",
default_value = "[::]"
)]
address: String,

#[clap(
long,
short,
value_name = "port",
help = "Set listen port",
default_value = "53"
default_value = "[::]:53"
)]
port: u16,
listen_address: SocketAddr,

#[clap(
long,
Expand Down Expand Up @@ -101,7 +92,7 @@ async fn main() -> anyhow::Result<()> {
opt.network_id.clone(),
);
let rechecker_handle = start_peer_rechecker(tls, authority.clone(), opt.network_id);
let server_handle = start_dns_server(catalog, opt.address, opt.port).await?;
let server_handle = start_dns_server(catalog, opt.listen_address).await?;

tokio::select! {
Err(e) = server_handle => println!("DNS server failed: {e}"),
Expand Down

0 comments on commit 89452f7

Please sign in to comment.