-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- ref shadowsocks/shadowsocks-android#2650 - Server's builtin DNS will not use local-dns-addr
- Loading branch information
Showing
8 changed files
with
153 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//! DNS configurations | ||
#[cfg(unix)] | ||
use std::{convert::Infallible, path::PathBuf}; | ||
use std::{ | ||
fmt::{self, Display}, | ||
net::SocketAddr, | ||
str::FromStr, | ||
}; | ||
|
||
/// DNS name server address | ||
#[derive(Debug, Clone, Eq, PartialEq, Hash)] | ||
pub enum NameServerAddr { | ||
/// IP address | ||
SocketAddr(SocketAddr), | ||
/// Unix Domain Socket address | ||
/// | ||
/// Specifically used by Android, which served as a stream protocol based DNS server | ||
#[cfg(unix)] | ||
UnixSocketAddr(PathBuf), | ||
} | ||
|
||
/// Parse `NameServerAddr` error | ||
#[cfg(unix)] | ||
pub type NameServerAddrError = Infallible; | ||
/// Parse `NameServerAddr` error | ||
#[cfg(not(unix))] | ||
pub type NameServerAddrError = <SocketAddr as FromStr>::Err; | ||
|
||
impl FromStr for NameServerAddr { | ||
type Err = NameServerAddrError; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
match s.parse::<SocketAddr>() { | ||
Ok(addr) => Ok(NameServerAddr::SocketAddr(addr)), | ||
#[cfg(unix)] | ||
Err(..) => Ok(NameServerAddr::UnixSocketAddr(PathBuf::from(s))), | ||
#[cfg(not(unix))] | ||
Err(err) => Err(err), | ||
} | ||
} | ||
} | ||
|
||
impl Display for NameServerAddr { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match *self { | ||
NameServerAddr::SocketAddr(ref sa) => Display::fmt(sa, f), | ||
#[cfg(unix)] | ||
NameServerAddr::UnixSocketAddr(ref p) => write!(f, "{}", p.display()), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
//! Customized DNS resolver | ||
pub use self::server::Dns; | ||
pub use self::{config::NameServerAddr, server::Dns}; | ||
|
||
mod client_cache; | ||
pub mod config; | ||
pub mod server; | ||
mod upstream; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters