|
1 |
| -// Copyright 2023 Protocol Labs. |
| 1 | +// Copyright 2020 Sigma Prime Pty Ltd. |
2 | 2 | //
|
3 | 3 | // Permission is hereby granted, free of charge, to any person obtaining a
|
4 | 4 | // copy of this software and associated documentation files (the "Software"),
|
|
18 | 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
19 | 19 | // DEALINGS IN THE SOFTWARE.
|
20 | 20 |
|
21 |
| -#[deprecated( |
22 |
| - since = "0.44.0", |
23 |
| - note = "Use `libp2p::gossipsub::PublishError` instead, as the `error` module will become crate-private in the future." |
24 |
| -)] |
25 |
| -pub type PublishError = crate::error_priv::PublishError; |
26 |
| - |
27 |
| -#[deprecated( |
28 |
| - since = "0.44.0", |
29 |
| - note = "Use `libp2p::gossipsub::SubscriptionError` instead, as the `error` module will become crate-private in the future." |
30 |
| -)] |
31 |
| -pub type SubscriptionError = crate::error_priv::SubscriptionError; |
32 |
| - |
33 |
| -#[deprecated(note = "This error will no longer be emitted")] |
34 |
| -pub type GossipsubHandlerError = crate::error_priv::HandlerError; |
35 |
| - |
36 |
| -#[deprecated(note = "This error will no longer be emitted")] |
37 |
| -pub type HandlerError = crate::error_priv::HandlerError; |
38 |
| - |
39 |
| -#[deprecated( |
40 |
| - since = "0.44.0", |
41 |
| - note = "Use `libp2p::gossipsub::ValidationError` instead, as the `error` module will become crate-private in the future." |
42 |
| -)] |
43 |
| -pub type ValidationError = crate::error_priv::ValidationError; |
| 21 | +//! Error types that can result from gossipsub. |
| 22 | +
|
| 23 | +use libp2p_core::identity::error::SigningError; |
| 24 | + |
| 25 | +/// Error associated with publishing a gossipsub message. |
| 26 | +#[derive(Debug)] |
| 27 | +pub enum PublishError { |
| 28 | + /// This message has already been published. |
| 29 | + Duplicate, |
| 30 | + /// An error occurred whilst signing the message. |
| 31 | + SigningError(SigningError), |
| 32 | + /// There were no peers to send this message to. |
| 33 | + InsufficientPeers, |
| 34 | + /// The overall message was too large. This could be due to excessive topics or an excessive |
| 35 | + /// message size. |
| 36 | + MessageTooLarge, |
| 37 | + /// The compression algorithm failed. |
| 38 | + TransformFailed(std::io::Error), |
| 39 | +} |
| 40 | + |
| 41 | +impl std::fmt::Display for PublishError { |
| 42 | + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
| 43 | + write!(f, "{self:?}") |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +impl std::error::Error for PublishError { |
| 48 | + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { |
| 49 | + match self { |
| 50 | + Self::SigningError(err) => Some(err), |
| 51 | + Self::TransformFailed(err) => Some(err), |
| 52 | + _ => None, |
| 53 | + } |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +/// Error associated with subscribing to a topic. |
| 58 | +#[derive(Debug)] |
| 59 | +pub enum SubscriptionError { |
| 60 | + /// Couldn't publish our subscription |
| 61 | + PublishError(PublishError), |
| 62 | + /// We are not allowed to subscribe to this topic by the subscription filter |
| 63 | + NotAllowed, |
| 64 | +} |
| 65 | + |
| 66 | +impl std::fmt::Display for SubscriptionError { |
| 67 | + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
| 68 | + write!(f, "{self:?}") |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +impl std::error::Error for SubscriptionError { |
| 73 | + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { |
| 74 | + match self { |
| 75 | + Self::PublishError(err) => Some(err), |
| 76 | + _ => None, |
| 77 | + } |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +impl From<SigningError> for PublishError { |
| 82 | + fn from(error: SigningError) -> Self { |
| 83 | + PublishError::SigningError(error) |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +#[derive(Debug, Clone, Copy)] |
| 88 | +pub enum ValidationError { |
| 89 | + /// The message has an invalid signature, |
| 90 | + InvalidSignature, |
| 91 | + /// The sequence number was empty, expected a value. |
| 92 | + EmptySequenceNumber, |
| 93 | + /// The sequence number was the incorrect size |
| 94 | + InvalidSequenceNumber, |
| 95 | + /// The PeerId was invalid |
| 96 | + InvalidPeerId, |
| 97 | + /// Signature existed when validation has been sent to |
| 98 | + /// [`crate::behaviour::MessageAuthenticity::Anonymous`]. |
| 99 | + SignaturePresent, |
| 100 | + /// Sequence number existed when validation has been sent to |
| 101 | + /// [`crate::behaviour::MessageAuthenticity::Anonymous`]. |
| 102 | + SequenceNumberPresent, |
| 103 | + /// Message source existed when validation has been sent to |
| 104 | + /// [`crate::behaviour::MessageAuthenticity::Anonymous`]. |
| 105 | + MessageSourcePresent, |
| 106 | + /// The data transformation failed. |
| 107 | + TransformFailed, |
| 108 | +} |
| 109 | + |
| 110 | +impl std::fmt::Display for ValidationError { |
| 111 | + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
| 112 | + write!(f, "{self:?}") |
| 113 | + } |
| 114 | +} |
| 115 | + |
| 116 | +impl std::error::Error for ValidationError {} |
| 117 | + |
| 118 | +impl From<std::io::Error> for PublishError { |
| 119 | + fn from(error: std::io::Error) -> PublishError { |
| 120 | + PublishError::TransformFailed(error) |
| 121 | + } |
| 122 | +} |
0 commit comments