domain_resolv/
resolver.rs

1//! The trait defining an abstract resolver.
2
3use std::io;
4use futures::future::Future;
5use domain::base::name::ToDname;
6use domain::base::message::Message;
7use domain::base::question::Question;
8
9
10//----------- Resolver -------------------------------------------------------
11
12/// A type that acts as a DNS resolver.
13///
14/// A resolver is anything that tries to answer questions using the DNS. The
15/// `query` method takes a single question and returns a future that will
16/// eventually resolve into either an answer or an IO error.
17pub trait Resolver {
18    type Octets: AsRef<[u8]>;
19
20    /// The answer returned by a query.
21    ///
22    /// This isn’t `Message` directly as it may be useful for the resolver
23    /// to provide additional information. For instance, a validating
24    /// resolver (a resolver that checks whether DNSSEC signatures are
25    /// correct) can supply more information as to why validation failed.
26    type Answer: AsRef<Message<Self::Octets>>;
27
28    /// The future resolving into an answer.
29    type Query: Future<Output = Result<Self::Answer, io::Error>>;
30
31    /// Returns a future answering a question.
32    ///
33    /// The method takes anything that can be converted into a question and
34    /// produces a future trying to answer the question.
35    fn query<N, Q>(&self, question: Q) -> Self::Query
36    where N: ToDname, Q: Into<Question<N>>;
37}
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}
57