Skip to main content

irontide_dht/
error.rs

1/// Crate-level result type.
2pub type Result<T> = std::result::Result<T, Error>;
3
4/// Errors from DHT operations.
5#[derive(Debug, thiserror::Error)]
6pub enum Error {
7    /// Remote node returned a KRPC error response.
8    #[error("KRPC error ({code}): {message}")]
9    Krpc {
10        /// KRPC error code (e.g. 201 = generic, 203 = method unknown).
11        code: i64,
12        /// Human-readable error description.
13        message: String,
14    },
15
16    /// Received a malformed KRPC message.
17    #[error("invalid KRPC message: {0}")]
18    InvalidMessage(String),
19
20    /// Response transaction ID does not match the request.
21    #[error("transaction ID mismatch: expected {expected}, got {got}")]
22    TransactionMismatch {
23        /// Expected transaction ID.
24        expected: u16,
25        /// Received transaction ID.
26        got: u16,
27    },
28
29    /// Query timed out with no response.
30    #[error("query timed out")]
31    Timeout,
32
33    /// Malformed compact node info bytes.
34    #[error("invalid compact node info: {0}")]
35    InvalidCompactNode(String),
36
37    /// All k-buckets are full and no stale nodes to replace.
38    #[error("routing table full")]
39    RoutingTableFull,
40
41    /// DHT actor has been shut down.
42    #[error("DHT shutting down")]
43    Shutdown,
44
45    /// Bencode parsing error.
46    #[error("bencode: {0}")]
47    Bencode(#[from] irontide_bencode::Error),
48
49    /// I/O error.
50    #[error("I/O: {0}")]
51    Io(#[from] std::io::Error),
52
53    /// BEP 44 value exceeds the 1000-byte limit.
54    #[error("BEP 44: value too large ({size} bytes, max {max})")]
55    Bep44ValueTooLarge {
56        /// Actual value size in bytes.
57        size: usize,
58        /// Maximum allowed size.
59        max: usize,
60    },
61
62    /// BEP 44 salt exceeds the 64-byte limit.
63    #[error("BEP 44: salt too large ({size} bytes, max {max})")]
64    Bep44SaltTooLarge {
65        /// Actual salt size in bytes.
66        size: usize,
67        /// Maximum allowed size.
68        max: usize,
69    },
70
71    /// BEP 44 ed25519 signature verification failed.
72    #[error("BEP 44: invalid signature")]
73    Bep44InvalidSignature,
74
75    /// BEP 44 put rejected because sequence number is not newer.
76    #[error("BEP 44: sequence number {got} not newer than {current}")]
77    Bep44SequenceTooOld {
78        /// Sequence number in the put request.
79        got: i64,
80        /// Current stored sequence number.
81        current: i64,
82    },
83
84    /// BEP 44 CAS (compare-and-swap) failed because stored seq differs.
85    #[error("BEP 44: CAS mismatch (expected seq {expected}, got {actual})")]
86    Bep44CasMismatch {
87        /// Expected sequence number from the CAS field.
88        expected: i64,
89        /// Actual stored sequence number.
90        actual: i64,
91    },
92}