@@ -25,49 +25,32 @@ super::manager::register_plugin! {
2525
2626#[ derive( Clone ) ]
2727pub ( crate ) struct DNS {
28- ips : Vec < IpAddr > ,
2928 opts : options:: Options ,
30- core_options : Options ,
29+ resolver_config : ResolverConfig ,
30+ resolver_options : ResolverOpts ,
3131 hits : Arc < DashMap < IpAddr , usize > > ,
3232 domains : Arc < DashSet < String > > ,
3333}
3434
3535impl DNS {
3636 pub fn new ( ) -> Self {
3737 DNS {
38- ips : vec ! [ ] ,
38+ resolver_config : ResolverConfig :: default ( ) ,
39+ resolver_options : ResolverOpts :: default ( ) ,
3940 opts : options:: Options :: default ( ) ,
40- core_options : Options :: default ( ) ,
4141 hits : Arc :: new ( DashMap :: new ( ) ) ,
4242 domains : Arc :: new ( DashSet :: new ( ) ) ,
4343 }
4444 }
4545
4646 async fn get_resolver ( & self , timeout : Duration ) -> Result < TokioAsyncResolver , Error > {
47- if !self . ips . is_empty ( ) {
48- let nameserver_group =
49- NameServerConfigGroup :: from_ips_clear ( & self . ips , self . opts . dns_port , true ) ;
47+ let mut options = self . resolver_options ;
5048
51- let mut options = ResolverOpts :: default ( ) ;
49+ options. timeout = timeout ;
5250
53- options. num_concurrent_reqs = self . core_options . concurrency ;
54- options. attempts = self . opts . dns_attempts ;
55- options. timeout = timeout;
56- options. shuffle_dns_servers = true ;
51+ let config = self . resolver_config . clone ( ) ;
5752
58- Ok ( AsyncResolver :: tokio (
59- ResolverConfig :: from_parts ( None , vec ! [ ] , nameserver_group) ,
60- options,
61- ) )
62- } else {
63- let ( config, mut options) =
64- trust_dns_resolver:: system_conf:: read_system_conf ( ) . map_err ( |e| e. to_string ( ) ) ?;
65-
66- options. attempts = self . opts . dns_attempts ;
67- options. timeout = timeout;
68-
69- Ok ( AsyncResolver :: tokio ( config, options) )
70- }
53+ Ok ( AsyncResolver :: tokio ( config, options) )
7154 }
7255
7356 async fn filter ( & self , addresses : Vec < IpAddr > ) -> Vec < IpAddr > {
@@ -199,9 +182,9 @@ impl Plugin for DNS {
199182 }
200183
201184 async fn setup ( & mut self , opts : & Options ) -> Result < ( ) , Error > {
202- self . core_options = opts. clone ( ) ;
203185 self . opts = opts. dns . clone ( ) ;
204- self . ips = if let Some ( resolvers) = opts. dns . dns_resolvers . as_ref ( ) {
186+
187+ if let Some ( resolvers) = opts. dns . dns_resolvers . as_ref ( ) {
205188 let ips: Vec < IpAddr > = resolvers
206189 . split ( ',' )
207190 . map ( |s| s. trim ( ) )
@@ -211,12 +194,30 @@ impl Plugin for DNS {
211194
212195 log:: info!( "using resolvers: {:?}" , & ips) ;
213196
214- ips
197+ let nameserver_group =
198+ NameServerConfigGroup :: from_ips_clear ( & ips, self . opts . dns_port , true ) ;
199+
200+ let mut options = ResolverOpts :: default ( ) ;
201+
202+ options. num_concurrent_reqs = opts. concurrency ;
203+ options. attempts = self . opts . dns_attempts ;
204+ options. timeout = Duration :: from_millis ( opts. timeout ) ;
205+ options. shuffle_dns_servers = true ;
206+
207+ self . resolver_config = ResolverConfig :: from_parts ( None , vec ! [ ] , nameserver_group) ;
208+ self . resolver_options = options;
215209 } else {
210+ let ( config, mut options) =
211+ trust_dns_resolver:: system_conf:: read_system_conf ( ) . map_err ( |e| e. to_string ( ) ) ?;
212+
216213 log:: info!( "using system resolver" ) ;
217214
218- vec ! [ ]
219- } ;
215+ options. attempts = self . opts . dns_attempts ;
216+ options. timeout = Duration :: from_millis ( opts. timeout ) ;
217+
218+ self . resolver_config = config;
219+ self . resolver_options = options;
220+ }
220221
221222 Ok ( ( ) )
222223 }
0 commit comments