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