Skip to content

Commit 25d1434

Browse files
authored
chore(gossipsub): remove deprecated items
Removes deprecated items from gossipsub and make certain modules crate-private. Related #3647. Pull-Request: #3862.
1 parent f858ec6 commit 25d1434

File tree

15 files changed

+170
-343
lines changed

15 files changed

+170
-343
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protocols/gossipsub/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
- Raise MSRV to 1.65.
44
See [PR 3715].
5+
- Remove deprecated items. See [PR 3862].
56

67
[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715
8+
[PR 3862]: https://github.com/libp2p/rust-libp2p/pull/3862
79

810
## 0.44.4
911

protocols/gossipsub/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ quick-protobuf-codec = { workspace = true }
3131
hex_fmt = "0.3.0"
3232
regex = "1.8.1"
3333
serde = { version = "1", optional = true, features = ["derive"] }
34-
thiserror = "1.0"
3534
wasm-timer = "0.2.5"
3635
instant = "0.1.11"
3736
void = "1.0.2"

protocols/gossipsub/src/behaviour.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ use crate::config::{Config, ValidationMode};
5050
use crate::gossip_promises::GossipPromises;
5151
use crate::handler::{Handler, HandlerEvent, HandlerIn};
5252
use crate::mcache::MessageCache;
53-
use crate::metrics_priv::{Churn, Config as MetricsConfig, Inclusion, Metrics, Penalty};
53+
use crate::metrics::{Churn, Config as MetricsConfig, Inclusion, Metrics, Penalty};
5454
use crate::peer_score::{PeerScore, PeerScoreParams, PeerScoreThresholds, RejectReason};
55-
use crate::protocol_priv::{ProtocolConfig, SIGNING_PREFIX};
56-
use crate::subscription_filter_priv::{AllowAllSubscriptionFilter, TopicSubscriptionFilter};
57-
use crate::time_cache_priv::{DuplicateCache, TimeCache};
55+
use crate::protocol::{ProtocolConfig, SIGNING_PREFIX};
56+
use crate::subscription_filter::{AllowAllSubscriptionFilter, TopicSubscriptionFilter};
57+
use crate::time_cache::{DuplicateCache, TimeCache};
5858
use crate::topic::{Hasher, Topic, TopicHash};
5959
use crate::transform::{DataTransform, IdentityTransform};
6060
use crate::types::{
@@ -3824,7 +3824,7 @@ mod local_test {
38243824
let mut length_codec = unsigned_varint::codec::UviBytes::default();
38253825
length_codec.set_max_len(max_transmit_size);
38263826
let mut codec =
3827-
crate::protocol_priv::GossipsubCodec::new(length_codec, ValidationMode::Permissive);
3827+
crate::protocol::GossipsubCodec::new(length_codec, ValidationMode::Permissive);
38283828

38293829
let rpc_proto = rpc.into_protobuf();
38303830
let fragmented_messages = gs

protocols/gossipsub/src/behaviour/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// Collection of tests for the gossipsub network behaviour
2222

2323
use super::*;
24-
use crate::subscription_filter_priv::WhitelistSubscriptionFilter;
24+
use crate::subscription_filter::WhitelistSubscriptionFilter;
2525
use crate::transform::{DataTransform, IdentityTransform};
2626
use crate::types::FastMessageId;
2727
use crate::ValidationError;

protocols/gossipsub/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ impl std::fmt::Debug for Config {
884884
#[cfg(test)]
885885
mod test {
886886
use super::*;
887-
use crate::protocol_priv::ProtocolConfig;
887+
use crate::protocol::ProtocolConfig;
888888
use crate::topic::IdentityHash;
889889
use crate::types::PeerKind;
890890
use crate::Topic;

protocols/gossipsub/src/error.rs

Lines changed: 103 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 Protocol Labs.
1+
// Copyright 2020 Sigma Prime Pty Ltd.
22
//
33
// Permission is hereby granted, free of charge, to any person obtaining a
44
// copy of this software and associated documentation files (the "Software"),
@@ -18,26 +18,105 @@
1818
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1919
// DEALINGS IN THE SOFTWARE.
2020

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+
}

protocols/gossipsub/src/error_priv.rs

Lines changed: 0 additions & 141 deletions
This file was deleted.

protocols/gossipsub/src/handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1919
// DEALINGS IN THE SOFTWARE.
2020

21-
use crate::protocol_priv::{GossipsubCodec, ProtocolConfig};
21+
use crate::protocol::{GossipsubCodec, ProtocolConfig};
2222
use crate::rpc_proto::proto;
2323
use crate::types::{PeerKind, RawMessage, Rpc};
2424
use crate::ValidationError;

0 commit comments

Comments
 (0)