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
/// Pickleback specific errors
#[derive(Debug)]
pub enum PicklebackError {
/// A wrapped io:Error
Io(std::io::Error),
/// Tried to insert into a sequence buffer, but sequence is too old for buffer
SequenceTooOld,
/// Parsing packet format error
InvalidPacket,
/// Packet arrived too late to be useful / out of sequence
StalePacket,
/// Already received this packet
DuplicatePacket,
/// Parsing message format error
InvalidMessage,
/// Can't send due to backpressure (num of unacks, bandwidth, etc)
Backpressure(Backpressure),
/// Payload exceeds max_message_size from config
PayloadTooBig,
/// Channel doesn't exist
NoSuchChannel,
/// Packets received from wrong source
SocketAddrMismatch,
}
/// Reasons for not being able to send due to backpressure
#[derive(Debug)]
pub enum Backpressure {
/// There are too many unacked packets outstanding, so we can't send any more
/// until we receive some acks.
TooManyPending,
// TODO: bandwidth related reasons, once implemented.
}
impl std::fmt::Display for PicklebackError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{self:?}")
}
}
impl std::error::Error for PicklebackError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Io(err) => Some(err),
_ => None,
}
}
}
impl From<std::io::Error> for PicklebackError {
fn from(err: std::io::Error) -> Self {
PicklebackError::Io(err)
}
}