From 49f8eef7b5c73271e4c9b2aed9fcaa527c7e94af Mon Sep 17 00:00:00 2001 From: ddidderr Date: Sat, 12 Sep 2026 13:07:14 +0200 Subject: [PATCH] style(peer): format security hardening Record the deterministic nightly rustfmt output for the newly added event-channel and retry code after the repository-wide formatter gate was repaired. Test Plan: - just fmt - just clippy - git diff --check --- crates/lanspread-peer/src/context.rs | 10 ++---- .../src/download/orchestrator.rs | 2 +- crates/lanspread-peer/src/download/retry.rs | 7 ++++- crates/lanspread-peer/src/handlers.rs | 31 ++++--------------- crates/lanspread-peer/src/lib.rs | 8 ++--- .../lanspread-peer/src/network_generation.rs | 6 +--- .../lanspread-peer/src/services/liveness.rs | 1 + .../src/services/remote_state.rs | 10 ++---- crates/lanspread-peer/src/startup.rs | 2 +- crates/lanspread-peer/src/transfer_status.rs | 8 ++--- 10 files changed, 24 insertions(+), 61 deletions(-) diff --git a/crates/lanspread-peer/src/context.rs b/crates/lanspread-peer/src/context.rs index c5e6a2c..39031d6 100644 --- a/crates/lanspread-peer/src/context.rs +++ b/crates/lanspread-peer/src/context.rs @@ -110,10 +110,7 @@ pub(crate) struct OutboundTransferNotifier { } impl OutboundTransferNotifier { - fn new( - state: Arc, - tx_notify_ui: PeerEventSender, - ) -> Self { + fn new(state: Arc, tx_notify_ui: PeerEventSender) -> Self { Self { state, tx_notify_ui, @@ -241,10 +238,7 @@ impl NetworkServiceCtx { } } - pub(crate) fn to_peer_ctx( - &self, - tx_notify_ui: PeerEventSender, - ) -> PeerCtx { + pub(crate) fn to_peer_ctx(&self, tx_notify_ui: PeerEventSender) -> PeerCtx { self.core.to_peer_ctx(tx_notify_ui, self.shutdown.clone()) } } diff --git a/crates/lanspread-peer/src/download/orchestrator.rs b/crates/lanspread-peer/src/download/orchestrator.rs index a5410db..9644467 100644 --- a/crates/lanspread-peer/src/download/orchestrator.rs +++ b/crates/lanspread-peer/src/download/orchestrator.rs @@ -9,7 +9,6 @@ use std::{ use futures::stream::FuturesUnordered; use lanspread_db::content_manifest::ContentId; use lanspread_proto::PeerEndpoint; -use crate::PeerEventSender; use tokio_util::sync::CancellationToken; use super::{ @@ -42,6 +41,7 @@ use crate::{ DownloadFailureReason, DownloadVerificationActivity, PeerEvent, + PeerEventSender, content_quarantine::ContentQuarantine, peer_db::PeerId, quic_runtime::QuicConnector, diff --git a/crates/lanspread-peer/src/download/retry.rs b/crates/lanspread-peer/src/download/retry.rs index 4ae5acf..6bd232e 100644 --- a/crates/lanspread-peer/src/download/retry.rs +++ b/crates/lanspread-peer/src/download/retry.rs @@ -425,7 +425,12 @@ mod tests { .map(|index| { source_at( &format!("peer-{index}"), - [192, 0, 2, u8::try_from(index + 1).expect("source index fits")], + [ + 192, + 0, + 2, + u8::try_from(index + 1).expect("source index fits"), + ], 12000 + index, ) }) diff --git a/crates/lanspread-peer/src/handlers.rs b/crates/lanspread-peer/src/handlers.rs index 5638662..c6bb619 100644 --- a/crates/lanspread-peer/src/handlers.rs +++ b/crates/lanspread-peer/src/handlers.rs @@ -14,7 +14,6 @@ use lanspread_db::{ db::GameDB, }; use lanspread_proto::PeerEndpoint; -use crate::PeerEventSender; use tokio_util::sync::CancellationToken; #[cfg(test)] @@ -25,6 +24,7 @@ use crate::{ DownloadVerificationActivity, InstallOperation, PeerEvent, + PeerEventSender, StreamInstallSettings, apply_launch_settings_to_verified_tree, content_quarantine::ContentQuarantine, @@ -545,11 +545,7 @@ async fn settle_download_completion( } /// Handles the `InstallGame` command. -pub async fn handle_install_game_command( - ctx: &Ctx, - tx_notify_ui: &PeerEventSender, - id: String, -) { +pub async fn handle_install_game_command(ctx: &Ctx, tx_notify_ui: &PeerEventSender, id: String) { let games_folder = ctx.game_dir.read().await.clone(); spawn_install_operation(ctx, tx_notify_ui, OperationTarget::new(games_folder, id)); } @@ -796,11 +792,7 @@ async fn select_stream_install_sources_or_finish( } /// Handles the `UninstallGame` command. -pub async fn handle_uninstall_game_command( - ctx: &Ctx, - tx_notify_ui: &PeerEventSender, - id: String, -) { +pub async fn handle_uninstall_game_command(ctx: &Ctx, tx_notify_ui: &PeerEventSender, id: String) { let games_folder = ctx.game_dir.read().await.clone(); let target = OperationTarget::new(games_folder, id); let ctx = ctx.clone(); @@ -1344,11 +1336,7 @@ fn promote_streamed_install( Ok(()) } -fn spawn_install_operation( - ctx: &Ctx, - tx_notify_ui: &PeerEventSender, - target: OperationTarget, -) { +fn spawn_install_operation(ctx: &Ctx, tx_notify_ui: &PeerEventSender, target: OperationTarget) { let ctx = ctx.clone(); let tx_notify_ui = tx_notify_ui.clone(); ctx.task_tracker.clone().spawn(async move { @@ -1356,11 +1344,7 @@ fn spawn_install_operation( }); } -async fn run_install_operation( - ctx: &Ctx, - tx_notify_ui: &PeerEventSender, - target: OperationTarget, -) { +async fn run_install_operation(ctx: &Ctx, tx_notify_ui: &PeerEventSender, target: OperationTarget) { let id = target.game_id().to_owned(); let Some(prepared) = prepare_install_operation(ctx, tx_notify_ui, &target).await else { return; @@ -2342,10 +2326,7 @@ async fn handle_set_game_dir_command_with_drain_timeout( } /// Loads the configured local library and announces the result. -pub async fn load_local_library( - ctx: &Ctx, - tx_notify_ui: &PeerEventSender, -) -> eyre::Result<()> { +pub async fn load_local_library(ctx: &Ctx, tx_notify_ui: &PeerEventSender) -> eyre::Result<()> { load_local_library_with_policy(ctx, tx_notify_ui, LocalLibraryEventPolicy::OnChange).await } diff --git a/crates/lanspread-peer/src/lib.rs b/crates/lanspread-peer/src/lib.rs index 7bf2f5c..58f75c2 100644 --- a/crates/lanspread-peer/src/lib.rs +++ b/crates/lanspread-peer/src/lib.rs @@ -59,6 +59,7 @@ use std::{ pub use config::CHUNK_SIZE; pub use error::PeerError; +pub use events::{PeerEventReceiver, PeerEventSender, peer_event_channel}; pub use identity::{ LoadedPeerIdentity, PeerIdentity, @@ -85,11 +86,7 @@ pub use peer_db::{ }; pub use scoped_blocking::scoped_blocking; pub use scoped_process::{ScopedProcess, ScopedProcessOutput}; -use tokio::sync::{ - RwLock, - mpsc::UnboundedReceiver, - oneshot, -}; +use tokio::sync::{RwLock, mpsc::UnboundedReceiver, oneshot}; use tokio_util::{sync::CancellationToken, task::TaskTracker}; pub use transfer_status::{ DownloadAttemptId, @@ -134,7 +131,6 @@ pub use crate::{ StreamInstallProvider, }, }; -pub use events::{PeerEventReceiver, PeerEventSender, peer_event_channel}; // ============================================================================= // Public API types diff --git a/crates/lanspread-peer/src/network_generation.rs b/crates/lanspread-peer/src/network_generation.rs index a001b2c..4291f87 100644 --- a/crates/lanspread-peer/src/network_generation.rs +++ b/crates/lanspread-peer/src/network_generation.rs @@ -808,11 +808,7 @@ fn send_state(tx_notify_ui: &PeerEventSender, state: LocalNetworkSharingState) { ); } -fn report_failure( - tx_notify_ui: &PeerEventSender, - component: PeerRuntimeComponent, - error: String, -) { +fn report_failure(tx_notify_ui: &PeerEventSender, component: PeerRuntimeComponent, error: String) { log::error!("{component:?} failed: {error}"); events::send(tx_notify_ui, PeerEvent::RuntimeFailed { component, error }); } diff --git a/crates/lanspread-peer/src/services/liveness.rs b/crates/lanspread-peer/src/services/liveness.rs index e1b58ca..f1d6329 100644 --- a/crates/lanspread-peer/src/services/liveness.rs +++ b/crates/lanspread-peer/src/services/liveness.rs @@ -3,6 +3,7 @@ use std::{sync::Arc, time::Duration}; use futures::{StreamExt as _, stream}; + use crate::{ PeerEventSender, config::{PEER_PING_IDLE_SECS, PEER_PING_INTERVAL_SECS, peer_stale_timeout}, diff --git a/crates/lanspread-peer/src/services/remote_state.rs b/crates/lanspread-peer/src/services/remote_state.rs index cf84afc..9214269 100644 --- a/crates/lanspread-peer/src/services/remote_state.rs +++ b/crates/lanspread-peer/src/services/remote_state.rs @@ -55,10 +55,7 @@ pub(crate) struct RemoteStateCtx { impl RemoteStateCtx { #[must_use] - pub(crate) fn from_network( - ctx: &NetworkServiceCtx, - tx_notify_ui: &PeerEventSender, - ) -> Self { + pub(crate) fn from_network(ctx: &NetworkServiceCtx, tx_notify_ui: &PeerEventSender) -> Self { Self { local_peer_id: ctx.peer_id, peer_game_db: ctx.peer_game_db.clone(), @@ -371,10 +368,7 @@ fn enqueue_final_views( /// Clears every remote projection after one network generation has fully /// drained, then queues the authoritative replacement views while the /// database-to-Call-to-Play lock order is still held. -pub(crate) async fn clear_remote_state_and_publish( - ctx: &Ctx, - tx_notify_ui: &PeerEventSender, -) { +pub(crate) async fn clear_remote_state_and_publish(ctx: &Ctx, tx_notify_ui: &PeerEventSender) { let mut db = ctx.peer_game_db.write().await; let mut call_to_play = ctx.call_to_play.write().await; let retired = db.clear_remote_peers(); diff --git a/crates/lanspread-peer/src/startup.rs b/crates/lanspread-peer/src/startup.rs index 632d682..57f3acd 100644 --- a/crates/lanspread-peer/src/startup.rs +++ b/crates/lanspread-peer/src/startup.rs @@ -23,9 +23,9 @@ use tokio_util::{sync::CancellationToken, task::TaskTracker}; use crate::{ PeerCommand, + PeerEventSender, PeerId, PeerIdentityDurability, - PeerEventSender, PeerRuntimeComponent, StreamInstallProvider, Unpacker, diff --git a/crates/lanspread-peer/src/transfer_status.rs b/crates/lanspread-peer/src/transfer_status.rs index 396c99b..08a6cad 100644 --- a/crates/lanspread-peer/src/transfer_status.rs +++ b/crates/lanspread-peer/src/transfer_status.rs @@ -10,10 +10,9 @@ use std::{ }; use serde::{Deserialize, Deserializer, Serialize, Serializer, de}; -use crate::PeerEventSender; use tokio_util::sync::CancellationToken; -use crate::{DownloadProgress, PeerEvent, events}; +use crate::{DownloadProgress, PeerEvent, PeerEventSender, events}; static NEXT_DOWNLOAD_ATTEMPT_ID: AtomicU64 = AtomicU64::new(1); @@ -457,10 +456,7 @@ impl ActiveDownloadSignal { mod tests { use super::*; - fn attempt() -> ( - DownloadAttemptStatus, - crate::PeerEventReceiver, - ) { + fn attempt() -> (DownloadAttemptStatus, crate::PeerEventReceiver) { let (tx, rx) = crate::peer_event_channel(); ( DownloadAttemptStatus::new(