refactor(peer): split bulk request dispatch

Move file-chunk and Stream Install branches into focused helpers so the new admission path remains within the workspace's strict Clippy limits without changing request behavior.

Test Plan:
- just clippy
- git diff --check
This commit is contained in:
2026-09-12 12:59:05 +02:00
parent b3174deabf
commit 01d92b1922
2 changed files with 68 additions and 36 deletions
+1 -2
View File
@@ -430,8 +430,7 @@ async fn run_server_body(
if !has_child_capacity(connection_tasks.len(), MAX_ESTABLISHED_CONNECTIONS) { if !has_child_capacity(connection_tasks.len(), MAX_ESTABLISHED_CONNECTIONS) {
log::warn!( log::warn!(
"Closing excess peer connection from {remote_addr} at application limit {}", "Closing excess peer connection from {remote_addr} at application limit {MAX_ESTABLISHED_CONNECTIONS}",
MAX_ESTABLISHED_CONNECTIONS,
); );
connection.close(application::Error::UNKNOWN); connection.close(application::Error::UNKNOWN);
continue; continue;
+44 -11
View File
@@ -300,13 +300,43 @@ async fn dispatch_request(
.schedule_hint(StateDomain::CallToPlay, hint, source_ip); .schedule_hint(StateDomain::CallToPlay, hint, source_ip);
DispatchResult::close(framed_tx) DispatchResult::close(framed_tx)
} }
Request::GetGameFileChunk { request @ Request::GetGameFileChunk { .. } => {
dispatch_file_chunk(ctx, request, framed_tx, stream_shutdown).await
}
Request::StreamInstall {
game_id,
content_id,
} => {
dispatch_stream_install(
ctx,
game_id,
content_id,
framed_tx,
stream_shutdown,
admission,
origin,
)
.await
}
}
}
async fn dispatch_file_chunk(
ctx: &PeerCtx,
request: Request,
framed_tx: ResponseWriter,
stream_shutdown: &CancellationToken,
) -> DispatchResult {
let Request::GetGameFileChunk {
game_id, game_id,
content_id, content_id,
relative_path, relative_path,
offset, offset,
length, length,
} => { } = request
else {
unreachable!("file-chunk dispatcher received a different request")
};
match handle_file_chunk_request( match handle_file_chunk_request(
ctx, ctx,
game_id, game_id,
@@ -322,13 +352,18 @@ async fn dispatch_request(
ChunkDispatch::Finished(writer) => DispatchResult::close(writer), ChunkDispatch::Finished(writer) => DispatchResult::close(writer),
ChunkDispatch::Reset(writer) => DispatchResult::reset(writer), ChunkDispatch::Reset(writer) => DispatchResult::reset(writer),
} }
} }
Request::StreamInstall {
game_id, async fn dispatch_stream_install(
content_id, ctx: &PeerCtx,
} => { game_id: String,
let Some(mut stream_install_admission) = admission.try_acquire_stream_install(origin) content_id: lanspread_db::content_manifest::ContentId,
else { framed_tx: ResponseWriter,
stream_shutdown: &CancellationToken,
admission: &ServerAdmission,
origin: ObservedOrigin,
) -> DispatchResult {
let Some(mut stream_install_admission) = admission.try_acquire_stream_install(origin) else {
let mut tx = framed_tx.into_inner(); let mut tx = framed_tx.into_inner();
let _ = tx.reset(application::Error::UNKNOWN); let _ = tx.reset(application::Error::UNKNOWN);
return DispatchResult::reset(FramedWrite::new(tx, control_codec())); return DispatchResult::reset(FramedWrite::new(tx, control_codec()));
@@ -345,8 +380,6 @@ async fn dispatch_request(
.await; .await;
drop(stream_install_admission); drop(stream_install_admission);
DispatchResult::close(writer) DispatchResult::close(writer)
}
}
} }
fn reset_response_writer(framed_tx: ResponseWriter, label: &str) -> DispatchResult { fn reset_response_writer(framed_tx: ResponseWriter, label: &str) -> DispatchResult {