Skip to content

Commit

Permalink
add specialization for lookup_service
Browse files Browse the repository at this point in the history
  • Loading branch information
bluejekyll committed Sep 10, 2017
1 parent 080d9fc commit 56c0018
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
2 changes: 1 addition & 1 deletion resolver/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- ipv4_lookup for looking up *only* ipv4 (lookup_ip has options for dual-stack)
- ipv6_lookup for looking up *only* ipv6 (lookup_ip has options for dual-stack)
- mx_lookup for querying mail exchanges
- srv_lookup for service records
- srv_lookup for service records and also a specialized form for ease of use lookup_service
- txt_lookup for text record lookups

## 0.4.0
Expand Down
7 changes: 0 additions & 7 deletions resolver/src/lookup_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// copied, modified, or distributed except according to those terms.

//! Caching related functionality for the Resolver.
//! FIXME: rename this to LookupState?

use std::io;
use std::mem;
Expand Down Expand Up @@ -415,12 +414,6 @@ impl<C: ClientHandle + 'static> Future for QueryState<C> {
}
QueryState::InsertCache(ref mut insert_cache) => {
return insert_cache.poll();
// match insert_cache.poll() {
// // need to query since it wasn't in the cache
// Ok(Async::Ready(ips)) => return Ok(Async::Ready(ips)),
// Ok(Async::NotReady) => return Ok(Async::NotReady),
// Err(error) => return Err(error),
// }
}
QueryState::Error => panic!("invalid error state"),
}
Expand Down
24 changes: 24 additions & 0 deletions resolver/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,30 @@ impl Resolver {
)
}

// Performs a DNS lookup for an SRV record for the speicified service type and protocol at the given name.
///
/// This is a convenience method over `lookup_srv`, it combines the service, protocol and name into a single name: `_service._protocol.name`.
///
/// # Arguments
///
/// * `service` - service to lookup, e.g. ldap or http
/// * `protocol` - wire protocol, e.g. udp or tcp
/// * `name` - zone or other name at which the service is located.
pub fn lookup_service(
&self,
service: &str,
protocol: &str,
name: &str,
) -> io::Result<lookup::SrvLookup> {
self.io_loop.borrow_mut().run(
self.resolver_future.borrow().lookup_service(
service,
protocol,
name,
),
)
}

lookup_fn!(reverse_lookup, lookup::ReverseLookup, IpAddr);
lookup_fn!(ipv4_lookup, lookup::Ipv4Lookup);
lookup_fn!(ipv6_lookup, lookup::Ipv6Lookup);
Expand Down
21 changes: 19 additions & 2 deletions resolver/src/resolver_future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,28 @@ impl ResolverFuture {
};

let names = self.build_names(name);

LookupIpFuture::lookup(names, self.options.ip_strategy, self.client_cache.clone())
}

/// Performs a DNS lookup for an SRV record for the speicified service type and protocol at the given name.
///
/// This is a convenience method over `lookup_srv`, it combines the service, protocol and name into a single name: `_service._protocol.name`.
///
/// # Arguments
///
/// * `service` - service to lookup, e.g. ldap or http
/// * `protocol` - wire protocol, e.g. udp or tcp
/// * `name` - zone or other name at which the service is located.
pub fn lookup_service(
&self,
service: &str,
protocol: &str,
name: &str,
) -> lookup::SrvLookupFuture {
let name = format!("_{}._{}.{}", service, protocol, name);
self.srv_lookup(&name)
}

lookup_fn!(
reverse_lookup,
lookup::ReverseLookupFuture,
Expand All @@ -181,7 +199,6 @@ impl ResolverFuture {
lookup_fn!(ipv4_lookup, lookup::Ipv4LookupFuture, RecordType::A);
lookup_fn!(ipv6_lookup, lookup::Ipv6LookupFuture, RecordType::AAAA);
lookup_fn!(mx_lookup, lookup::MxLookupFuture, RecordType::MX);
// TODO: SRV records should be constructed from service+protocol+name
lookup_fn!(srv_lookup, lookup::SrvLookupFuture, RecordType::SRV);
lookup_fn!(txt_lookup, lookup::TxtLookupFuture, RecordType::TXT);
}
Expand Down

0 comments on commit 56c0018

Please sign in to comment.