Skip to main content

cliquenet/
error.rs

1use std::io;
2
3use thiserror::Error;
4
5use crate::{Version, addr::NetAddr, x25519::PublicKey};
6pub use crate::{addr::InvalidNetAddr, msg::InvalidHeader};
7
8/// The empty type has no values.
9#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
10pub(crate) enum Empty {}
11
12/// The various errors that can occur during networking.
13#[derive(Debug, Error)]
14pub enum NetworkError {
15    /// Generic I/O error.
16    #[error("i/o error: {0}")]
17    Io(#[from] io::Error),
18
19    /// Bind error.
20    #[error("error binding to address {0}: {1}")]
21    Bind(NetAddr, #[source] io::Error),
22
23    /// The received frame header is not valid.
24    #[error("invalid frame header: {0}")]
25    InvalidFrameHeader(#[from] InvalidHeader),
26
27    /// The received message trailer is not valid.
28    #[error("invalid message trailer")]
29    InvalidTrailer,
30
31    /// The received ack frame is not valid.
32    #[error("invalid ack frame")]
33    InvalidAck,
34
35    /// The received hello frame is not valid.
36    #[error("invalid hello frame")]
37    InvalidHello,
38
39    /// The received frame has an unknown type.
40    #[error("unknown frame type: {0}")]
41    UnknownFrameType(u8),
42
43    /// Version negotiation failed.
44    #[error("version negotiation failed, ours = {ours:?}, theirs = {theirs:?}")]
45    IncompatibleVersions {
46        ours: (Version, Version),
47        theirs: (Version, Version),
48    },
49
50    /// Generic Noise error.
51    #[error("noise error: {0}")]
52    Noise(#[from] snow::Error),
53
54    /// The Noise handshake message is not valid.
55    #[error("invalid handshake message")]
56    InvalidHandshakeMessage,
57
58    /// The total message size exceeds the allowed maximum.
59    #[error("message too large")]
60    MessageTooLarge,
61
62    /// An MPSC channel is unexpectedly closed.
63    #[error("channel closed")]
64    ChannelClosed,
65
66    /// A receive budget has unexpectedly closed.
67    #[error("receive budget closed")]
68    BudgetClosed,
69
70    /// An operation timed out.
71    #[error("timeout")]
72    Timeout,
73
74    /// A peer's I/O processing has been interrupted.
75    #[error("peer process interrupted")]
76    PeerInterrupt,
77
78    /// We have accumulated too many ACKs for a peer that we can not send
79    /// to the remote, meaning we can read fine, but not write properly.
80    #[error("too many pending acks for peer {0}")]
81    TooManyPendingAcks(PublicKey),
82}