irtt_server/error.rs
1use irtt_proto::ProtoError;
2use thiserror::Error;
3
4/// An internal server failure.
5///
6/// This type deliberately does **not** describe rejected traffic. Malformed,
7/// unauthenticated, unsupported and policy-refused datagrams are not errors:
8/// the protocol defines no rejection response, so they are answered with
9/// silence and reported as `Ok(None)` from
10/// [`ServerCore::handle_datagram`](crate::ServerCore::handle_datagram). An
11/// inbound [`ProtoError`] never reaches a caller — that is the whole point of
12/// the admission boundary, which turns hostile UDP into a dropped datagram
13/// rather than a failure.
14///
15/// Every variant here is instead something wrong on *this* side, where the
16/// server could not do its job for a request it had already accepted.
17#[derive(Debug, Error, PartialEq, Eq)]
18pub enum ServerError {
19 /// The operating system's random source failed, so no session token could
20 /// be drawn.
21 #[error("the operating system random source failed: {reason}")]
22 RandomSource { reason: String },
23 /// No unique non-zero token was found within the retry budget.
24 ///
25 /// Each attempt drew a fresh value and rejected it as zero or as a
26 /// collision with a live session. With a working random source this is
27 /// vanishingly unlikely; it exists so token allocation cannot spin forever
28 /// on a degenerate source.
29 #[error("no unique non-zero session token after {attempts} attempts")]
30 TokenExhausted { attempts: u32 },
31 /// A reply the server itself constructed could not be encoded.
32 ///
33 /// The `ProtoError` here always describes server-generated bytes, never
34 /// anything a peer sent.
35 #[error("could not encode a server-generated reply: {source}")]
36 ReplyEncoding {
37 #[source]
38 source: ProtoError,
39 },
40}