Skip to content

Commit

Permalink
chore: Provide BitswapMessage instead of bitswap_pb::Message (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusc93 authored Sep 26, 2024
1 parent 108daeb commit 052c3ca
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- refactor: Remove optional error from `UnixfsStatus`.
- refactor: Remove sled and redb datastore and dependency. [PR 304](https://github.com/dariusc93/rust-ipfs/pull/304)
- chore: Replace tokio-stream `StreamMap` with pollable-map `StreamMap`. [PR 306](https://github.com/dariusc93/rust-ipfs/pull/306)
- chore: Provide `BitswapMessage` instead of `bitswap_pb::Message`. [PR 308](https://github.com/dariusc93/rust-ipfs/pull/308)

# 0.11.21
- chore: Put libp2p-webrtc-websys behind feature.
Expand Down
7 changes: 0 additions & 7 deletions src/p2p/bitswap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,6 @@ impl NetworkBehaviour for Behaviour {
}
};

let message = BitswapMessage::from_proto(message)
.map_err(|e| {
tracing::error!(error = %e, %peer_id, "unable to parse message");
e
})
.unwrap_or_default();

if message.is_empty() {
tracing::warn!(%peer_id, %connection_id, "received an empty message");
return;
Expand Down
13 changes: 9 additions & 4 deletions src/p2p/bitswap/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<TSocket> InboundUpgrade<TSocket> for BitswapProtocol
where
TSocket: AsyncRead + AsyncWrite + Send + Unpin + 'static,
{
type Output = bitswap_pb::Message;
type Output = BitswapMessage;
type Error = io::Error;
type Future = BoxFuture<'static, Result<Self::Output, Self::Error>>;

Expand All @@ -43,6 +43,11 @@ where
.ok_or_else(|| std::io::Error::from(std::io::ErrorKind::UnexpectedEof))?
.map_err(|e| std::io::Error::new(std::io::ErrorKind::UnexpectedEof, e))?;

let message = BitswapMessage::from_proto(message).map_err(|e| {
tracing::error!(error = %e, "unable to parse message");
e
})?;

Ok(message)
})
}
Expand Down Expand Up @@ -84,13 +89,13 @@ where

#[derive(Debug)]
pub enum Message {
Receive { message: bitswap_pb::Message },
Receive { message: BitswapMessage },
Sent,
}

impl From<bitswap_pb::Message> for Message {
impl From<BitswapMessage> for Message {
#[inline]
fn from(message: bitswap_pb::Message) -> Self {
fn from(message: BitswapMessage) -> Self {
Message::Receive { message }
}
}
Expand Down

0 comments on commit 052c3ca

Please sign in to comment.