mirror of
https://github.com/shadowsocks/shadowsocks-rust.git
synced 2026-11-07 00:13:33 +00:00
+2
-2
@@ -282,8 +282,8 @@ impl AccessControl {
|
||||
|
||||
pub fn check_ip_in_proxy_list(&self, ip: &IpAddr) -> bool {
|
||||
match self.mode {
|
||||
Mode::BlackList => !self.black_list.check_ip_matched(ip),
|
||||
Mode::WhiteList => self.white_list.check_ip_matched(ip),
|
||||
Mode::BlackList => self.black_list.check_ip_matched(ip),
|
||||
Mode::WhiteList => !self.white_list.check_ip_matched(ip),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
-14
@@ -291,6 +291,9 @@ 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 mut reverse_lookup_cache = self.reverse_lookup_cache.lock();
|
||||
reverse_lookup_cache.insert(addr.clone(), forward);
|
||||
}
|
||||
@@ -311,21 +314,13 @@ impl Context {
|
||||
// Proxy everything by default
|
||||
None => true,
|
||||
Some(ref a) => {
|
||||
// first check the IP list
|
||||
if a.check_ip_in_proxy_list(ip) {
|
||||
true
|
||||
// do the reverse lookup in our local cache
|
||||
let mut reverse_lookup_cache = self.reverse_lookup_cache.lock();
|
||||
// if a qname is found
|
||||
if let Some(forward) = reverse_lookup_cache.get(ip) {
|
||||
!*forward
|
||||
} else {
|
||||
// do the reverse lookup in our local cache
|
||||
let mut reverse_lookup_cache = self.reverse_lookup_cache.lock();
|
||||
// if a qname is found
|
||||
if let Some(forward) = reverse_lookup_cache.get(ip) {
|
||||
// if qname is resolved by remote,
|
||||
// we should proxy it as well
|
||||
*forward
|
||||
} else {
|
||||
// by default not proxied
|
||||
false
|
||||
}
|
||||
a.check_ip_in_proxy_list(ip)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user