MCPcopy Create free account
hub / github.com/DNSCrypt/encrypted-dns-server / resolve

Function resolve

src/resolver.rs:213–270  ·  view source on GitHub ↗
(
    globals: &Globals,
    packet: &mut Vec<u8>,
    packet_qname: Vec<u8>,
    cached_response: Option<CachedResponse>,
    packet_hash: u128,
    original_tid: u16,
)

Source from the content-addressed store, hash-verified

211}
212
213pub async fn resolve(
214 globals: &Globals,
215 packet: &mut Vec<u8>,
216 packet_qname: Vec<u8>,
217 cached_response: Option<CachedResponse>,
218 packet_hash: u128,
219 original_tid: u16,
220) -> Result<Vec<u8>, Error> {
221 #[cfg(feature = "metrics")]
222 globals.varz.upstream_sent.inc();
223 let tid = random();
224 dns::set_tid(packet, tid);
225 let mut response = resolve_udp(
226 globals,
227 packet,
228 &packet_qname,
229 tid,
230 cached_response.is_some(),
231 )
232 .await?;
233 if dns::is_truncated(&response) {
234 response = resolve_tcp(globals, packet, &packet_qname, tid).await?;
235 }
236 #[cfg(feature = "metrics")]
237 {
238 globals.varz.upstream_received.inc();
239 if dns::rcode_nxdomain(&response) {
240 globals.varz.upstream_rcode_nxdomain.inc();
241 }
242 }
243 if dns::rcode_servfail(&response) || dns::rcode_refused(&response) {
244 trace!("SERVFAIL/REFUSED: {}", dns::rcode(&response));
245 if let Some(cached_response) = cached_response {
246 trace!("Serving stale");
247 #[cfg(feature = "metrics")]
248 {
249 globals.varz.client_queries_offline.inc();
250 globals.varz.client_queries_cached.inc();
251 }
252 return Ok(cached_response.into_response());
253 } else {
254 #[cfg(feature = "metrics")]
255 globals.varz.upstream_errors.inc();
256 }
257 } else {
258 trace!("Adding to cache");
259 let cached_response = CachedResponse::new(&globals.cache, response.clone());
260 globals.cache.lock().insert(packet_hash, cached_response);
261 }
262 dns::set_tid(&mut response, original_tid);
263 dns::recase_qname(&mut response, &packet_qname)?;
264 #[cfg(feature = "metrics")]
265 globals
266 .varz
267 .upstream_response_sizes
268 .observe(response.len() as f64);
269 Ok(response)
270}

Callers 1

Calls 11

set_tidFunction · 0.85
resolve_udpFunction · 0.85
is_truncatedFunction · 0.85
resolve_tcpFunction · 0.85
rcode_nxdomainFunction · 0.85
rcode_servfailFunction · 0.85
rcode_refusedFunction · 0.85
newFunction · 0.85
recase_qnameFunction · 0.85
into_responseMethod · 0.80
lockMethod · 0.80

Tested by

no test coverage detected