node: Small fix to allow reconnections

We weren't allowing reconnections after a failed attempt previously.
This commit is contained in:
cloudhead 2023-12-20 12:16:31 +01:00
parent 8eac221f4c
commit 9cf6fab7c8
No known key found for this signature in database
1 changed files with 6 additions and 5 deletions

View File

@ -2059,13 +2059,14 @@ where
.into_iter() .into_iter()
.find(|ka| match (ka.last_success, ka.last_attempt) { .find(|ka| match (ka.last_success, ka.last_attempt) {
// If we succeeded the last time we tried, this is a good address. // If we succeeded the last time we tried, this is a good address.
// TODO: This will always be hit after a success, and never re-attempted after // If it's been long enough that we failed to connect, we also try again.
// the first failed attempt. (Some(success), Some(attempt)) => {
(Some(success), attempt) => success >= attempt.unwrap_or_default(), success >= attempt || now - attempt >= CONNECTION_RETRY_DELTA
}
// If we haven't succeeded yet, and we waited long enough, we can try this address. // If we haven't succeeded yet, and we waited long enough, we can try this address.
(None, Some(attempt)) => now - attempt >= CONNECTION_RETRY_DELTA, (None, Some(attempt)) => now - attempt >= CONNECTION_RETRY_DELTA,
// If we've never tried this address, it's worth a try. // If we have no failed attempts for this address, it's worth a try.
(None, None) => true, (_, None) => true,
}) })
.map(|ka| (peer.nid, ka)) .map(|ka| (peer.nid, ka))
}) })