mirror of
https://github.com/Revertron/Alfis
synced 2024-11-03 15:40:19 +00:00
Changed format of DNS-listen options. Added DNS-thread count options to config.
This commit is contained in:
parent
ac915a1e92
commit
ce212ab749
@ -10,7 +10,7 @@ peers = ["test2-ip4.alfis.name:4244", "test2-ip6.alfis.name:4244"]
|
||||
|
||||
# DNS server options
|
||||
[dns]
|
||||
host = "0.0.0.0"
|
||||
port = 5300
|
||||
listen = "0.0.0.0:5300"
|
||||
threads = 20
|
||||
#AdGuard DNS servers to filter ads and trackers
|
||||
forwarders = ["94.140.14.14:53", "94.140.15.15:53"]
|
||||
|
@ -45,8 +45,7 @@ pub struct ServerContext {
|
||||
pub cache: SynchronizedCache,
|
||||
pub filters: Vec<Box<dyn DnsFilter + Sync + Send>>,
|
||||
pub client: Box<dyn DnsClient + Sync + Send>,
|
||||
pub dns_host: String,
|
||||
pub dns_port: u16,
|
||||
pub dns_listen: String,
|
||||
pub api_port: u16,
|
||||
pub resolve_strategy: ResolveStrategy,
|
||||
pub allow_recursive: bool,
|
||||
@ -70,8 +69,7 @@ impl ServerContext {
|
||||
cache: SynchronizedCache::new(),
|
||||
filters: Vec::new(),
|
||||
client: Box::new(DnsNetworkClient::new(10000 + (rand::random::<u16>() % 20000))),
|
||||
dns_host: String::from("0.0.0.0"),
|
||||
dns_port: 53,
|
||||
dns_listen: String::from("0.0.0.0:53"),
|
||||
api_port: 5380,
|
||||
resolve_strategy: ResolveStrategy::Recursive,
|
||||
allow_recursive: true,
|
||||
@ -125,8 +123,7 @@ pub mod tests {
|
||||
cache: SynchronizedCache::new(),
|
||||
filters: Vec::new(),
|
||||
client: Box::new(DnsStubClient::new(callback)),
|
||||
dns_host: String::from("0.0.0.0"),
|
||||
dns_port: 53,
|
||||
dns_listen: String::from("0.0.0.0:53"),
|
||||
api_port: 5380,
|
||||
resolve_strategy: ResolveStrategy::Recursive,
|
||||
allow_recursive: true,
|
||||
|
@ -176,7 +176,7 @@ impl DnsServer for DnsUdpServer {
|
||||
/// This method takes ownership of the server, preventing the method from being called multiple times.
|
||||
fn run_server(self) -> Result<()> {
|
||||
// Bind the socket
|
||||
let socket = UdpSocket::bind((self.context.dns_host.as_str(), self.context.dns_port))?;
|
||||
let socket = UdpSocket::bind(self.context.dns_listen.as_str())?;
|
||||
|
||||
// Spawn threads for handling requests
|
||||
for thread_id in 0..self.thread_count {
|
||||
@ -291,7 +291,7 @@ impl DnsTcpServer {
|
||||
|
||||
impl DnsServer for DnsTcpServer {
|
||||
fn run_server(mut self) -> Result<()> {
|
||||
let socket = TcpListener::bind((self.context.dns_host.as_str(), self.context.dns_port))?;
|
||||
let socket = TcpListener::bind(self.context.dns_listen.as_str())?;
|
||||
|
||||
// Spawn threads for handling requests, and create the channels
|
||||
for thread_id in 0..self.thread_count {
|
||||
|
@ -140,14 +140,14 @@ fn start_dns_server(context: &Arc<Mutex<Context>>, settings: &Settings) {
|
||||
let server_context = create_server_context(context.clone(), &settings);
|
||||
|
||||
if server_context.enable_udp {
|
||||
let udp_server = DnsUdpServer::new(server_context.clone(), 20);
|
||||
let udp_server = DnsUdpServer::new(server_context.clone(), settings.dns.threads);
|
||||
if let Err(e) = udp_server.run_server() {
|
||||
error!(target: LOG_TARGET_MAIN, "Failed to bind UDP listener: {:?}", e);
|
||||
}
|
||||
}
|
||||
|
||||
if server_context.enable_tcp {
|
||||
let tcp_server = DnsTcpServer::new(server_context.clone(), 20);
|
||||
let tcp_server = DnsTcpServer::new(server_context.clone(), settings.dns.threads);
|
||||
if let Err(e) = tcp_server.run_server() {
|
||||
error!(target: LOG_TARGET_MAIN, "Failed to bind TCP listener: {:?}", e);
|
||||
}
|
||||
@ -468,8 +468,7 @@ fn generate_key(difficulty: usize, mining: Arc<AtomicBool>) -> Option<Keystore>
|
||||
fn create_server_context(context: Arc<Mutex<Context>>, settings: &Settings) -> Arc<ServerContext> {
|
||||
let mut server_context = ServerContext::new();
|
||||
server_context.allow_recursive = true;
|
||||
server_context.dns_host = settings.dns.host.clone();
|
||||
server_context.dns_port = settings.dns.port;
|
||||
server_context.dns_listen = settings.dns.listen.clone();
|
||||
server_context.resolve_strategy = match settings.dns.forwarders.is_empty() {
|
||||
true => { ResolveStrategy::Recursive }
|
||||
false => { ResolveStrategy::Forward { upstreams: settings.dns.forwarders.clone() } }
|
||||
|
@ -46,18 +46,23 @@ impl Settings {
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct Dns {
|
||||
#[serde(default = "default_host")]
|
||||
pub host: String,
|
||||
pub port: u16,
|
||||
#[serde(default = "default_listen")]
|
||||
pub listen: String,
|
||||
#[serde(default = "default_threads")]
|
||||
pub threads: usize,
|
||||
pub forwarders: Vec<String>
|
||||
}
|
||||
|
||||
impl Default for Dns {
|
||||
fn default() -> Self {
|
||||
Dns { host: String::from("0.0.0.0"), port: 53, forwarders: Vec::new() }
|
||||
Dns { listen: String::from("0.0.0.0:53"), threads: 20, forwarders: Vec::new() }
|
||||
}
|
||||
}
|
||||
|
||||
fn default_host() -> String {
|
||||
String::from("0.0.0.0")
|
||||
fn default_listen() -> String {
|
||||
String::from("0.0.0.0:53")
|
||||
}
|
||||
|
||||
fn default_threads() -> usize {
|
||||
20
|
||||
}
|
Loading…
Reference in New Issue
Block a user