nodecraft/resolver/
impls.rs

1/// Async DNS resolver
2#[cfg(feature = "dns")]
3#[cfg_attr(docsrs, doc(cfg(feature = "dns")))]
4pub mod dns;
5
6/// Dummy [`SocketAddr`] resolver
7#[cfg(all(feature = "std", feature = "async"))]
8#[cfg_attr(docsrs, doc(cfg(all(feature = "std", feature = "async"))))]
9pub mod socket_addr;
10
11/// [`Address`](crate::Address) resolver, but will not send DNS query
12/// and only use [`ToSocketAddrs`](std::net::ToSocketAddrs) to resolve the address.
13#[cfg(all(feature = "std", feature = "async"))]
14#[cfg_attr(docsrs, doc(cfg(all(feature = "std", feature = "async"))))]
15pub mod address;
16
17#[cfg(all(feature = "std", feature = "async"))]
18struct CachedSocketAddr {
19  val: std::net::SocketAddr,
20  born: std::time::Instant,
21  ttl: std::time::Duration,
22}
23
24#[cfg(all(feature = "std", feature = "async"))]
25impl CachedSocketAddr {
26  fn new(val: std::net::SocketAddr, ttl: std::time::Duration) -> Self {
27    Self {
28      val,
29      born: std::time::Instant::now(),
30      ttl,
31    }
32  }
33
34  fn is_expired(&self) -> bool {
35    self.born.elapsed() > self.ttl
36  }
37}