Skip to content

Commit

Permalink
delete: cache field in lookupip
Browse files Browse the repository at this point in the history
  • Loading branch information
justRkive committed Nov 16, 2023
1 parent 865a245 commit bb16cf8
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions src/resolver/lookup.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::client::client_error::ClientError;
use crate::dns_cache::DnsCache;
use crate::domain_name::DomainName;
use crate::message::DnsMessage;
use crate::message::header::Header;
Expand Down Expand Up @@ -34,8 +33,6 @@ pub struct LookupFutureStub {
/// The `Output` of this future is a `Result<DnsMessage, ResolverError>`.
/// The returned `DnsMessage` contains the corresponding response of the query.
query_answer: Arc<std::sync::Mutex<Pin<Box<dyn futures_util::Future<Output = Result<DnsMessage, ResolverError>> + Send>>>>,
/// Cache for the resolver.
cache: DnsCache,
/// Waker for the future.
waker: Option<Waker>,
}
Expand All @@ -59,7 +56,6 @@ impl Future for LookupFutureStub {
lookup_stub(
self.name.clone(),
self.record_type,
self.cache.clone(),
self.config.get_name_servers(),
self.waker.clone(),
referenced_query,
Expand All @@ -85,7 +81,6 @@ impl LookupFutureStub {
name: DomainName,
qtype: Qtype,
config: ResolverConfig,
cache: DnsCache
) -> Self {

Self {
Expand All @@ -94,7 +89,6 @@ impl LookupFutureStub {
config: config,
query_answer:
Arc::new(Mutex::new(future::err(ResolverError::EmptyQuery).boxed())), //FIXME: cambiar a otro tipo el error/inicio
cache: cache,
waker: None,
}
}
Expand All @@ -115,7 +109,6 @@ impl LookupFutureStub {
pub async fn lookup_stub( //FIXME: podemos ponerle de nombre lookup_strategy y que se le pase ahi un parametro strategy que diga si son los pasos o si funciona como stub
name: DomainName,
record_type: Qtype,
cache: DnsCache,
name_servers: Vec<(ClientUDPConnection, ClientTCPConnection)>,
waker: Option<Waker>,
referenced_query:Arc<std::sync::Mutex<Pin<Box<dyn futures_util::Future<Output = Result<DnsMessage, ResolverError>> + Send>>>>,
Expand Down Expand Up @@ -247,14 +240,10 @@ mod async_resolver_test {
domain_name,
record_type,
config,
cache
);

assert_eq!(lookup_future.name, DomainName::new_from_string("example.com".to_string()));
assert_eq!(lookup_future.config.get_addr(),SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 5333));
assert_eq!(lookup_future.cache.get_max_size(), 20);
assert_eq!(lookup_future.cache.get_size(), 1);

}

#[tokio::test]
Expand All @@ -274,7 +263,7 @@ mod async_resolver_test {
let record_type = Qtype::A;

let name_servers = vec![(conn_udp,conn_tcp)];
let response = lookup_stub(domain_name,record_type, cache, name_servers, waker,query,config).await.unwrap();
let response = lookup_stub(domain_name,record_type, name_servers, waker,query,config).await.unwrap();

assert_eq!(response.get_header().get_qr(),true);
assert_ne!(response.get_answer().len(),0);
Expand All @@ -299,7 +288,7 @@ mod async_resolver_test {
let record_type = Qtype::NS;

let name_servers = vec![(conn_udp,conn_tcp)];
let response = lookup_stub(domain_name, record_type, cache, name_servers, waker,query,config).await.unwrap();
let response = lookup_stub(domain_name, record_type, name_servers, waker,query,config).await.unwrap();

assert_eq!(response.get_header().get_qr(),true);
assert_ne!(response.get_answer().len(),0);
Expand Down Expand Up @@ -332,7 +321,7 @@ mod async_resolver_test {
config.set_name_servers(vec![(conn_udp,conn_tcp)]);

let name_servers = vec![(conn_udp,conn_tcp)];
let response = lookup_stub(domain_name, record_type, cache, name_servers, waker,query,config).await;
let response = lookup_stub(domain_name, record_type, name_servers, waker,query,config).await;
retries_attempted += 1;

if response.is_ok() {
Expand Down Expand Up @@ -363,7 +352,7 @@ mod async_resolver_test {
config.set_retry(3);
let cache = DnsCache::new();

let response_future = LookupFutureStub::lookup(domain_name, record_type ,config, cache).await;
let response_future = LookupFutureStub::lookup(domain_name, record_type, config).await;
println!("response_future {:?}",response_future);

assert_eq!(response_future.is_ok(), true);
Expand All @@ -388,7 +377,7 @@ mod async_resolver_test {
config.set_retry(3);
let cache = DnsCache::new();

let response_future = LookupFutureStub::lookup(domain_name, record_type ,config, cache).await;
let response_future = LookupFutureStub::lookup(domain_name, record_type ,config).await;
println!("response_future {:?}",response_future);

assert_eq!(response_future.is_ok(), true);
Expand Down Expand Up @@ -416,7 +405,7 @@ mod async_resolver_test {
config.set_retry(1);
let cache = DnsCache::new();

let response_future = LookupFutureStub::lookup(domain_name, record_type ,config, cache).await;
let response_future = LookupFutureStub::lookup(domain_name, record_type ,config).await;
println!("response_future {:?}",response_future);

assert_eq!(response_future.is_ok(), true);
Expand All @@ -442,7 +431,7 @@ mod async_resolver_test {
cache.set_max_size(1);
cache.add(domain_name.clone(), rr);

let _response_future = LookupFutureStub::lookup(domain_name, record_type, config, cache).await;
let _response_future = LookupFutureStub::lookup(domain_name, record_type, config).await;

// TODO: test
}
Expand Down

0 comments on commit bb16cf8

Please sign in to comment.