Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use std::{
};

#[cfg(feature = "local-dns-relay")]
use std::net::IpAddr;
use std::{
net::IpAddr,
time::Duration,
};

use bloomfilter::Bloom;
#[cfg(feature = "local-dns-relay")]
Expand Down Expand Up @@ -183,7 +186,8 @@ 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_capacity(8192));
let reverse_lookup_cache = Mutex::new(LruCache::<IpAddr, bool>::with_expiry_duration(
Duration::from_secs(3 * 24 * 60 * 60)));

Context {
config,
Expand Down Expand Up @@ -291,11 +295,19 @@ impl Context {
/// Add a record to the reverse lookup cache
#[cfg(feature = "local-dns-relay")]
pub fn add_to_reverse_lookup_cache(&self, addr: &IpAddr, forward: bool) {
if self.check_ip_in_proxy_list(addr) == forward {
return;
}
let is_exception = self.check_ip_in_proxy_list(addr) != forward;
let mut reverse_lookup_cache = self.reverse_lookup_cache.lock();
reverse_lookup_cache.insert(addr.clone(), forward);
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);
}
None => if is_exception {
reverse_lookup_cache.insert(addr.clone(), forward);
}
}
}

/// Check if domain name is in proxy_list.
Expand Down