Skip to content

Commit cb0e925

Browse files
committed
update trait return types and remove non used impl
1 parent 1a60512 commit cb0e925

File tree

2 files changed

+8
-45
lines changed

2 files changed

+8
-45
lines changed

protocols/gossipsub/src/error.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,8 @@ pub enum PartialMessageError {
180180

181181
/// The partial data doesn't belong to this message group.
182182
WrongGroup {
183-
/// Expected minimum number of bytes.
184-
expected: usize,
185-
/// Actual number of bytes received.
186-
received: usize,
183+
/// Group Id of the received message.
184+
received: Vec<u8>,
187185
},
188186

189187
/// The partial data is a duplicate of already received data.
@@ -214,12 +212,8 @@ impl std::fmt::Display for PartialMessageError {
214212
Self::InvalidFormat => {
215213
write!(f, "Invalid data format")
216214
}
217-
Self::WrongGroup { expected, received } => {
218-
write!(
219-
f,
220-
"Wrong group ID: expected {:?}, got {:?}",
221-
expected, received
222-
)
215+
Self::WrongGroup { received } => {
216+
write!(f, "Wrong group ID: got {:?}", received)
223217
}
224218
Self::DuplicateData(part_id) => {
225219
write!(f, "Duplicate data for part {:?}", part_id)

protocols/gossipsub/src/partial.rs

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub trait Partial {
3838
/// All partial messages belonging to the same logical message should return
3939
/// the same group ID. This is used to associate partial messages together
4040
/// during reconstruction.
41-
fn group_id(&self) -> &[u8];
41+
fn group_id(&self) -> impl AsRef<[u8]>;
4242

4343
/// Returns metadata describing which parts of the message are missing.
4444
///
@@ -48,7 +48,7 @@ pub trait Partial {
4848
///
4949
/// The returned bytes will be sent in PartialIWANT messages to request
5050
/// missing parts from peers.
51-
fn missing_parts(&self) -> Option<&[u8]>;
51+
fn missing_parts(&self) -> Option<impl AsRef<[u8]>>;
5252

5353
/// Returns metadata describing which parts of the message are available.
5454
///
@@ -58,7 +58,7 @@ pub trait Partial {
5858
///
5959
/// The returned bytes will be sent in PartialIHAVE messages to advertise
6060
/// available parts to peers.
61-
fn available_parts(&self) -> Option<&[u8]>;
61+
fn available_parts(&self) -> Option<impl AsRef<[u8]>>;
6262

6363
/// Generates partial message bytes from the given metadata.
6464
///
@@ -72,7 +72,7 @@ pub trait Partial {
7272
fn partial_message_bytes_from_metadata(
7373
&self,
7474
metadata: &[u8],
75-
) -> Result<(Vec<u8>, Option<Vec<u8>>), PartialMessageError>;
75+
) -> Result<(impl AsRef<[u8]>, Option<impl AsRef<[u8]>>), PartialMessageError>;
7676

7777
/// Extends this message with received partial message data.
7878
///
@@ -87,34 +87,3 @@ pub trait Partial {
8787
data: &[u8],
8888
) -> Result<(), PartialMessageError>;
8989
}
90-
91-
/// Default implementation that disables partial messages.
92-
impl Partial for () {
93-
fn group_id(&self) -> &[u8] {
94-
&[]
95-
}
96-
97-
fn missing_parts(&self) -> Option<&[u8]> {
98-
None
99-
}
100-
101-
fn available_parts(&self) -> Option<&[u8]> {
102-
None
103-
}
104-
105-
fn partial_message_bytes_from_metadata(
106-
&self,
107-
_metadata: &[u8],
108-
) -> Result<(Vec<u8>, Option<Vec<u8>>), PartialMessageError> {
109-
Ok((vec![], None))
110-
}
111-
112-
fn extend_from_encoded_partial_message(
113-
&mut self,
114-
_data: &[u8],
115-
) -> Result<(), PartialMessageError> {
116-
// This should never be called since we never advertise having or wanting parts,
117-
// but if it is called, just ignore the data silently
118-
Ok(())
119-
}
120-
}

0 commit comments

Comments
 (0)