domain/resolv/resolver.rs
1//! The trait defining an abstract resolver.
2
3use crate::base::message::Message;
4use crate::base::name::ToDname;
5use crate::base::question::Question;
6use std::future::Future;
7use std::io;
8
9//----------- Resolver -------------------------------------------------------
10
11/// A type that acts as a DNS resolver.
12///
13/// A resolver is anything that tries to answer questions using the DNS. The
14/// `query` method takes a single question and returns a future that will
15/// eventually resolve into either an answer or an IO error.
16pub trait Resolver {
17 type Octets: AsRef<[u8]>;
18
19 /// The answer returned by a query.
20 ///
21 /// This isn’t `Message` directly as it may be useful for the resolver
22 /// to provide additional information. For instance, a validating
23 /// resolver (a resolver that checks whether DNSSEC signatures are
24 /// correct) can supply more information as to why validation failed.
25 type Answer: AsRef<Message<Self::Octets>>;
26
27 /// The future resolving into an answer.
28 type Query: Future<Output = Result<Self::Answer, io::Error>> + Send;
29
30 /// Returns a future answering a question.
31 ///
32 /// The method takes anything that can be converted into a question and
33 /// produces a future trying to answer the question.
34 fn query<N, Q>(&self, question: Q) -> Self::Query
35 where
36 N: ToDname,
37 Q: Into<Question<N>>;
38}
39
40//------------ SearchNames ---------------------------------------------------
41
42/// A type that can produce a list of name suffixes.
43///
44/// Legacy systems have the ability to interpret relative domain names as
45/// within the local system. They provide a list of suffixes that can be
46/// attached to the name to make it absolute.
47///
48/// A search resolver is a resolver that provides such a list. This is
49/// implemented via an iterator over domain names.
50pub trait SearchNames {
51 type Name: ToDname;
52 type Iter: Iterator<Item = Self::Name>;
53
54 /// Returns an iterator over the search suffixes.
55 fn search_iter(&self) -> Self::Iter;
56}