Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qname router #353

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
749eded
Prototype version of a query router.
Philip-NLnetLabs Jul 12, 2024
a62225c
Clippy
Philip-NLnetLabs Jul 12, 2024
9772ae0
Features for query-routing.
Philip-NLnetLabs Jul 12, 2024
af1ee53
Remove MyService
Philip-NLnetLabs Jul 12, 2024
0e6d67d
Duplicate mock_instant
Philip-NLnetLabs Jul 12, 2024
27689d2
QnameRouter instead of QueryRouter.
Philip-NLnetLabs Jul 22, 2024
7243cde
SrService becomes SingleService
Philip-NLnetLabs Jul 22, 2024
65095d3
Cargo fmt
Philip-NLnetLabs Jul 23, 2024
67fe2f5
Changes for service-layering
Philip-NLnetLabs Jul 26, 2024
c3fae7a
Adapt to changes in net::client.
Philip-NLnetLabs Aug 29, 2024
1e791a8
Adapts to changes in Service.
Philip-NLnetLabs Sep 2, 2024
0460739
Changes for proxy.
Philip-NLnetLabs Sep 2, 2024
9cab8db
Fmt
Philip-NLnetLabs Sep 2, 2024
2b7e949
Docs
Philip-NLnetLabs Sep 3, 2024
1e77887
Fix example.
Philip-NLnetLabs Sep 5, 2024
2731da8
Docs and cleanup
Philip-NLnetLabs Sep 5, 2024
21c9304
Cleanup use.
Philip-NLnetLabs Sep 5, 2024
fb2f7ec
Document RequestNG
Philip-NLnetLabs Sep 5, 2024
2c779d4
Remove some dead code.
Philip-NLnetLabs Sep 5, 2024
c2bac03
Improvements by Ximon
Philip-NLnetLabs Oct 10, 2024
9d4ae49
Docs
Philip-NLnetLabs Oct 11, 2024
df74b3d
Improved example.
Philip-NLnetLabs Oct 11, 2024
27f213c
Fmt
Philip-NLnetLabs Oct 11, 2024
c2fd2f4
Add Debug
Philip-NLnetLabs Oct 11, 2024
64919fb
Remove unwraps.
Philip-NLnetLabs Oct 14, 2024
4b147a6
Remove unwraps
Philip-NLnetLabs Oct 14, 2024
784b538
Remove unwraps
Philip-NLnetLabs Oct 14, 2024
1c98dec
Merge branch 'main' into qname-router
Philip-NLnetLabs Oct 14, 2024
25d796e
Merge branch 'main' into qname-router
Philip-NLnetLabs Oct 14, 2024
26df1a7
Avoid futures
Philip-NLnetLabs Oct 14, 2024
d71c766
Remove Unpin bounds
Philip-NLnetLabs Oct 14, 2024
6420956
Switch to ServiceError, include EDE to report error.
Philip-NLnetLabs Oct 15, 2024
5094638
Remove unwraps
Philip-NLnetLabs Oct 15, 2024
e371c28
Remove unwraps
Philip-NLnetLabs Oct 15, 2024
0b3bc88
Merge branch 'main' into qname-router
Philip-NLnetLabs Oct 15, 2024
6df7ace
Clippy
Philip-NLnetLabs Oct 15, 2024
d513f78
Add tracing and more dnsi query examples
Philip-NLnetLabs Oct 18, 2024
9568c0a
Some comments from @bal-e and @tertsdiepraam.
Philip-NLnetLabs Oct 28, 2024
1729ff3
Small fix.
Philip-NLnetLabs Oct 28, 2024
b159484
Clippy
Philip-NLnetLabs Oct 28, 2024
20558da
Move boilerplate out of the way
Philip-NLnetLabs Oct 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ required-features = ["zonefile", "net", "unstable-server-transport", "unstable-z
name = "ixfr-client"
required-features = ["zonefile", "net", "unstable-client-transport", "unstable-zonetree"]

[[example]]
name = "query-routing"
required-features = ["net", "unstable-client-transport", "unstable-server-transport", "tracing-subscriber"]

# This example is commented out because it is difficult, if not impossible,
# when including the sqlx dependency, to make the dependency tree compatible
# with both `cargo +nightly update -Z minimal versions` and the crate minimum
Expand Down
139 changes: 139 additions & 0 deletions examples/query-routing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
use domain::base::Name;
use domain::net::client::protocol::{TcpConnect, UdpConnect};
use domain::net::client::{dgram_stream, redundant};
use domain::net::server::adapter::{
ClientTransportToSingleService, SingleServiceToService,
};
use domain::net::server::buf::VecBufSource;
use domain::net::server::dgram::DgramServer;
use domain::net::server::middleware::mandatory::MandatoryMiddlewareSvc;
use domain::net::server::qname_router::QnameRouter;
use domain::net::server::single_service::ReplyMessage;
use domain::net::server::stream::StreamServer;
use std::net::{IpAddr, SocketAddr};
use std::str::FromStr;
use std::sync::Arc;
use std::vec::Vec;
use tokio::net::{TcpSocket, UdpSocket};
use tracing_subscriber::EnvFilter;

//----------- main() ---------------------------------------------------------

#[tokio::main(flavor = "multi_thread")]
async fn main() {
eprintln!("Test with commands such as:");
eprintln!(" dnsi query --server ::1 -p 8053 ietf.org");
eprintln!(" dnsi query --server ::1 -p 8053 nlnetlabs.nl");
eprintln!(" dnsi query --server ::1 -p 8053 google.com");
eprintln!("Enabled tracing with 'RUST_LOG=trace' before the command");
Philip-NLnetLabs marked this conversation as resolved.
Show resolved Hide resolved

// -----------------------------------------------------------------------
// Setup logging. You can override the log level by setting environment
// variable RUST_LOG, e.g. RUST_LOG=trace.
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
.with_thread_ids(true)
.without_time()
.try_init()
.ok();

// Start building the query router plus upstreams.
let mut qr: QnameRouter<Vec<u8>, Vec<u8>, ReplyMessage> =
QnameRouter::new();

// Queries to the root go to 2606:4700:4700::1111 and 1.1.1.1.
let (redun, transport) = redundant::Connection::new();
tokio::spawn(transport.run());
let server_addr = SocketAddr::new(
IpAddr::from_str("2606:4700:4700::1111").unwrap(),
53,
);
let udp_connect = UdpConnect::new(server_addr);
let tcp_connect = TcpConnect::new(server_addr);
let (conn, transport) =
dgram_stream::Connection::new(udp_connect, tcp_connect);
tokio::spawn(transport.run());
redun.add(Box::new(conn)).await.unwrap();
let server_addr =
SocketAddr::new(IpAddr::from_str("1.1.1.1").unwrap(), 53);
let udp_connect = UdpConnect::new(server_addr);
let tcp_connect = TcpConnect::new(server_addr);
let (conn, transport) =
dgram_stream::Connection::new(udp_connect, tcp_connect);
tokio::spawn(transport.run());
redun.add(Box::new(conn)).await.unwrap();
let conn_service = ClientTransportToSingleService::new(redun);
qr.add(Name::<Vec<u8>>::from_str(".").unwrap(), conn_service);
Philip-NLnetLabs marked this conversation as resolved.
Show resolved Hide resolved

// Queries to .com go to 2001:4860:4860::8888 and 8.8.8.8.
let (redun, transport) = redundant::Connection::new();
tokio::spawn(transport.run());
let server_addr = SocketAddr::new(
IpAddr::from_str("2001:4860:4860::8888").unwrap(),
53,
);
let udp_connect = UdpConnect::new(server_addr);
let tcp_connect = TcpConnect::new(server_addr);
let (conn, transport) =
dgram_stream::Connection::new(udp_connect, tcp_connect);
tokio::spawn(transport.run());
redun.add(Box::new(conn)).await.unwrap();
let server_addr =
SocketAddr::new(IpAddr::from_str("8.8.8.8").unwrap(), 53);
let udp_connect = UdpConnect::new(server_addr);
let tcp_connect = TcpConnect::new(server_addr);
let (conn, transport) =
dgram_stream::Connection::new(udp_connect, tcp_connect);
tokio::spawn(transport.run());
redun.add(Box::new(conn)).await.unwrap();
let conn_service = ClientTransportToSingleService::new(redun);
qr.add(Name::<Vec<u8>>::from_str("com").unwrap(), conn_service);

// Queries to .nl go to 2620:fe::9 and 9.9.9.9.
let (redun, transport) = redundant::Connection::new();
tokio::spawn(transport.run());
let server_addr =
SocketAddr::new(IpAddr::from_str("2620:fe::9").unwrap(), 53);
let udp_connect = UdpConnect::new(server_addr);
let tcp_connect = TcpConnect::new(server_addr);
let (conn, transport) =
dgram_stream::Connection::new(udp_connect, tcp_connect);
tokio::spawn(transport.run());
redun.add(Box::new(conn)).await.unwrap();
let server_addr =
SocketAddr::new(IpAddr::from_str("9.9.9.9").unwrap(), 53);
let udp_connect = UdpConnect::new(server_addr);
let tcp_connect = TcpConnect::new(server_addr);
let (conn, transport) =
dgram_stream::Connection::new(udp_connect, tcp_connect);
tokio::spawn(transport.run());
redun.add(Box::new(conn)).await.unwrap();
let conn_service = ClientTransportToSingleService::new(redun);
qr.add(Name::<Vec<u8>>::from_str("nl").unwrap(), conn_service);
Philip-NLnetLabs marked this conversation as resolved.
Show resolved Hide resolved

let srv = SingleServiceToService::new(qr);
let srv = MandatoryMiddlewareSvc::<Vec<u8>, _, _>::new(srv);
let my_svc = Arc::new(srv);

let udpsocket = UdpSocket::bind("[::1]:8053").await.unwrap();
let buf = Arc::new(VecBufSource);
let srv = DgramServer::new(udpsocket, buf.clone(), my_svc.clone());
let udp_join_handle = tokio::spawn(async move { srv.run().await });

// -----------------------------------------------------------------------
// Run a DNS server on TCP port 8053 on ::1. Test it like so:
// dnsi query -t --server 127.0.0.1 -p 8053 google.com
let v6socket = TcpSocket::new_v6().unwrap();
v6socket.set_reuseaddr(true).unwrap();
v6socket.bind("[::1]:8053".parse().unwrap()).unwrap();
let v6listener = v6socket.listen(1024).unwrap();
let buf = Arc::new(VecBufSource);
let srv = StreamServer::new(v6listener, buf.clone(), my_svc.clone());
let tcp_join_handle = tokio::spawn(async move { srv.run().await });

// -----------------------------------------------------------------------
// Keep the services running in the background

udp_join_handle.await.unwrap();
tcp_join_handle.await.unwrap();
}
Loading