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
This commit is contained in:
2026-09-12 13:07:14 +02:00
parent f6af9b9420
commit 49f8eef7b5
10 changed files with 24 additions and 61 deletions
+2 -8
View File
@@ -110,10 +110,7 @@ pub(crate) struct OutboundTransferNotifier {
} }
impl OutboundTransferNotifier { impl OutboundTransferNotifier {
fn new( fn new(state: Arc<AtomicU8>, tx_notify_ui: PeerEventSender) -> Self {
state: Arc<AtomicU8>,
tx_notify_ui: PeerEventSender,
) -> Self {
Self { Self {
state, state,
tx_notify_ui, tx_notify_ui,
@@ -241,10 +238,7 @@ impl NetworkServiceCtx {
} }
} }
pub(crate) fn to_peer_ctx( pub(crate) fn to_peer_ctx(&self, tx_notify_ui: PeerEventSender) -> PeerCtx {
&self,
tx_notify_ui: PeerEventSender,
) -> PeerCtx {
self.core.to_peer_ctx(tx_notify_ui, self.shutdown.clone()) self.core.to_peer_ctx(tx_notify_ui, self.shutdown.clone())
} }
} }
@@ -9,7 +9,6 @@ use std::{
use futures::stream::FuturesUnordered; use futures::stream::FuturesUnordered;
use lanspread_db::content_manifest::ContentId; use lanspread_db::content_manifest::ContentId;
use lanspread_proto::PeerEndpoint; use lanspread_proto::PeerEndpoint;
use crate::PeerEventSender;
use tokio_util::sync::CancellationToken; use tokio_util::sync::CancellationToken;
use super::{ use super::{
@@ -42,6 +41,7 @@ use crate::{
DownloadFailureReason, DownloadFailureReason,
DownloadVerificationActivity, DownloadVerificationActivity,
PeerEvent, PeerEvent,
PeerEventSender,
content_quarantine::ContentQuarantine, content_quarantine::ContentQuarantine,
peer_db::PeerId, peer_db::PeerId,
quic_runtime::QuicConnector, quic_runtime::QuicConnector,
+6 -1
View File
@@ -425,7 +425,12 @@ mod tests {
.map(|index| { .map(|index| {
source_at( source_at(
&format!("peer-{index}"), &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, 12000 + index,
) )
}) })
+6 -25
View File
@@ -14,7 +14,6 @@ use lanspread_db::{
db::GameDB, db::GameDB,
}; };
use lanspread_proto::PeerEndpoint; use lanspread_proto::PeerEndpoint;
use crate::PeerEventSender;
use tokio_util::sync::CancellationToken; use tokio_util::sync::CancellationToken;
#[cfg(test)] #[cfg(test)]
@@ -25,6 +24,7 @@ use crate::{
DownloadVerificationActivity, DownloadVerificationActivity,
InstallOperation, InstallOperation,
PeerEvent, PeerEvent,
PeerEventSender,
StreamInstallSettings, StreamInstallSettings,
apply_launch_settings_to_verified_tree, apply_launch_settings_to_verified_tree,
content_quarantine::ContentQuarantine, content_quarantine::ContentQuarantine,
@@ -545,11 +545,7 @@ async fn settle_download_completion(
} }
/// Handles the `InstallGame` command. /// Handles the `InstallGame` command.
pub async fn handle_install_game_command( pub async fn handle_install_game_command(ctx: &Ctx, tx_notify_ui: &PeerEventSender, id: String) {
ctx: &Ctx,
tx_notify_ui: &PeerEventSender,
id: String,
) {
let games_folder = ctx.game_dir.read().await.clone(); let games_folder = ctx.game_dir.read().await.clone();
spawn_install_operation(ctx, tx_notify_ui, OperationTarget::new(games_folder, id)); 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. /// Handles the `UninstallGame` command.
pub async fn handle_uninstall_game_command( pub async fn handle_uninstall_game_command(ctx: &Ctx, tx_notify_ui: &PeerEventSender, id: String) {
ctx: &Ctx,
tx_notify_ui: &PeerEventSender,
id: String,
) {
let games_folder = ctx.game_dir.read().await.clone(); let games_folder = ctx.game_dir.read().await.clone();
let target = OperationTarget::new(games_folder, id); let target = OperationTarget::new(games_folder, id);
let ctx = ctx.clone(); let ctx = ctx.clone();
@@ -1344,11 +1336,7 @@ fn promote_streamed_install(
Ok(()) Ok(())
} }
fn spawn_install_operation( fn spawn_install_operation(ctx: &Ctx, tx_notify_ui: &PeerEventSender, target: OperationTarget) {
ctx: &Ctx,
tx_notify_ui: &PeerEventSender,
target: OperationTarget,
) {
let ctx = ctx.clone(); let ctx = ctx.clone();
let tx_notify_ui = tx_notify_ui.clone(); let tx_notify_ui = tx_notify_ui.clone();
ctx.task_tracker.clone().spawn(async move { ctx.task_tracker.clone().spawn(async move {
@@ -1356,11 +1344,7 @@ fn spawn_install_operation(
}); });
} }
async fn run_install_operation( async fn run_install_operation(ctx: &Ctx, tx_notify_ui: &PeerEventSender, target: OperationTarget) {
ctx: &Ctx,
tx_notify_ui: &PeerEventSender,
target: OperationTarget,
) {
let id = target.game_id().to_owned(); let id = target.game_id().to_owned();
let Some(prepared) = prepare_install_operation(ctx, tx_notify_ui, &target).await else { let Some(prepared) = prepare_install_operation(ctx, tx_notify_ui, &target).await else {
return; return;
@@ -2342,10 +2326,7 @@ async fn handle_set_game_dir_command_with_drain_timeout(
} }
/// Loads the configured local library and announces the result. /// Loads the configured local library and announces the result.
pub async fn load_local_library( pub async fn load_local_library(ctx: &Ctx, tx_notify_ui: &PeerEventSender) -> eyre::Result<()> {
ctx: &Ctx,
tx_notify_ui: &PeerEventSender,
) -> eyre::Result<()> {
load_local_library_with_policy(ctx, tx_notify_ui, LocalLibraryEventPolicy::OnChange).await load_local_library_with_policy(ctx, tx_notify_ui, LocalLibraryEventPolicy::OnChange).await
} }
+2 -6
View File
@@ -59,6 +59,7 @@ use std::{
pub use config::CHUNK_SIZE; pub use config::CHUNK_SIZE;
pub use error::PeerError; pub use error::PeerError;
pub use events::{PeerEventReceiver, PeerEventSender, peer_event_channel};
pub use identity::{ pub use identity::{
LoadedPeerIdentity, LoadedPeerIdentity,
PeerIdentity, PeerIdentity,
@@ -85,11 +86,7 @@ pub use peer_db::{
}; };
pub use scoped_blocking::scoped_blocking; pub use scoped_blocking::scoped_blocking;
pub use scoped_process::{ScopedProcess, ScopedProcessOutput}; pub use scoped_process::{ScopedProcess, ScopedProcessOutput};
use tokio::sync::{ use tokio::sync::{RwLock, mpsc::UnboundedReceiver, oneshot};
RwLock,
mpsc::UnboundedReceiver,
oneshot,
};
use tokio_util::{sync::CancellationToken, task::TaskTracker}; use tokio_util::{sync::CancellationToken, task::TaskTracker};
pub use transfer_status::{ pub use transfer_status::{
DownloadAttemptId, DownloadAttemptId,
@@ -134,7 +131,6 @@ pub use crate::{
StreamInstallProvider, StreamInstallProvider,
}, },
}; };
pub use events::{PeerEventReceiver, PeerEventSender, peer_event_channel};
// ============================================================================= // =============================================================================
// Public API types // Public API types
@@ -808,11 +808,7 @@ fn send_state(tx_notify_ui: &PeerEventSender, state: LocalNetworkSharingState) {
); );
} }
fn report_failure( fn report_failure(tx_notify_ui: &PeerEventSender, component: PeerRuntimeComponent, error: String) {
tx_notify_ui: &PeerEventSender,
component: PeerRuntimeComponent,
error: String,
) {
log::error!("{component:?} failed: {error}"); log::error!("{component:?} failed: {error}");
events::send(tx_notify_ui, PeerEvent::RuntimeFailed { component, error }); events::send(tx_notify_ui, PeerEvent::RuntimeFailed { component, error });
} }
@@ -3,6 +3,7 @@
use std::{sync::Arc, time::Duration}; use std::{sync::Arc, time::Duration};
use futures::{StreamExt as _, stream}; use futures::{StreamExt as _, stream};
use crate::{ use crate::{
PeerEventSender, PeerEventSender,
config::{PEER_PING_IDLE_SECS, PEER_PING_INTERVAL_SECS, peer_stale_timeout}, config::{PEER_PING_IDLE_SECS, PEER_PING_INTERVAL_SECS, peer_stale_timeout},
@@ -55,10 +55,7 @@ pub(crate) struct RemoteStateCtx {
impl RemoteStateCtx { impl RemoteStateCtx {
#[must_use] #[must_use]
pub(crate) fn from_network( pub(crate) fn from_network(ctx: &NetworkServiceCtx, tx_notify_ui: &PeerEventSender) -> Self {
ctx: &NetworkServiceCtx,
tx_notify_ui: &PeerEventSender,
) -> Self {
Self { Self {
local_peer_id: ctx.peer_id, local_peer_id: ctx.peer_id,
peer_game_db: ctx.peer_game_db.clone(), 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 /// Clears every remote projection after one network generation has fully
/// drained, then queues the authoritative replacement views while the /// drained, then queues the authoritative replacement views while the
/// database-to-Call-to-Play lock order is still held. /// database-to-Call-to-Play lock order is still held.
pub(crate) async fn clear_remote_state_and_publish( pub(crate) async fn clear_remote_state_and_publish(ctx: &Ctx, tx_notify_ui: &PeerEventSender) {
ctx: &Ctx,
tx_notify_ui: &PeerEventSender,
) {
let mut db = ctx.peer_game_db.write().await; let mut db = ctx.peer_game_db.write().await;
let mut call_to_play = ctx.call_to_play.write().await; let mut call_to_play = ctx.call_to_play.write().await;
let retired = db.clear_remote_peers(); let retired = db.clear_remote_peers();
+1 -1
View File
@@ -23,9 +23,9 @@ use tokio_util::{sync::CancellationToken, task::TaskTracker};
use crate::{ use crate::{
PeerCommand, PeerCommand,
PeerEventSender,
PeerId, PeerId,
PeerIdentityDurability, PeerIdentityDurability,
PeerEventSender,
PeerRuntimeComponent, PeerRuntimeComponent,
StreamInstallProvider, StreamInstallProvider,
Unpacker, Unpacker,
+2 -6
View File
@@ -10,10 +10,9 @@ use std::{
}; };
use serde::{Deserialize, Deserializer, Serialize, Serializer, de}; use serde::{Deserialize, Deserializer, Serialize, Serializer, de};
use crate::PeerEventSender;
use tokio_util::sync::CancellationToken; 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); static NEXT_DOWNLOAD_ATTEMPT_ID: AtomicU64 = AtomicU64::new(1);
@@ -457,10 +456,7 @@ impl ActiveDownloadSignal {
mod tests { mod tests {
use super::*; use super::*;
fn attempt() -> ( fn attempt() -> (DownloadAttemptStatus, crate::PeerEventReceiver) {
DownloadAttemptStatus,
crate::PeerEventReceiver,
) {
let (tx, rx) = crate::peer_event_channel(); let (tx, rx) = crate::peer_event_channel();
( (
DownloadAttemptStatus::new( DownloadAttemptStatus::new(