Skip to content

Commit

Permalink
Fix compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Jotape24 committed Jan 29, 2025
1 parent b6ac4ec commit 7268ed0
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/async_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl AsyncResolver {


if self.config.get_tsig(){
self.verify_tsig(response.clone());
let _ = self.verify_tsig(response.clone());
}

return self.check_error_from_msg(response);
Expand Down
16 changes: 8 additions & 8 deletions src/async_resolver/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ impl ResolverConfig {
retransmission_loop_attempts: 3,
cache_enabled: true,
recursive_available: false,
protocol: protocol,
timeout: timeout,
protocol,
timeout,
max_retry_interval_seconds: 10,
min_retry_interval_seconds: 1,
global_retransmission_limit: 30,
Expand Down Expand Up @@ -163,14 +163,14 @@ impl ResolverConfig {
let resolver_config: ResolverConfig = ResolverConfig {
name_servers: servers_info,
bind_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 5333),
retransmission_loop_attempts: retransmission_loop_attempts,
retransmission_loop_attempts,
cache_enabled: true,
recursive_available: false,
protocol: ConnectionProtocol::UDP,
timeout: timeout,
max_retry_interval_seconds: max_retry_interval_seconds,
min_retry_interval_seconds: min_retry_interval_seconds,
global_retransmission_limit: global_retransmission_limit,
timeout,
max_retry_interval_seconds,
min_retry_interval_seconds,
global_retransmission_limit,
edns0: false,
max_payload: RECOMMENDED_MAX_PAYLOAD as u16,
bufsize: RECOMMENDED_MAX_PAYLOAD as u16,
Expand Down Expand Up @@ -318,7 +318,7 @@ impl ResolverConfig {
/// ```
#[cfg(any(target_os = "linux", target_os = "macos"))]
pub fn os_config() -> Self {
let mut path = "";
let path;
if env::consts::OS == "macos" {
path = "var/run/resolv.conf";
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/async_resolver/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct LookupStrategy {
/// Resolver configuration.
config: ResolverConfig,
/// Reference to the response of the query.
response_msg: Arc<std::sync::Mutex<Result<(DnsMessage, Vec<u8>), ResolverError>>>,
response_msg: Arc<Mutex<Result<(DnsMessage, Vec<u8>), ResolverError>>>,
}

impl LookupStrategy {
Expand All @@ -38,8 +38,8 @@ impl LookupStrategy {

) -> Self {
Self {
query: query,
config: config,
query,
config,
response_msg: Arc::new(Mutex::new(Err(ResolverError::EmptyQuery))),
}
}
Expand Down Expand Up @@ -103,7 +103,7 @@ impl LookupStrategy {
timeout_duration = tokio::time::Duration::from_secs_f64(rto);
tokio::time::sleep(timeout_duration).await;
}
return lookup_response_result;
lookup_response_result
}

/// Checks if an appropiate answer was received.
Expand All @@ -115,7 +115,7 @@ impl LookupStrategy {
// appropriate response to its caller.
pub fn received_appropriate_response(&self) -> bool {
let response_arc = self.response_msg.lock().unwrap();
if let Ok((dns_msg, bytes)) = response_arc.as_ref() {
if let Ok((dns_msg, _)) = response_arc.as_ref() {
match dns_msg.get_header().get_rcode().into() {
Rcode::SERVFAIL => return false,
Rcode::NOTIMP => return false,
Expand Down
6 changes: 3 additions & 3 deletions src/async_resolver/slist/slist_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ impl SlistElement{
/// * `response_time` - A u16 that represents the response time of the slist element
pub fn new(domain_name: DomainName, ip_address: IpAddr, response_time: u32) -> SlistElement{
SlistElement{
domain_name: domain_name,
ip_address: ip_address,
response_time: response_time,
domain_name,
ip_address,
response_time,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/udp_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl ClientConnection for ClientUDPConnection {
/// implement get_ip
/// returns IpAddr
fn get_ip(&self) -> IpAddr {
return self.server_addr.clone();
self.server_addr.clone()
}

async fn send(self, dns_query:DnsMessage) -> Result<Vec<u8>, ClientError> {
Expand Down
2 changes: 1 addition & 1 deletion src/dns_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl DnsCache {

if let Some(existing_record) = self.cache.get_mut(&key) {
// If the key is already cached
if let Some(stored) = existing_record.take(&rr_cache) {
if let Some(_) = existing_record.take(&rr_cache) {
// If a stored record with the same resource record exists, replace it
existing_record.replace(rr_cache);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/dns_cache/rr_stored_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl RRStoredData {
pub fn new(resource_record: ResourceRecord) -> Self {
let rr_cache = RRStoredData {
rcode: Rcode::NOERROR,
resource_record: resource_record,
resource_record,
response_time: 5000,
creation_time: Utc::now(),
};
Expand Down
44 changes: 26 additions & 18 deletions src/dnssec/dnssec_message.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use crate::domain_name::DomainName;
use crate::message::rclass::Rclass;
use crate::message::DnsMessage;
use crate::message::rdata::opt_rdata::OptRdata;
use crate::message::rdata::Rdata;
use crate::message::resource_record::{ResourceRecord};
use crate::message::rcode::Rcode;
use crate::message::rrtype::Rrtype;

const EDNS_VERSION: u8 = 0;
const REQUESTED_UDP_LEN: u16 = 4096;
Expand Down Expand Up @@ -45,7 +43,7 @@ fn read_opt_rr(opt_rr: ResourceRecord) -> (u16, Rcode, u8, bool) {
let (e_rcode, version) = (data[0], data[1]);
let z = u16::from_be_bytes([data[2], data[3]]);

let do_bit = ((z & 0x8000) > 0) as bool ;
let do_bit = (z & 0x8000) > 0;
(requested_udp_len, Rcode::from(e_rcode), version, do_bit)
//format!("OPT PSEUDO-RR\n\trequested_udp_len: {requested_udp_len}\n\terror code: {e_rcode}\n\tversion: EDNS{version}\n\tuse dnssec: {do_bit}")
}
Expand All @@ -64,19 +62,29 @@ fn add_opt_record_dns_message(msg: &mut DnsMessage, capacity: u16, e_rcode :Rcod
msg.update_header_counters();
}

#[test]
fn see_dnssec_message() {
let mut query = DnsMessage::new_query_message(
DomainName::new_from_str("example.com"),
Rrtype::A,
Rclass::IN,
1,
true,
2000
);
add_opt_record_dns_message(&mut query, 4096, Rcode::NOERROR, true);
let expected = (4096,Rcode::NOERROR,0,true);
assert_eq!(expected,
read_opt_rr(query.get_additional().pop().expect("No OPT Record!"))
)
#[cfg(test)]
mod dnssec_message_processing_tests {
use crate::dnssec::dnssec_message::{add_opt_record_dns_message, read_opt_rr};
use crate::domain_name::DomainName;
use crate::message::rrtype::Rrtype;
use crate::message::rclass::Rclass;
use crate::message::DnsMessage;
use crate::message::rcode::Rcode;

#[test]
fn see_dnssec_message() {
let mut query = DnsMessage::new_query_message(
DomainName::new_from_str("example.com"),
Rrtype::A,
Rclass::IN,
1,
true,
2000
);
add_opt_record_dns_message(&mut query, 4096, Rcode::NOERROR, true);
let expected = (4096, Rcode::NOERROR, 0, true);
assert_eq!(expected,
read_opt_rr(query.get_additional().pop().expect("No OPT Record!"))
)
}
}
6 changes: 3 additions & 3 deletions src/dnssec/dnssec_message_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::message::resource_record::ResourceRecord;
use crate::message::rrset::RRset;
use crate::message::rrtype::Rrtype;

use crate::message::resource_record::ToBytes;

pub fn extract_signed_rrsets(rrs: &Vec<ResourceRecord>) -> Option<Vec<(ResourceRecord, RRset)>> {
// check if there exists RRSIG records
Expand All @@ -28,7 +27,7 @@ pub fn extract_signed_rrsets(rrs: &Vec<ResourceRecord>) -> Option<Vec<(ResourceR
let rrs_filtered = rrs_filtered?;
result.push((rrsig_rr.clone(), rrs_filtered));
}
return Some(result);
Some(result)
}
#[cfg(test)]
mod dnssec_message_processing_tests {
Expand All @@ -41,6 +40,7 @@ mod dnssec_message_processing_tests {
use crate::message::resource_record::{ResourceRecord, ToBytes};
use crate::message::rrtype::Rrtype;


#[test]
pub fn test_extract_signed_rrsets() {
use std::net::IpAddr;
Expand All @@ -52,7 +52,7 @@ mod dnssec_message_processing_tests {
header.set_qr(true);
header.set_rd(true);
message.set_header(header);
let mut question = crate::message::question::Question::new();
let mut question = message::question::Question::new();
question.set_qname(DomainName::new_from_str("example.com"));
question.set_rrtype(Rrtype::A);
question.set_rclass(Rclass::IN);
Expand Down
4 changes: 2 additions & 2 deletions src/domain_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl DomainName {
}
}

let (domain_label, _bytes) = domain_name_result.unwrap();
let (domain_label, _bytes) = domain_name_result?;

let label = domain_label.get_name();

Expand Down Expand Up @@ -168,7 +168,7 @@ impl DomainName {
}
}

bytes.push(0 as u8);
bytes.push(0u8);

bytes
}
Expand Down
2 changes: 1 addition & 1 deletion src/edns/options/ede.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub mod ede_code {

pub mod ede_optdata {
use crate::edns::options::ede::ede_code::EdeCode;
use crate::message::resource_record::{FromBytes, ToBytes};
use crate::message::resource_record:: ToBytes;

/*
Extended DNS Error (EDE) information in DNS messages. The option is structured as follows:
Expand Down
2 changes: 1 addition & 1 deletion src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ impl DnsMessage {
let addi = self.get_additional();
for opt in addi.iter() {
match opt.get_rdata() {
Rdata::OPT(opt) => {
Rdata::OPT(_) => {
return true
},
_ => {}
Expand Down
2 changes: 1 addition & 1 deletion src/message/rdata/a_ch_rdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ mod a_ch_rdata_test {
let ach_rdata = AChRdata::from_bytes(&data_bytes, &data_bytes).unwrap();

assert_eq!(ach_rdata.get_domain_name().get_name(), String::from("test.com"));
assert_eq!(ach_rdata.get_ch_address(), 10 as u16);
assert_eq!(ach_rdata.get_ch_address(), 10u16);
}

//ToDo: Revisar
Expand Down
4 changes: 2 additions & 2 deletions src/message/rdata/opt_rdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl FromBytes<Result<Self, &'static str>> for OptRdata {
return Err("Format Error");
}

let option_data = option_data.unwrap();
let option_data = option_data?;

let mut option = OptOption::new(option_code);

Expand All @@ -97,7 +97,7 @@ impl OptRdata {
}
}

pub fn get_option(&self) -> Vec<(OptOption)> {
pub fn get_option(&self) -> Vec<OptOption> {
self.option.clone()
}
}
Expand Down
1 change: 0 additions & 1 deletion src/resolver_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,6 @@ impl ResolverCache {

#[cfg(test)]
mod resolver_cache_test {
use std::collections::HashSet;
use super::*;
use crate::message::question::Question;
use crate::message::rdata::a_rdata::ARdata;
Expand Down

0 comments on commit 7268ed0

Please sign in to comment.