cultmesh-rs: drop the unreachable earlier-failure arm; rustfmt the resolution

receive() returns a reply only for a Ping, answered with a Pong, and a
Ping delivers no frame, so no rejection can follow an earlier send in the
same poll. The arm that carried such a failure into the rejection's end
was dead code; its mutant survived for that reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-30 21:05:45 +02:00
commit fa34b68593
3 changed files with 21 additions and 10 deletions

View file

@ -546,14 +546,13 @@ where
now_unix,
now_monotonic,
)? {
// A reply that already failed permanently this poll is not dropped:
// the session ends over it.
let end = match (unsendable.take(), &rejection.reason) {
(Some(error), _) => SessionEnd::Unsendable(error),
(None, CultMeshRudpRejectionReason::ResponseSendFailed(kind)) => {
// The only reply `receive` returns is a Pong, which delivers no
// frame, so no earlier send of this poll can precede a rejection.
let end = match &rejection.reason {
CultMeshRudpRejectionReason::ResponseSendFailed(kind) => {
SessionEnd::Unsendable(std::io::Error::from(*kind))
}
(None, reason) => SessionEnd::Rejected(reason.refusal_text()),
reason => SessionEnd::Rejected(reason.refusal_text()),
};
self.end_session(key, end)?;
return Ok(CultMeshRudpPollOutcome::ApplicationRejected(rejection));
@ -896,7 +895,11 @@ where
}
/// The refusal a rejected peer is sent, as unreliable, unordered packets.
fn refusal_packets(&self, session: &mut CultNetRudpSession, text: &str) -> Vec<CultNetRudpPacket> {
fn refusal_packets(
&self,
session: &mut CultNetRudpSession,
text: &str,
) -> Vec<CultNetRudpPacket> {
let refusal = CultNetMessage::Error {
error: text.into(),
code: None,

View file

@ -299,8 +299,13 @@ fn a_permanent_failure_sending_a_snapshot_response_rejects_it_and_sends_no_refus
}
thread::sleep(Duration::from_millis(2));
}
assert!(frames.is_empty(), "no refusal is sent to an unreachable peer: {frames:?}");
assert!(is_unsendable_reason(&reason.expect("the client was told the session ended")));
assert!(
frames.is_empty(),
"no refusal is sent to an unreachable peer: {frames:?}"
);
assert!(is_unsendable_reason(
&reason.expect("the client was told the session ended")
));
}
#[test]

View file

@ -1420,7 +1420,10 @@ fn a_refusal_reaches_a_peer_missing_an_earlier_packet() -> Result<()> {
resend_delay_ms: 10_000,
max_pending_reliable_packets: Some(64),
});
peer.send_to(&encode_rudp_packet(&session.create_connect(0, Vec::new())?)?, target)?;
peer.send_to(
&encode_rudp_packet(&session.create_connect(0, Vec::new())?)?,
target,
)?;
server.poll_once()?;
let accept = received().expect("the server accepts the connect");
assert_eq!(accept.packet_type, CultNetRudpPacketType::Accept);