From 2903b4f09a9404b1dc71402b0446286a684b31ca Mon Sep 17 00:00:00 2001 From: cloudhead Date: Fri, 10 Nov 2023 13:42:06 +0100 Subject: [PATCH] node: Don't connect to all peer's addresses Instead of connecting to the first address of a peer, we attempted to connect to all addresses, which caused problems. --- radicle-node/src/service.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/radicle-node/src/service.rs b/radicle-node/src/service.rs index f3180f82..fe058c35 100644 --- a/radicle-node/src/service.rs +++ b/radicle-node/src/service.rs @@ -1617,14 +1617,17 @@ where for (id, ka) in self .available_peers() .into_iter() - .flat_map(|(nid, kas)| kas.into_iter().map(move |ka| (nid, ka))) - .filter(|(_, ka)| match (ka.last_success, ka.last_attempt) { - // If we succeeded the last time we tried, this is a good address. - (Some(success), attempt) => success >= attempt.unwrap_or_default(), - // If we haven't succeeded yet, and we waited long enough, we can try this address. - (None, Some(attempt)) => now - attempt >= CONNECTION_RETRY_DELTA, - // If we've never tried this address, it's worth a try. - (None, None) => true, + .filter_map(|(nid, kas)| { + kas.into_iter() + .find(|ka| match (ka.last_success, ka.last_attempt) { + // If we succeeded the last time we tried, this is a good address. + (Some(success), attempt) => success >= attempt.unwrap_or_default(), + // If we haven't succeeded yet, and we waited long enough, we can try this address. + (None, Some(attempt)) => now - attempt >= CONNECTION_RETRY_DELTA, + // If we've never tried this address, it's worth a try. + (None, None) => true, + }) + .map(|ka| (nid, ka)) }) .take(wanted) {