Code formatting

This commit is contained in:
zonyitoo
2020-05-08 23:35:54 +08:00
parent 84db921d34
commit 2ea466d3a2
2 changed files with 22 additions and 17 deletions
+16 -14
View File
@@ -10,10 +10,7 @@ use std::{
};
#[cfg(feature = "local-dns-relay")]
use std::{
net::IpAddr,
time::Duration,
};
use std::{net::IpAddr, time::Duration};
use bloomfilter::Bloom;
#[cfg(feature = "local-dns-relay")]
@@ -186,8 +183,9 @@ impl Context {
fn new(config: Config, server_state: SharedServerState) -> Context {
let nonce_ppbloom = Mutex::new(PingPongBloom::new(config.config_type));
#[cfg(feature = "local-dns-relay")]
let reverse_lookup_cache = Mutex::new(LruCache::<IpAddr, bool>::with_expiry_duration(
Duration::from_secs(3 * 24 * 60 * 60)));
let reverse_lookup_cache = Mutex::new(LruCache::<IpAddr, bool>::with_expiry_duration(Duration::from_secs(
3 * 24 * 60 * 60,
)));
Context {
config,
@@ -298,14 +296,18 @@ impl Context {
let is_exception = self.check_ip_in_proxy_list(addr) != forward;
let mut reverse_lookup_cache = self.reverse_lookup_cache.lock();
match reverse_lookup_cache.get_mut(addr) {
Some(value) => if is_exception {
*value = forward;
} else {
// we do not need to remember the entry if it is already matched correctly
reverse_lookup_cache.remove(addr);
Some(value) => {
if is_exception {
*value = forward;
} else {
// we do not need to remember the entry if it is already matched correctly
reverse_lookup_cache.remove(addr);
}
}
None => if is_exception {
reverse_lookup_cache.insert(addr.clone(), forward);
None => {
if is_exception {
reverse_lookup_cache.insert(addr.clone(), forward);
}
}
}
}
@@ -351,7 +353,7 @@ impl Context {
let mut reverse_lookup_cache = self.reverse_lookup_cache.lock();
// if a qname is found
if let Some(forward) = reverse_lookup_cache.get(&saddr.ip()) {
return !*forward
return !*forward;
}
}
}
+6 -3
View File
@@ -140,7 +140,9 @@ async fn acl_lookup(
Some(false) => None,
_ => {
let timeout = Some(Duration::new(3, 0));
try_timeout(proxy_lookup(context.clone(), svr_cfg, remote, qname, qtype), timeout).await.ok()
try_timeout(proxy_lookup(context.clone(), svr_cfg, remote, qname, qtype), timeout)
.await
.ok()
}
}
};
@@ -151,7 +153,8 @@ async fn acl_lookup(
let timeout = Some(Duration::new(3, 0));
try_timeout(local_lookup(qname, qtype, local), timeout).await.ok()
}
}.unwrap_or_else(Message::new);
}
.unwrap_or_else(Message::new);
match qname_in_proxy_list {
Some(true) => {
@@ -179,7 +182,7 @@ async fn acl_lookup(
};
if !forward {
debug!("pick local response (ip): {:?}", local_response);
return Ok((local_response, false))
return Ok((local_response, false));
}
}