Skip to content

Commit 6f0f764

Browse files
committed
files changed as suggested
1 parent 417ecab commit 6f0f764

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

transports/dns/CHANGELOG.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
## 0.43.0
1+
## 0.44.0
2+
3+
- Report all transport errors in a dial attempt instead of only returning the last error.
4+
See [PR #5899](https://github.com/libp2p/rust-libp2p/pull/5899).
5+
6+
## 0.43.0
27

38
- Upgrade `async-std-resolver` and `hickory-resolver`.
49
See [PR 5727](https://github.com/libp2p/rust-libp2p/pull/5727)
5-
- Report all transport errors in a dial attempt instead of only returning the last error.
6-
See [PR #5899](https://github.com/libp2p/rust-libp2p/pull/5899).
10+
711

812
<!-- Update to libp2p-core v0.43.0 -->
913

transports/dns/src/lib.rs

+19-24
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ where
295295
}) {
296296
if dns_lookups == MAX_DNS_LOOKUPS {
297297
tracing::debug!(address=%addr, "Too many DNS lookups, dropping unresolved address");
298-
dial_errors.push(Error::TooManyLookups); // this is imp
298+
dial_errors.push(Error::TooManyLookups);
299299
// There may still be fully resolved addresses in `unresolved`,
300300
// so keep going until `unresolved` is empty.
301301
continue;
@@ -366,38 +366,33 @@ where
366366
Err(err) => {
367367
tracing::debug!("Dial error: {:?}.", err);
368368
dial_errors.push(err);
369+
370+
if unresolved.is_empty(){
371+
// If there are no further addresses to try—or we've hit the limit—
372+
// break out of the loop.
373+
break;
374+
}
375+
369376
if dial_attempts == MAX_DIAL_ATTEMPTS {
370377
tracing::debug!(
371378
"Aborting dialing after {} attempts.",
372379
MAX_DIAL_ATTEMPTS
373380
);
374381
break;
375382
}
376-
if unresolved.is_empty(){
377-
// If there are no further addresses to try—or we've hit the limit—
378-
// break out of the loop.
379-
break;
380-
}
383+
381384
}
382385
}
383386
}
384387
}
385-
386-
// At this point, if there was at least one failed dialing
387-
// attempt, return that error. Otherwise there were no valid DNS records
388-
// for the given address to begin with (i.e. DNS lookups succeeded but
389-
// produced no records relevant for the given `addr`).
388+
// If we have any dial errors, aggregate them. Otherwise, report that no valid
389+
// DNS records were found for the address.
390390
if !dial_errors.is_empty() {
391-
if dial_errors.len() ==1{
392-
Err(dial_errors.pop().unwrap())
393-
} else {
394-
Err(Error::DialErrors(dial_errors))
395-
}
391+
Err(Error::Dial(dial_errors))
396392
} else {
397393
Err(Error::ResolveError(ResolveErrorKind::Message("No Matching Records Found").into()))
398394
}
399-
400-
}
395+
}
401396
.boxed()
402397
.right_future()
403398
}
@@ -422,7 +417,7 @@ pub enum Error<TErr> {
422417
/// should be investigated.
423418
TooManyLookups,
424419
/// Multiple dial errors were encountered.
425-
DialErrors(Vec<Error<TErr>>),
420+
Dial(Vec<Error<TErr>>),
426421
}
427422

428423
impl<TErr> fmt::Display for Error<TErr>
@@ -435,7 +430,7 @@ where
435430
Error::ResolveError(err) => write!(f, "{err}"),
436431
Error::MultiaddrNotSupported(a) => write!(f, "Unsupported resolved address: {a}"),
437432
Error::TooManyLookups => write!(f, "Too many DNS lookups"),
438-
Error::DialErrors(errs) => {
433+
Error::Dial(errs) => {
439434
write!(f, "Multiple dial errors occured:")?;
440435
for err in errs {
441436
write!(f, "/n - {err}")?;
@@ -456,7 +451,7 @@ where
456451
Error::ResolveError(err) => Some(err),
457452
Error::MultiaddrNotSupported(_) => None,
458453
Error::TooManyLookups => None,
459-
Error::DialErrors(errs) => errs.first().and_then(|e| e.source()),
454+
Error::Dial(errs) => errs.first().and_then(|e| e.source()),
460455
}
461456
}
462457
}
@@ -819,7 +814,7 @@ mod tests {
819814
fn listen_on(
820815
&mut self,
821816
_id: ListenerId,
822-
_addr: Multiaddr,
817+
addr: Multiaddr,
823818
) -> Result<(), TransportError<Self::Error>> {
824819
unimplemented!()
825820
}
@@ -831,7 +826,7 @@ mod tests {
831826
fn dial(
832827
&mut self,
833828
_addr: Multiaddr,
834-
_opts: DialOpts,
829+
_: DialOpts,
835830
) -> Result<Self::Dial, TransportError<Self::Error>> {
836831
// Every dial attempt fails with an error that includes the address.
837832
Ok(Box::pin(future::ready(Err(io::Error::new(
@@ -867,7 +862,7 @@ mod tests {
867862
let result = dial_future.await;
868863

869864
match result {
870-
Err(Error::DialErrors(errs)) => {
865+
Err(Error::Dial(errs)) => {
871866
// We expect at least 2 errors, one per resolved IP.
872867
assert!(
873868
errs.len() >= 2,

0 commit comments

Comments
 (0)