mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 10:18:54 +00:00
chore: fix clippy warnings about HashMap iteration (#10661)
Not quite sure how these didn't get picked up by CI but they showed in my local IDE. --------- Signed-off-by: Thomas Eizinger <thomas@eizinger.io> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -4,7 +4,7 @@ mod get_user_agent;
|
||||
mod login_url;
|
||||
|
||||
use anyhow::{Context as _, Result};
|
||||
use std::collections::{HashMap, VecDeque};
|
||||
use std::collections::{BTreeMap, VecDeque};
|
||||
use std::net::{IpAddr, SocketAddr, ToSocketAddrs as _};
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
@@ -48,7 +48,7 @@ pub struct PhoenixChannel<TInitReq, TInboundMsg, TFinish> {
|
||||
|
||||
_phantom: PhantomData<TInboundMsg>,
|
||||
|
||||
pending_join_requests: HashMap<OutboundRequestId, Instant>,
|
||||
pending_join_requests: BTreeMap<OutboundRequestId, Instant>,
|
||||
|
||||
// Stored here to allow re-connecting.
|
||||
url_prototype: Secret<LoginUrl<TFinish>>,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::{
|
||||
collections::{BTreeMap, HashMap, VecDeque},
|
||||
collections::{BTreeMap, VecDeque},
|
||||
fmt,
|
||||
hash::Hash,
|
||||
iter,
|
||||
@@ -23,9 +23,9 @@ pub struct Connections<TId, RId> {
|
||||
|
||||
established_by_wireguard_session_index: BTreeMap<usize, TId>,
|
||||
|
||||
disconnected_ids: HashMap<TId, Instant>,
|
||||
disconnected_public_keys: HashMap<[u8; 32], Instant>,
|
||||
disconnected_session_indices: HashMap<usize, Instant>,
|
||||
disconnected_ids: BTreeMap<TId, Instant>,
|
||||
disconnected_public_keys: BTreeMap<[u8; 32], Instant>,
|
||||
disconnected_session_indices: BTreeMap<usize, Instant>,
|
||||
}
|
||||
|
||||
impl<TId, RId> Default for Connections<TId, RId> {
|
||||
@@ -359,9 +359,9 @@ pub struct UnknownConnection {
|
||||
}
|
||||
|
||||
impl UnknownConnection {
|
||||
fn by_id<TId>(id: TId, disconnected_ids: &HashMap<TId, Instant>, now: Instant) -> Self
|
||||
fn by_id<TId>(id: TId, disconnected_ids: &BTreeMap<TId, Instant>, now: Instant) -> Self
|
||||
where
|
||||
TId: fmt::Display + Eq + Hash,
|
||||
TId: fmt::Display + Eq + Ord,
|
||||
{
|
||||
Self {
|
||||
id: id.to_string(),
|
||||
@@ -372,7 +372,7 @@ impl UnknownConnection {
|
||||
}
|
||||
}
|
||||
|
||||
fn by_index(id: usize, disconnected_indices: &HashMap<usize, Instant>, now: Instant) -> Self {
|
||||
fn by_index(id: usize, disconnected_indices: &BTreeMap<usize, Instant>, now: Instant) -> Self {
|
||||
Self {
|
||||
id: id.to_string(),
|
||||
kind: "index",
|
||||
@@ -384,7 +384,7 @@ impl UnknownConnection {
|
||||
|
||||
fn by_public_key(
|
||||
key: [u8; 32],
|
||||
disconnected_public_keys: &HashMap<[u8; 32], Instant>,
|
||||
disconnected_public_keys: &BTreeMap<[u8; 32], Instant>,
|
||||
now: Instant,
|
||||
) -> Self {
|
||||
Self {
|
||||
|
||||
@@ -483,7 +483,7 @@ pub struct RefClient {
|
||||
|
||||
/// The expected TCP connections.
|
||||
#[debug(skip)]
|
||||
pub(crate) expected_tcp_connections: HashMap<(IpAddr, Destination, SPort, DPort), ResourceId>,
|
||||
pub(crate) expected_tcp_connections: BTreeMap<(IpAddr, Destination, SPort, DPort), ResourceId>,
|
||||
|
||||
/// The expected UDP DNS handshakes.
|
||||
#[debug(skip)]
|
||||
@@ -703,10 +703,6 @@ impl RefClient {
|
||||
}
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::disallowed_methods,
|
||||
reason = "We don't care about the ordering of the expected TCP connections."
|
||||
)]
|
||||
pub(crate) fn expected_resource_status(
|
||||
&self,
|
||||
has_failed_tcp_connection: impl Fn((SPort, DPort)) -> bool,
|
||||
@@ -1223,10 +1219,6 @@ impl RefClient {
|
||||
.contains_key(&(src, dst, sport, dport))
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::disallowed_methods,
|
||||
reason = "Iteration order does not matter here."
|
||||
)]
|
||||
pub(crate) fn tcp_connection_tuple_to_resource(
|
||||
&self,
|
||||
resource: ResourceId,
|
||||
|
||||
@@ -144,6 +144,28 @@ pub(crate) enum Destination {
|
||||
IpAddr(IpAddr),
|
||||
}
|
||||
|
||||
impl Ord for Destination {
|
||||
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
||||
match (self, other) {
|
||||
(
|
||||
Destination::DomainName { name: left, .. },
|
||||
Destination::DomainName { name: right, .. },
|
||||
) => left.cmp(right),
|
||||
(Destination::IpAddr(left), Destination::IpAddr(right)) => left.cmp(right),
|
||||
|
||||
// These are according to variant order.
|
||||
(Destination::DomainName { .. }, Destination::IpAddr(_)) => std::cmp::Ordering::Less,
|
||||
(Destination::IpAddr(_), Destination::DomainName { .. }) => std::cmp::Ordering::Greater,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for Destination {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for Destination {}
|
||||
|
||||
impl std::hash::Hash for Destination {
|
||||
|
||||
@@ -54,7 +54,7 @@ pub struct Server<R> {
|
||||
public_address: IpStack,
|
||||
|
||||
/// All client allocations, indexed by client's socket address.
|
||||
allocations: HashMap<ClientSocket, Allocation>,
|
||||
allocations: BTreeMap<ClientSocket, Allocation>,
|
||||
clients_by_allocation: HashMap<AllocationPort, ClientSocket>,
|
||||
/// Redundant mapping so we can look route data with a single lookup.
|
||||
channel_and_client_by_port_and_peer:
|
||||
|
||||
Reference in New Issue
Block a user