1use dns_types::protocol::types::*;
2use dns_types::zones::types::Zones;
3
4use crate::cache::SharedCache;
5use crate::metrics::Metrics;
6
7pub struct Context<'a, CT> {
8 pub r: CT,
10 pub zones: &'a Zones,
11 pub cache: &'a SharedCache,
12 question_stack: Vec<Question>,
14 metrics: Metrics,
15}
16
17impl<'a, CT> Context<'a, CT> {
18 pub fn new(r: CT, zones: &'a Zones, cache: &'a SharedCache, recursion_limit: usize) -> Self {
19 Self {
20 r,
21 zones,
22 cache,
23 question_stack: Vec::with_capacity(recursion_limit),
24 metrics: Metrics::new(),
25 }
26 }
27
28 pub fn metrics(&mut self) -> &mut Metrics {
29 &mut self.metrics
30 }
31
32 pub fn done(self) -> Metrics {
33 self.metrics
34 }
35
36 pub fn at_recursion_limit(&self) -> bool {
37 self.question_stack.len() == self.question_stack.capacity()
38 }
39
40 pub fn is_duplicate_question(&self, question: &Question) -> bool {
41 self.question_stack.contains(question)
42 }
43
44 pub fn push_question(&mut self, question: &Question) {
45 self.question_stack.push(question.clone());
46 }
47
48 pub fn pop_question(&mut self) {
49 self.question_stack.pop();
50 }
51}