Skip to content

Commit

Permalink
fix(client): expand quoting range by 1
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi committed Dec 12, 2024
1 parent 51a513f commit 2f3023c
Showing 1 changed file with 1 addition and 45 deletions.
46 changes: 1 addition & 45 deletions ant-networking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1063,50 +1063,6 @@ impl Network {
send_local_swarm_cmd(self.local_swarm_cmd_sender().clone(), cmd);
}

/// Returns the closest peers to the given `XorName`, sorted by their distance to the xor_name.
/// If `client` is false, then include `self` among the `closest_peers`
pub async fn get_close_group_closest_peers(
&self,
key: &NetworkAddress,
client: bool,
) -> Result<Vec<PeerId>> {
debug!("Getting the closest peers to {key:?}");
let (sender, receiver) = oneshot::channel();
self.send_network_swarm_cmd(NetworkSwarmCmd::GetClosestPeersToAddressFromNetwork {
key: key.clone(),
sender,
});
let k_bucket_peers = receiver.await?;

// Count self in if among the CLOSE_GROUP_SIZE closest and sort the result
let result_len = k_bucket_peers.len();
let mut closest_peers = k_bucket_peers;
// ensure we're not including self here
if client {
// remove our peer id from the calculations here:
closest_peers.retain(|&x| x != self.peer_id());
if result_len != closest_peers.len() {
info!("Remove self client from the closest_peers");
}
}
if tracing::level_enabled!(tracing::Level::DEBUG) {
let close_peers_pretty_print: Vec<_> = closest_peers
.iter()
.map(|peer_id| {
format!(
"{peer_id:?}({:?})",
PrettyPrintKBucketKey(NetworkAddress::from_peer(*peer_id).as_kbucket_key())
)
})
.collect();

debug!("Network knowledge of close peers to {key:?} are: {close_peers_pretty_print:?}");
}

let closest_peers = sort_peers_by_address(&closest_peers, key, CLOSE_GROUP_SIZE)?;
Ok(closest_peers.into_iter().cloned().collect())
}

/// Returns the closest peers to the given `XorName`, sorted by their distance to the xor_name.
/// If `client` is false, then include `self` among the `closest_peers`
///
Expand Down Expand Up @@ -1155,7 +1111,7 @@ impl Network {
);
}

let closest_peers = sort_peers_by_address(&closest_peers, key, CLOSE_GROUP_SIZE)?;
let closest_peers = sort_peers_by_address(&closest_peers, key, CLOSE_GROUP_SIZE + 1)?;
Ok(closest_peers.into_iter().cloned().collect())
}

Expand Down

0 comments on commit 2f3023c

Please sign in to comment.