Skip to content

Commit

Permalink
query TYPE_A and TYPE_AAAA via Command::Resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
keepsimple1 committed Mar 19, 2024
1 parent ed1541f commit e295cb2
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/service_daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ impl ServiceDaemon {
},

Command::Resolve(instance, try_count) => {
let pending_query = zc.query_missing_srv(&instance);
let pending_query = zc.query_unresolved(&instance);
let max_try = 3;
if pending_query && try_count < max_try {
// Note that if the current try already succeeds, the next retransmission
Expand Down Expand Up @@ -1446,20 +1446,29 @@ impl Zeroconf {
true
}

/// Sends TYPE_ANY query for instances who are missing SRV records.
/// Returns true, if sent query. Returns false if SRV already exists.
fn query_missing_srv(&mut self, instance: &str) -> bool {
if self.cache.srv.contains_key(instance) {
return false;
}

fn query_unresolved(&mut self, instance: &str) -> bool {
if !valid_instance_name(instance) {
debug!("instance name {} not valid", instance);
return false;
}

self.send_query(instance, TYPE_ANY);
true
if let Some(records) = self.cache.srv.get(instance) {
for record in records {
if let Some(srv) = record.any().downcast_ref::<DnsSrv>() {
if self.cache.addr.get(&srv.host).is_none() {
self.send_query(&srv.host, TYPE_A);
self.send_query(&srv.host, TYPE_AAAA);
return true;
}
}
}
} else {
self.send_query(instance, TYPE_ANY);
return true;
}

false
}

/// Checks if `ty_domain` has records in the cache. If yes, sends the
Expand Down

0 comments on commit e295cb2

Please sign in to comment.