File tree Expand file tree Collapse file tree 1 file changed +9
-15
lines changed Expand file tree Collapse file tree 1 file changed +9
-15
lines changed Original file line number Diff line number Diff line change 1+ use itertools:: Itertools ;
12use tokio:: net:: lookup_host;
23use tracing:: warn;
34use uuid:: Uuid ;
@@ -270,7 +271,6 @@ pub(crate) struct ResolvedContactPoint {
270271// The resolution may return multiple IPs and the function returns one of them.
271272// It prefers to return IPv4s first, and only if there are none, IPv6s.
272273pub ( crate ) async fn resolve_hostname ( hostname : & str ) -> Result < SocketAddr , io:: Error > {
273- let mut ret = None ;
274274 let addrs = match lookup_host ( hostname) . await {
275275 Ok ( addrs) => itertools:: Either :: Left ( addrs) ,
276276 // Use a default port in case of error, but propagate the original error on failure
@@ -279,21 +279,15 @@ pub(crate) async fn resolve_hostname(hostname: &str) -> Result<SocketAddr, io::E
279279 itertools:: Either :: Right ( addrs)
280280 }
281281 } ;
282- for a in addrs {
283- match a {
284- SocketAddr :: V4 ( _) => return Ok ( a) ,
285- _ => {
286- ret = Some ( a) ;
287- }
288- }
289- }
290282
291- ret. ok_or_else ( || {
292- io:: Error :: new (
293- io:: ErrorKind :: Other ,
294- format ! ( "Empty address list returned by DNS for {}" , hostname) ,
295- )
296- } )
283+ addrs
284+ . find_or_last ( |addr| matches ! ( addr, SocketAddr :: V4 ( _) ) )
285+ . ok_or_else ( || {
286+ io:: Error :: new (
287+ io:: ErrorKind :: Other ,
288+ format ! ( "Empty address list returned by DNS for {}" , hostname) ,
289+ )
290+ } )
297291}
298292
299293/// Transforms the given [`InternalKnownNode`]s into [`ContactPoint`]s.
You can’t perform that action at this time.
0 commit comments