*: Don't leak prost dependency in error types (#3058)

With the current design, a major version bump of `prost` leaks into
all consumers of `prost-codec`.
This commit is contained in:
Thomas Eizinger
2022-11-02 23:02:21 +11:00
committed by GitHub
parent b42f28630e
commit 71131e0622
70 changed files with 428 additions and 400 deletions

View File

@ -51,7 +51,30 @@
See [PR 3001].
- Introduce [`libp2p-tls` `v0.1.0`](transports/tls/CHANGELOG.md#010). See [PR 2945].
- Update individual crates.
- Update to [`libp2p-autonat` `v0.89.0`](protocols/autonat/CHANGELOG.md#090).
- Update to [`libp2p-core` `v0.38.0`](core/CHANGELOG.md#0380).
- Update to [`libp2p-dcutr` `v0.8.0`](protocols/dcutr/CHANGELOG.md#080).
- Update to [`libp2p-deflate` `v0.38.0`](transports/deflate/CHANGELOG.md#0380).
- Update to [`libp2p-dns` `v0.38.0`](transports/dns/CHANGELOG.md#0380).
- Update to [`libp2p-floodsub` `v0.41.0`](protocols/floodsub/CHANGELOG.md#0410).
- Update to [`libp2p-gossipsub` `v0.43.0`](protocols/gossipsub/CHANGELOG.md#0430).
- Update to [`libp2p-identify` `v0.41.0`](protocols/identify/CHANGELOG.md#0410).
- Update to [`libp2p-kad` `v0.42.0`](protocols/kad/CHANGELOG.md#0420).
- Update to [`libp2p-mdns` `v0.42.0`](protocols/mdns/CHANGELOG.md#0420).
- Update to [`libp2p-metrics` `v0.11.0`](misc/metrics/CHANGELOG.md#0110).
- Update to [`libp2p-mplex` `v0.38.0`](muxers/mplex/CHANGELOG.md#0380).
- Update to [`libp2p-noise` `v0.41.0`](transports/noise/CHANGELOG.md#0410).
- Update to [`libp2p-ping` `v0.41.0`](protocols/ping/CHANGELOG.md#0410).
- Update to [`libp2p-plaintext` `v0.38.0`](transports/plaintext/CHANGELOG.md#0380).
- Update to [`libp2p-relay` `v0.14.0`](protocols/relay/CHANGELOG.md#0140).
- Update to [`libp2p-rendezvous` `v0.11.0`](protocols/rendezovus/CHANGELOG.md#0110).
- Update to [`libp2p-request-response` `v0.23.0`](protocols/request-response/CHANGELOG.md#0230).
- Update to [`libp2p-swarm` `v0.41.0`](swarm/CHANGELOG.md#0410).
- Update to [`libp2p-tcp` `v0.38.0`](transports/tcp/CHANGELOG.md#0380).
- Update to [`libp2p-uds` `v0.37.0`](transports/uds/CHANGELOG.md#0370).
- Update to [`libp2p-wasm-ext` `v0.38.0`](transports/wasm-ext/CHANGELOG.md#0380).
- Update to [`libp2p-websocket` `v0.40.0`](transports/websocket/CHANGELOG.md#0400).
- Update to [`libp2p-yamux` `v0.42.0`](muxers/yamux/CHANGELOG.md#0420).
[PR 2945]: https://github.com/libp2p/rust-libp2p/pull/2945
[PR 3001]: https://github.com/libp2p/rust-libp2p/pull/3001

View File

@ -86,41 +86,41 @@ getrandom = "0.2.3" # Explicit dependency to be used in `wasm-bindgen` feature
instant = "0.1.11" # Explicit dependency to be used in `wasm-bindgen` feature
lazy_static = "1.2"
libp2p-autonat = { version = "0.8.0", path = "protocols/autonat", optional = true }
libp2p-core = { version = "0.37.0", path = "core" }
libp2p-dcutr = { version = "0.7.0", path = "protocols/dcutr", optional = true }
libp2p-floodsub = { version = "0.40.1", path = "protocols/floodsub", optional = true }
libp2p-identify = { version = "0.40.0", path = "protocols/identify", optional = true }
libp2p-kad = { version = "0.41.0", path = "protocols/kad", optional = true }
libp2p-metrics = { version = "0.10.0", path = "misc/metrics", optional = true }
libp2p-mplex = { version = "0.37.0", path = "muxers/mplex", optional = true }
libp2p-noise = { version = "0.40.0", path = "transports/noise", optional = true }
libp2p-ping = { version = "0.40.1", path = "protocols/ping", optional = true }
libp2p-plaintext = { version = "0.37.0", path = "transports/plaintext", optional = true }
libp2p-autonat = { version = "0.9.0", path = "protocols/autonat", optional = true }
libp2p-core = { version = "0.38.0", path = "core" }
libp2p-dcutr = { version = "0.8.0", path = "protocols/dcutr", optional = true }
libp2p-floodsub = { version = "0.41.0", path = "protocols/floodsub", optional = true }
libp2p-identify = { version = "0.41.0", path = "protocols/identify", optional = true }
libp2p-kad = { version = "0.42.0", path = "protocols/kad", optional = true }
libp2p-metrics = { version = "0.11.0", path = "misc/metrics", optional = true }
libp2p-mplex = { version = "0.38.0", path = "muxers/mplex", optional = true }
libp2p-noise = { version = "0.41.0", path = "transports/noise", optional = true }
libp2p-ping = { version = "0.41.0", path = "protocols/ping", optional = true }
libp2p-plaintext = { version = "0.38.0", path = "transports/plaintext", optional = true }
libp2p-pnet = { version = "0.22.1", path = "transports/pnet", optional = true }
libp2p-relay = { version = "0.13.0", path = "protocols/relay", optional = true }
libp2p-rendezvous = { version = "0.10.0", path = "protocols/rendezvous", optional = true }
libp2p-request-response = { version = "0.22.1", path = "protocols/request-response", optional = true }
libp2p-swarm = { version = "0.40.1", path = "swarm" }
libp2p-relay = { version = "0.14.0", path = "protocols/relay", optional = true }
libp2p-rendezvous = { version = "0.11.0", path = "protocols/rendezvous", optional = true }
libp2p-request-response = { version = "0.23.0", path = "protocols/request-response", optional = true }
libp2p-swarm = { version = "0.41.0", path = "swarm" }
libp2p-swarm-derive = { version = "0.30.1", path = "swarm-derive" }
libp2p-uds = { version = "0.36.0", path = "transports/uds", optional = true }
libp2p-wasm-ext = { version = "0.37.0", path = "transports/wasm-ext", optional = true }
libp2p-yamux = { version = "0.41.0", path = "muxers/yamux", optional = true }
libp2p-uds = { version = "0.37.0", path = "transports/uds", optional = true }
libp2p-wasm-ext = { version = "0.38.0", path = "transports/wasm-ext", optional = true }
libp2p-yamux = { version = "0.42.0", path = "muxers/yamux", optional = true }
multiaddr = { version = "0.14.0" }
parking_lot = "0.12.0"
pin-project = "1.0.0"
smallvec = "1.6.1"
[target.'cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))'.dependencies]
libp2p-deflate = { version = "0.37.0", path = "transports/deflate", optional = true }
libp2p-dns = { version = "0.37.0", path = "transports/dns", optional = true }
libp2p-mdns = { version = "0.41.0", path = "protocols/mdns", optional = true }
libp2p-deflate = { version = "0.38.0", path = "transports/deflate", optional = true }
libp2p-dns = { version = "0.38.0", path = "transports/dns", optional = true }
libp2p-mdns = { version = "0.42.0", path = "protocols/mdns", optional = true }
libp2p-tcp = { version = "0.38.0", path = "transports/tcp", optional = true }
libp2p-websocket = { version = "0.39.0", path = "transports/websocket", optional = true }
libp2p-websocket = { version = "0.40.0", path = "transports/websocket", optional = true }
libp2p-tls = { version = "0.1.0-alpha", path = "transports/tls", optional = true }
[target.'cfg(not(target_os = "unknown"))'.dependencies]
libp2p-gossipsub = { version = "0.42.1", path = "protocols/gossipsub", optional = true }
libp2p-gossipsub = { version = "0.43.0", path = "protocols/gossipsub", optional = true }
[dev-dependencies]
async-std = { version = "1.6.2", features = ["attributes"] }

View File

@ -1,3 +1,9 @@
# 0.38.0 [unreleased]
- Hide `prost::Error` from public API in `FromEnvelopeError::InvalidPeerRecord` and `signed_envelope::DecodingError`. See [PR 3058].
[PR 3058]: https://github.com/libp2p/rust-libp2p/pull/3058
# 0.37.0
- Implement `Hash` and `Ord` for `PublicKey`. See [PR 2915].

View File

@ -3,7 +3,7 @@ name = "libp2p-core"
edition = "2021"
rust-version = "1.56.1"
description = "Core traits and structs of libp2p"
version = "0.37.0"
version = "0.38.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"

View File

@ -79,6 +79,10 @@ pub use translation::address_translation;
pub use transport::Transport;
pub use upgrade::{InboundUpgrade, OutboundUpgrade, ProtocolName, UpgradeError, UpgradeInfo};
#[derive(thiserror::Error, Debug)]
#[error(transparent)]
pub struct DecodeError(prost::DecodeError);
use std::{future::Future, pin::Pin};
/// Implemented on objects that can run a `Future` in the background.

View File

@ -1,10 +1,9 @@
use crate::identity::error::SigningError;
use crate::identity::Keypair;
use crate::signed_envelope::SignedEnvelope;
use crate::{peer_record_proto, signed_envelope, Multiaddr, PeerId};
use crate::{peer_record_proto, signed_envelope, DecodeError, Multiaddr, PeerId};
use instant::SystemTime;
use std::convert::TryInto;
use std::fmt;
const PAYLOAD_TYPE: &str = "/libp2p/routing-state-record";
const DOMAIN_SEP: &str = "libp2p-routing-state";
@ -34,7 +33,7 @@ impl PeerRecord {
let (payload, signing_key) =
envelope.payload_and_signing_key(String::from(DOMAIN_SEP), PAYLOAD_TYPE.as_bytes())?;
let record = peer_record_proto::PeerRecord::decode(payload)?;
let record = peer_record_proto::PeerRecord::decode(payload).map_err(DecodeError)?;
let peer_id = PeerId::from_bytes(&record.peer_id)?;
@ -124,73 +123,23 @@ impl PeerRecord {
}
}
#[derive(Debug)]
#[derive(thiserror::Error, Debug)]
pub enum FromEnvelopeError {
/// Failed to extract the payload from the envelope.
BadPayload(signed_envelope::ReadPayloadError),
#[error("Failed to extract payload from envelope")]
BadPayload(#[from] signed_envelope::ReadPayloadError),
/// Failed to decode the provided bytes as a [`PeerRecord`].
InvalidPeerRecord(prost::DecodeError),
#[error("Failed to decode bytes as PeerRecord")]
InvalidPeerRecord(#[from] DecodeError),
/// Failed to decode the peer ID.
InvalidPeerId(multihash::Error),
#[error("Failed to decode bytes as PeerId")]
InvalidPeerId(#[from] multihash::Error),
/// The signer of the envelope is different than the peer id in the record.
#[error("The signer of the envelope is different than the peer id in the record")]
MismatchedSignature,
/// Failed to decode a multi-address.
InvalidMultiaddr(multiaddr::Error),
}
impl From<signed_envelope::ReadPayloadError> for FromEnvelopeError {
fn from(e: signed_envelope::ReadPayloadError) -> Self {
Self::BadPayload(e)
}
}
impl From<prost::DecodeError> for FromEnvelopeError {
fn from(e: prost::DecodeError) -> Self {
Self::InvalidPeerRecord(e)
}
}
impl From<multihash::Error> for FromEnvelopeError {
fn from(e: multihash::Error) -> Self {
Self::InvalidPeerId(e)
}
}
impl From<multiaddr::Error> for FromEnvelopeError {
fn from(e: multiaddr::Error) -> Self {
Self::InvalidMultiaddr(e)
}
}
impl fmt::Display for FromEnvelopeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::BadPayload(_) => write!(f, "Failed to extract payload from envelope"),
Self::InvalidPeerRecord(_) => {
write!(f, "Failed to decode bytes as PeerRecord")
}
Self::InvalidPeerId(_) => write!(f, "Failed to decode bytes as PeerId"),
Self::MismatchedSignature => write!(
f,
"The signer of the envelope is different than the peer id in the record"
),
Self::InvalidMultiaddr(_) => {
write!(f, "Failed to decode bytes as MultiAddress")
}
}
}
}
impl std::error::Error for FromEnvelopeError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::InvalidPeerRecord(inner) => Some(inner),
Self::InvalidPeerId(inner) => Some(inner),
Self::MismatchedSignature => None,
Self::InvalidMultiaddr(inner) => Some(inner),
Self::BadPayload(inner) => Some(inner),
}
}
#[error("Failed to decode bytes as MultiAddress")]
InvalidMultiaddr(#[from] multiaddr::Error),
}
#[cfg(test)]

View File

@ -1,6 +1,6 @@
use crate::identity::error::SigningError;
use crate::identity::Keypair;
use crate::{identity, PublicKey};
use crate::{identity, DecodeError, PublicKey};
use std::convert::TryInto;
use std::fmt;
use unsigned_varint::encode::usize_buffer;
@ -94,7 +94,7 @@ impl SignedEnvelope {
pub fn from_protobuf_encoding(bytes: &[u8]) -> Result<Self, DecodingError> {
use prost::Message;
let envelope = crate::envelope_proto::Envelope::decode(bytes)?;
let envelope = crate::envelope_proto::Envelope::decode(bytes).map_err(DecodeError)?;
Ok(Self {
key: envelope
@ -140,48 +140,19 @@ fn signature_payload(domain_separation: String, payload_type: &[u8], payload: &[
}
/// Errors that occur whilst decoding a [`SignedEnvelope`] from its byte representation.
#[derive(Debug)]
#[derive(thiserror::Error, Debug)]
pub enum DecodingError {
/// Decoding the provided bytes as a signed envelope failed.
InvalidEnvelope(prost::DecodeError),
#[error("Failed to decode envelope")]
InvalidEnvelope(#[from] DecodeError),
/// The public key in the envelope could not be converted to our internal public key type.
InvalidPublicKey(identity::error::DecodingError),
#[error("Failed to convert public key")]
InvalidPublicKey(#[from] identity::error::DecodingError),
/// The public key in the envelope could not be converted to our internal public key type.
#[error("Public key is missing from protobuf struct")]
MissingPublicKey,
}
impl From<prost::DecodeError> for DecodingError {
fn from(e: prost::DecodeError) -> Self {
Self::InvalidEnvelope(e)
}
}
impl From<identity::error::DecodingError> for DecodingError {
fn from(e: identity::error::DecodingError) -> Self {
Self::InvalidPublicKey(e)
}
}
impl fmt::Display for DecodingError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidEnvelope(_) => write!(f, "Failed to decode envelope"),
Self::InvalidPublicKey(_) => write!(f, "Failed to convert public key"),
Self::MissingPublicKey => write!(f, "Public key is missing from protobuf struct"),
}
}
}
impl std::error::Error for DecodingError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::InvalidEnvelope(inner) => Some(inner),
Self::InvalidPublicKey(inner) => Some(inner),
Self::MissingPublicKey => None,
}
}
}
/// Errors that occur whilst extracting the payload of a [`SignedEnvelope`].
#[derive(Debug)]
pub enum ReadPayloadError {

View File

@ -14,5 +14,5 @@ clap = { version = "4.0.13", features = ["derive"] }
zeroize = "1"
serde = { version = "1.0.136", features = ["derive"] }
serde_json = "1.0.79"
libp2p-core = { version = "0.37.0", path = "../../core" }
libp2p-core = { version = "0.38.0", path = "../../core" }
base64 = "0.13.0"

View File

@ -1,3 +1,21 @@
# 0.11.0 [unreleased]
- Update to `libp2p-dcutr` `v0.8.0`.
- Update to `libp2p-identify` `v0.41.0`.
- Update to `libp2p-relay` `v0.14.0`.
- Update to `libp2p-core` `v0.38.0`.
- Update to `libp2p-swarm` `v0.41.0`.
- Update to `libp2p-ping` `v0.41.0`.
- Update to `libp2p-kad` `v0.42.0`.
- Update to `libp2p-gossipsub` `v0.43.0`.
# 0.10.0
- Update to `libp2p-swarm` `v0.40.0`.
@ -129,6 +147,7 @@
- Drop support for gossipsub in wasm32-unknown-unknown target (see [PR 2506]).
[PR 2442]: https://github.com/libp2p/rust-libp2p/pull/2442
[PR 2506]: https://github.com/libp2p/rust-libp2p/pull/2506
# 0.3.0 [2022-01-27]

View File

@ -3,7 +3,7 @@ name = "libp2p-metrics"
edition = "2021"
rust-version = "1.56.1"
description = "Metrics for libp2p"
version = "0.10.0"
version = "0.11.0"
authors = ["Max Inden <mail@max-inden.de>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -19,17 +19,17 @@ relay = ["libp2p-relay"]
dcutr = ["libp2p-dcutr"]
[dependencies]
libp2p-core = { version = "0.37.0", path = "../../core" }
libp2p-dcutr = { version = "0.7.0", path = "../../protocols/dcutr", optional = true }
libp2p-identify = { version = "0.40.0", path = "../../protocols/identify", optional = true }
libp2p-kad = { version = "0.41.0", path = "../../protocols/kad", optional = true }
libp2p-ping = { version = "0.40.0", path = "../../protocols/ping", optional = true }
libp2p-relay = { version = "0.13.0", path = "../../protocols/relay", optional = true }
libp2p-swarm = { version = "0.40.0", path = "../../swarm" }
libp2p-core = { version = "0.38.0", path = "../../core" }
libp2p-dcutr = { version = "0.8.0", path = "../../protocols/dcutr", optional = true }
libp2p-identify = { version = "0.41.0", path = "../../protocols/identify", optional = true }
libp2p-kad = { version = "0.42.0", path = "../../protocols/kad", optional = true }
libp2p-ping = { version = "0.41.0", path = "../../protocols/ping", optional = true }
libp2p-relay = { version = "0.14.0", path = "../../protocols/relay", optional = true }
libp2p-swarm = { version = "0.41.0", path = "../../swarm" }
prometheus-client = "0.18.0"
[target.'cfg(not(target_os = "unknown"))'.dependencies]
libp2p-gossipsub = { version = "0.42.0", path = "../../protocols/gossipsub", optional = true }
libp2p-gossipsub = { version = "0.43.0", path = "../../protocols/gossipsub", optional = true }
[dev-dependencies]
log = "0.4.0"

View File

@ -1,3 +1,9 @@
# 0.3.0 [unreleased]
- Don't leak `prost` dependency in `Error` type. See [PR 3058].
[PR 3058]: https://github.com/libp2p/rust-libp2p/pull/3058/
# 0.2.0
- Update to prost(-build) `v0.11`. See [PR 2788].

View File

@ -3,7 +3,7 @@ name = "prost-codec"
edition = "2021"
rust-version = "1.56.1"
description = "Asynchronous de-/encoding of Protobuf structs using asynchronous-codec, unsigned-varint and prost."
version = "0.2.0"
version = "0.3.0"
authors = ["Max Inden <mail@max-inden.de>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"

View File

@ -5,7 +5,6 @@ use bytes::BytesMut;
use prost::Message;
use std::io::Cursor;
use std::marker::PhantomData;
use thiserror::Error;
use unsigned_varint::codec::UviBytes;
/// [`Codec`] implements [`Encoder`] and [`Decoder`], uses [`unsigned_varint`]
@ -36,17 +35,13 @@ impl<In: Message, Out> Encoder for Codec<In, Out> {
type Item = In;
type Error = Error;
fn encode(
&mut self,
item: Self::Item,
dst: &mut asynchronous_codec::BytesMut,
) -> Result<(), Self::Error> {
fn encode(&mut self, item: Self::Item, dst: &mut BytesMut) -> Result<(), Self::Error> {
let mut encoded_msg = BytesMut::new();
item.encode(&mut encoded_msg)
.expect("BytesMut to have sufficient capacity.");
self.uvi
.encode(encoded_msg.freeze(), dst)
.map_err(|e| e.into())
self.uvi.encode(encoded_msg.freeze(), dst)?;
Ok(())
}
}
@ -54,30 +49,19 @@ impl<In, Out: Message + Default> Decoder for Codec<In, Out> {
type Item = Out;
type Error = Error;
fn decode(
&mut self,
src: &mut asynchronous_codec::BytesMut,
) -> Result<Option<Self::Item>, Self::Error> {
Ok(self
.uvi
.decode(src)?
.map(|msg| Message::decode(Cursor::new(msg)))
.transpose()?)
fn decode(&mut self, src: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> {
let msg = match self.uvi.decode(src)? {
None => return Ok(None),
Some(msg) => msg,
};
let message = Message::decode(Cursor::new(msg))
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?;
Ok(Some(message))
}
}
#[derive(Debug, Error)]
pub enum Error {
#[error("Failed to decode response: {0}.")]
Decode(
#[from]
#[source]
prost::DecodeError,
),
#[error("Io error {0}")]
Io(
#[from]
#[source]
std::io::Error,
),
}
#[derive(thiserror::Error, Debug)]
#[error("Failed to encode/decode message")]
pub struct Error(#[from] std::io::Error);

View File

@ -1,3 +1,7 @@
# 0.38.0 [unreleased]
- Update to `libp2p-core` `v0.38.0`.
# 0.37.0
- Bump rand to 0.8 and quickcheck to 1. See [PR 2857].

View File

@ -3,7 +3,7 @@ name = "libp2p-mplex"
edition = "2021"
rust-version = "1.56.1"
description = "Mplex multiplexing protocol for libp2p"
version = "0.37.0"
version = "0.38.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -14,7 +14,7 @@ categories = ["network-programming", "asynchronous"]
bytes = "1"
futures = "0.3.1"
asynchronous-codec = "0.6"
libp2p-core = { version = "0.37.0", path = "../../core" }
libp2p-core = { version = "0.38.0", path = "../../core" }
log = "0.4"
nohash-hasher = "0.2"
parking_lot = "0.12"

View File

@ -1,3 +1,7 @@
# 0.42.0 [unreleased]
- Update to `libp2p-core` `v0.38.0`.
# 0.41.0
- Update to `libp2p-core` `v0.37.0`.

View File

@ -3,7 +3,7 @@ name = "libp2p-yamux"
edition = "2021"
rust-version = "1.56.1"
description = "Yamux multiplexing protocol for libp2p"
version = "0.41.0"
version = "0.42.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"]
[dependencies]
futures = "0.3.1"
libp2p-core = { version = "0.37.0", path = "../../core" }
libp2p-core = { version = "0.38.0", path = "../../core" }
parking_lot = "0.12"
thiserror = "1.0"
yamux = "0.10.0"

View File

@ -1,3 +1,11 @@
# 0.9.0 [unreleased]
- Update to `libp2p-core` `v0.38.0`.
- Update to `libp2p-swarm` `v0.41.0`.
- Update to `libp2p-request-response` `v0.23.0`.
# 0.8.0
- Update to `libp2p-core` `v0.37.0`.

View File

@ -3,7 +3,7 @@ name = "libp2p-autonat"
edition = "2021"
rust-version = "1.56.1"
description = "NAT and firewall detection for libp2p"
version = "0.8.0"
version = "0.9.0"
authors = ["David Craven <david@craven.ch>", "Elena Frank <elena.frank@protonmail.com>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -18,9 +18,9 @@ async-trait = "0.1"
futures = "0.3"
futures-timer = "3.0"
instant = "0.1"
libp2p-core = { version = "0.37.0", path = "../../core" }
libp2p-swarm = { version = "0.40.0", path = "../../swarm" }
libp2p-request-response = { version = "0.22.0", path = "../request-response" }
libp2p-core = { version = "0.38.0", path = "../../core" }
libp2p-swarm = { version = "0.41.0", path = "../../swarm" }
libp2p-request-response = { version = "0.23.0", path = "../request-response" }
log = "0.4"
rand = "0.8"
prost = "0.11"

View File

@ -1,3 +1,11 @@
# 0.8.0 [unreleased]
- Update to `prost-codec` `v0.3.0`.
- Update to `libp2p-core` `v0.38.0`.
- Update to `libp2p-swarm` `v0.41.0`.
# 0.7.0
- Update to `libp2p-core` `v0.37.0`.

View File

@ -3,7 +3,7 @@ name = "libp2p-dcutr"
edition = "2021"
rust-version = "1.56.1"
description = "Direct connection upgrade through relay"
version = "0.7.0"
version = "0.8.0"
authors = ["Max Inden <mail@max-inden.de>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -17,10 +17,10 @@ either = "1.6.0"
futures = "0.3.1"
futures-timer = "3.0"
instant = "0.1.11"
libp2p-core = { version = "0.37.0", path = "../../core" }
libp2p-swarm = { version = "0.40.0", path = "../../swarm" }
libp2p-core = { version = "0.38.0", path = "../../core" }
libp2p-swarm = { version = "0.41.0", path = "../../swarm" }
log = "0.4"
prost-codec = { version = "0.2", path = "../../misc/prost-codec" }
prost-codec = { version = "0.3", path = "../../misc/prost-codec" }
prost = "0.11"
thiserror = "1.0"
void = "1"

View File

@ -118,12 +118,8 @@ impl PendingConnect {
#[derive(Debug, Error)]
pub enum UpgradeError {
#[error("Failed to encode or decode")]
Codec(
#[from]
#[source]
prost_codec::Error,
),
#[error(transparent)]
Codec(#[from] prost_codec::Error),
#[error("Stream closed")]
StreamClosed,
#[error("Expected at least one address in reservation.")]

View File

@ -116,12 +116,8 @@ pub struct Connect {
#[derive(Debug, Error)]
pub enum UpgradeError {
#[error("Failed to encode or decode: {0}")]
Codec(
#[from]
#[source]
prost_codec::Error,
),
#[error(transparent)]
Codec(#[from] prost_codec::Error),
#[error("Stream closed")]
StreamClosed,
#[error("Expected 'status' field to be set.")]

View File

@ -1,3 +1,9 @@
# 0.41.0 [unreleased]
- Update to `libp2p-core` `v0.38.0`.
- Update to `libp2p-swarm` `v0.41.0`.
# 0.40.0
- Bump rand to 0.8 and quickcheck to 1. See [PR 2857].

View File

@ -3,7 +3,7 @@ name = "libp2p-floodsub"
edition = "2021"
rust-version = "1.56.1"
description = "Floodsub protocol for libp2p"
version = "0.40.1"
version = "0.41.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -14,12 +14,13 @@ categories = ["network-programming", "asynchronous"]
cuckoofilter = "0.5.0"
fnv = "1.0"
futures = "0.3.1"
libp2p-core = { version = "0.37.0", path = "../../core" }
libp2p-swarm = { version = "0.40.0", path = "../../swarm" }
libp2p-core = { version = "0.38.0", path = "../../core" }
libp2p-swarm = { version = "0.41.0", path = "../../swarm" }
log = "0.4"
prost = "0.11"
rand = "0.8"
smallvec = "1.6.1"
thiserror = "1.0.37"
[build-dependencies]
prost-build = "0.11"

View File

@ -26,7 +26,7 @@ use futures::{
};
use libp2p_core::{upgrade, InboundUpgrade, OutboundUpgrade, PeerId, UpgradeInfo};
use prost::Message;
use std::{error, fmt, io, iter, pin::Pin};
use std::{io, iter, pin::Pin};
/// Implementation of `ConnectionUpgrade` for the floodsub protocol.
#[derive(Debug, Clone, Default)]
@ -59,7 +59,7 @@ where
fn upgrade_inbound(self, mut socket: TSocket, _: Self::Info) -> Self::Future {
Box::pin(async move {
let packet = upgrade::read_length_prefixed(&mut socket, 2048).await?;
let rpc = rpc_proto::Rpc::decode(&packet[..])?;
let rpc = rpc_proto::Rpc::decode(&packet[..]).map_err(DecodeError)?;
let mut messages = Vec::with_capacity(rpc.publish.len());
for publish in rpc.publish.into_iter() {
@ -92,53 +92,22 @@ where
}
/// Reach attempt interrupt errors.
#[derive(Debug)]
#[derive(thiserror::Error, Debug)]
pub enum FloodsubDecodeError {
/// Error when reading the packet from the socket.
ReadError(io::Error),
#[error("Failed to read from socket")]
ReadError(#[from] io::Error),
/// Error when decoding the raw buffer into a protobuf.
ProtobufError(prost::DecodeError),
#[error("Failed to decode protobuf")]
ProtobufError(#[from] DecodeError),
/// Error when parsing the `PeerId` in the message.
#[error("Failed to decode PeerId from message")]
InvalidPeerId,
}
impl From<io::Error> for FloodsubDecodeError {
fn from(err: io::Error) -> Self {
FloodsubDecodeError::ReadError(err)
}
}
impl From<prost::DecodeError> for FloodsubDecodeError {
fn from(err: prost::DecodeError) -> Self {
FloodsubDecodeError::ProtobufError(err)
}
}
impl fmt::Display for FloodsubDecodeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
FloodsubDecodeError::ReadError(ref err) => {
write!(f, "Error while reading from socket: {}", err)
}
FloodsubDecodeError::ProtobufError(ref err) => {
write!(f, "Error while decoding protobuf: {}", err)
}
FloodsubDecodeError::InvalidPeerId => {
write!(f, "Error while decoding PeerId from message")
}
}
}
}
impl error::Error for FloodsubDecodeError {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match *self {
FloodsubDecodeError::ReadError(ref err) => Some(err),
FloodsubDecodeError::ProtobufError(ref err) => Some(err),
FloodsubDecodeError::InvalidPeerId => None,
}
}
}
#[derive(thiserror::Error, Debug)]
#[error(transparent)]
pub struct DecodeError(prost::DecodeError);
/// An RPC received by the floodsub system.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]

View File

@ -1,3 +1,9 @@
# 0.43.0 [unreleased]
- Update to `libp2p-core` `v0.38.0`.
- Update to `libp2p-swarm` `v0.41.0`.
# 0.42.0
- Bump rand to 0.8 and quickcheck to 1. See [PR 2857].

View File

@ -3,7 +3,7 @@ name = "libp2p-gossipsub"
edition = "2021"
rust-version = "1.56.1"
description = "Gossipsub protocol for libp2p"
version = "0.42.1"
version = "0.43.0"
authors = ["Age Manning <Age@AgeManning.com>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -11,8 +11,8 @@ keywords = ["peer-to-peer", "libp2p", "networking"]
categories = ["network-programming", "asynchronous"]
[dependencies]
libp2p-swarm = { version = "0.40.0", path = "../../swarm" }
libp2p-core = { version = "0.37.0", path = "../../core" }
libp2p-swarm = { version = "0.41.0", path = "../../swarm" }
libp2p-core = { version = "0.38.0", path = "../../core" }
bytes = "1.0"
byteorder = "1.3.4"
fnv = "1.0.7"

View File

@ -1,3 +1,11 @@
# 0.41.0 [unreleased]
- Update to `prost-codec` `v0.3.0`.
- Update to `libp2p-core` `v0.38.0`.
- Update to `libp2p-swarm` `v0.41.0`.
# 0.40.0
- Update dependencies.

View File

@ -3,7 +3,7 @@ name = "libp2p-identify"
edition = "2021"
rust-version = "1.56.1"
description = "Nodes identifcation protocol for libp2p"
version = "0.40.0"
version = "0.41.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -14,11 +14,11 @@ categories = ["network-programming", "asynchronous"]
asynchronous-codec = "0.6"
futures = "0.3.1"
futures-timer = "3.0.2"
libp2p-core = { version = "0.37.0", path = "../../core" }
libp2p-swarm = { version = "0.40.0", path = "../../swarm" }
libp2p-core = { version = "0.38.0", path = "../../core" }
libp2p-swarm = { version = "0.41.0", path = "../../swarm" }
log = "0.4.1"
lru = "0.8.0"
prost-codec = { version = "0.2", path = "../../misc/prost-codec" }
prost-codec = { version = "0.3", path = "../../misc/prost-codec" }
prost = "0.11"
smallvec = "1.6.1"
thiserror = "1.0"

View File

@ -259,32 +259,16 @@ impl TryFrom<structs_proto::Identify> for Info {
#[derive(Debug, Error)]
pub enum UpgradeError {
#[error("Failed to encode or decode")]
Codec(
#[from]
#[source]
prost_codec::Error,
),
#[error(transparent)]
Codec(#[from] prost_codec::Error),
#[error("I/O interaction failed")]
Io(
#[from]
#[source]
io::Error,
),
Io(#[from] io::Error),
#[error("Stream closed")]
StreamClosed,
#[error("Failed decoding multiaddr")]
Multiaddr(
#[from]
#[source]
multiaddr::Error,
),
Multiaddr(#[from] multiaddr::Error),
#[error("Failed decoding public key")]
PublicKey(
#[from]
#[source]
identity::error::DecodingError,
),
PublicKey(#[from] identity::error::DecodingError),
}
#[cfg(test)]

View File

@ -1,3 +1,9 @@
# 0.42.0 [unreleased]
- Update to `libp2p-core` `v0.38.0`.
- Update to `libp2p-swarm` `v0.41.0`.
# 0.41.0
- Remove deprecated `set_protocol_name()` from `KademliaConfig` & `KademliaProtocolConfig`.

View File

@ -3,7 +3,7 @@ name = "libp2p-kad"
edition = "2021"
rust-version = "1.56.1"
description = "Kademlia protocol for libp2p"
version = "0.41.0"
version = "0.42.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -18,8 +18,8 @@ fnv = "1.0"
asynchronous-codec = "0.6"
futures = "0.3.1"
log = "0.4"
libp2p-core = { version = "0.37.0", path = "../../core" }
libp2p-swarm = { version = "0.40.0", path = "../../swarm" }
libp2p-core = { version = "0.38.0", path = "../../core" }
libp2p-swarm = { version = "0.41.0", path = "../../swarm" }
prost = "0.11"
rand = "0.8"
sha2 = "0.10.0"

View File

@ -1,3 +1,9 @@
# 0.42.0 [unreleased]
- Update to `libp2p-core` `v0.38.0`.
- Update to `libp2p-swarm` `v0.41.0`.
# 0.41.0
- Remove default features. If you previously depended on `async-io` you need to enable this explicitly now. See [PR 2918].

View File

@ -2,7 +2,7 @@
name = "libp2p-mdns"
edition = "2021"
rust-version = "1.56.1"
version = "0.41.0"
version = "0.42.0"
description = "Implementation of the libp2p mDNS discovery method"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
@ -15,8 +15,8 @@ data-encoding = "2.3.2"
dns-parser = "0.8.0"
futures = "0.3.13"
if-watch = "2.0.0"
libp2p-core = { version = "0.37.0", path = "../../core" }
libp2p-swarm = { version = "0.40.0", path = "../../swarm" }
libp2p-core = { version = "0.38.0", path = "../../core" }
libp2p-swarm = { version = "0.41.0", path = "../../swarm" }
log = "0.4.14"
rand = "0.8.3"
smallvec = "1.6.1"

View File

@ -1,3 +1,9 @@
# 0.41.0 [unreleased]
- Update to `libp2p-core` `v0.38.0`.
- Update to `libp2p-swarm` `v0.41.0`.
# 0.40.0
- Bump rand to 0.8 and quickcheck to 1. See [PR 2857].

View File

@ -3,7 +3,7 @@ name = "libp2p-ping"
edition = "2021"
rust-version = "1.56.1"
description = "Ping protocol for libp2p"
version = "0.40.1"
version = "0.41.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -14,8 +14,8 @@ categories = ["network-programming", "asynchronous"]
futures = "0.3.1"
futures-timer = "3.0.2"
instant = "0.1.11"
libp2p-core = { version = "0.37.0", path = "../../core" }
libp2p-swarm = { version = "0.40.0", path = "../../swarm" }
libp2p-core = { version = "0.38.0", path = "../../core" }
libp2p-swarm = { version = "0.41.0", path = "../../swarm" }
log = "0.4.1"
rand = "0.8"
void = "1.0"

View File

@ -1,3 +1,11 @@
# 0.14.0 [unreleased]
- Update to `prost-codec` `v0.3.0`.
- Update to `libp2p-core` `v0.38.0`.
- Update to `libp2p-swarm` `v0.41.0`.
# 0.13.0
- Update to `libp2p-core` `v0.37.0`.

View File

@ -3,7 +3,7 @@ name = "libp2p-relay"
edition = "2021"
rust-version = "1.56.1"
description = "Communications relaying for libp2p"
version = "0.13.0"
version = "0.14.0"
authors = ["Parity Technologies <admin@parity.io>", "Max Inden <mail@max-inden.de>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -17,11 +17,11 @@ either = "1.6.0"
futures = "0.3.1"
futures-timer = "3"
instant = "0.1.11"
libp2p-core = { version = "0.37.0", path = "../../core" }
libp2p-swarm = { version = "0.40.0", path = "../../swarm" }
libp2p-core = { version = "0.38.0", path = "../../core" }
libp2p-swarm = { version = "0.41.0", path = "../../swarm" }
log = "0.4"
pin-project = "1"
prost-codec = { version = "0.2", path = "../../misc/prost-codec" }
prost-codec = { version = "0.3", path = "../../misc/prost-codec" }
prost = "0.11"
rand = "0.8.4"
smallvec = "1.6.1"

View File

@ -104,12 +104,8 @@ impl From<prost_codec::Error> for UpgradeError {
#[derive(Debug, Error)]
pub enum FatalUpgradeError {
#[error("Failed to encode or decode")]
Codec(
#[from]
#[source]
prost_codec::Error,
),
#[error(transparent)]
Codec(#[from] prost_codec::Error),
#[error("Stream closed")]
StreamClosed,
#[error("Failed to parse response type field.")]

View File

@ -92,12 +92,8 @@ impl From<prost_codec::Error> for UpgradeError {
#[derive(Debug, Error)]
pub enum FatalUpgradeError {
#[error("Failed to encode or decode")]
Codec(
#[from]
#[source]
prost_codec::Error,
),
#[error(transparent)]
Codec(#[from] prost_codec::Error),
#[error("Stream closed")]
StreamClosed,
#[error("Failed to parse response type field.")]

View File

@ -233,12 +233,8 @@ pub enum ReservationFailedReason {
#[derive(Debug, Error)]
pub enum FatalUpgradeError {
#[error("Failed to encode or decode")]
Codec(
#[from]
#[source]
prost_codec::Error,
),
#[error(transparent)]
Codec(#[from] prost_codec::Error),
#[error("Stream closed")]
StreamClosed,
#[error("Expected 'status' field to be set.")]

View File

@ -146,12 +146,8 @@ pub enum CircuitFailedReason {
#[derive(Debug, Error)]
pub enum FatalUpgradeError {
#[error("Failed to encode or decode")]
Codec(
#[from]
#[source]
prost_codec::Error,
),
#[error(transparent)]
Codec(#[from] prost_codec::Error),
#[error("Stream closed")]
StreamClosed,
#[error("Expected 'status' field to be set.")]

View File

@ -1,3 +1,13 @@
# 0.11.0 [unreleased]
- De- and encode protobuf messages using `prost-codec`. See [PR 3058].
- Update to `libp2p-core` `v0.38.0`.
- Update to `libp2p-swarm` `v0.41.0`.
[PR 3058]: https://github.com/libp2p/rust-libp2p/pull/3058
# 0.10.0
- Update to `libp2p-core` `v0.37.0`.

View File

@ -3,7 +3,7 @@ name = "libp2p-rendezvous"
edition = "2021"
rust-version = "1.56.1"
description = "Rendezvous protocol for libp2p"
version = "0.10.0"
version = "0.11.0"
authors = ["The COMIT guys <hello@comit.network>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -12,19 +12,20 @@ categories = ["network-programming", "asynchronous"]
[dependencies]
asynchronous-codec = "0.6"
libp2p-core = { version = "0.37.0", path = "../../core" }
libp2p-swarm = { version = "0.40.0", path = "../../swarm" }
prost = "0.11"
void = "1"
log = "0.4"
futures = { version = "0.3", default-features = false, features = ["std"] }
thiserror = "1"
unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] }
bimap = "0.6.1"
sha2 = "0.10"
rand = "0.8"
futures = { version = "0.3", default-features = false, features = ["std"] }
futures-timer = "3.0.2"
instant = "0.1.11"
libp2p-core = { version = "0.38.0", path = "../../core" }
libp2p-swarm = { version = "0.41.0", path = "../../swarm" }
log = "0.4"
prost = "0.11"
prost-codec = { version = "0.3.0", path = "../../misc/prost-codec" }
rand = "0.8"
sha2 = "0.10"
thiserror = "1"
unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] }
void = "1"
[dev-dependencies]
async-trait = "0.1"

View File

@ -19,12 +19,11 @@
// DEALINGS IN THE SOFTWARE.
use crate::DEFAULT_TTL;
use asynchronous_codec::{Bytes, BytesMut, Decoder, Encoder};
use asynchronous_codec::{BytesMut, Decoder, Encoder};
use libp2p_core::{peer_record, signed_envelope, PeerRecord, SignedEnvelope};
use rand::RngCore;
use std::convert::{TryFrom, TryInto};
use std::fmt;
use unsigned_varint::codec::UviBytes;
pub type Ttl = u64;
@ -201,16 +200,14 @@ pub enum ErrorCode {
}
pub struct RendezvousCodec {
/// Codec to encode/decode the Unsigned varint length prefix of the frames.
length_codec: UviBytes,
inner: prost_codec::Codec<wire::Message>,
}
impl Default for RendezvousCodec {
fn default() -> Self {
let mut length_codec = UviBytes::default();
length_codec.set_max_len(1024 * 1024); // 1MB
Self { length_codec }
Self {
inner: prost_codec::Codec::new(1024 * 1024), // 1MB
}
}
}
@ -219,18 +216,7 @@ impl Encoder for RendezvousCodec {
type Error = Error;
fn encode(&mut self, item: Self::Item, dst: &mut BytesMut) -> Result<(), Self::Error> {
use prost::Message;
let message = wire::Message::from(item);
let mut buf = Vec::with_capacity(message.encoded_len());
message
.encode(&mut buf)
.expect("Buffer has sufficient capacity");
// Length prefix the protobuf message, ensuring the max limit is not hit
self.length_codec.encode(Bytes::from(buf), dst)?;
self.inner.encode(wire::Message::from(item), dst)?;
Ok(())
}
@ -241,25 +227,19 @@ impl Decoder for RendezvousCodec {
type Error = Error;
fn decode(&mut self, src: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> {
use prost::Message;
let message = match self.length_codec.decode(src)? {
let message = match self.inner.decode(src)? {
Some(p) => p,
None => return Ok(None),
};
let message = wire::Message::decode(message)?;
Ok(Some(message.try_into()?))
}
}
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("Failed to encode message as bytes")]
Encode(#[from] prost::EncodeError),
#[error("Failed to decode message from bytes")]
Decode(#[from] prost::DecodeError),
#[error(transparent)]
Codec(#[from] prost_codec::Error),
#[error("Failed to read/write")]
Io(#[from] std::io::Error),
#[error("Failed to convert wire message to internal data model")]

View File

@ -1,3 +1,9 @@
# 0.23.0 [unreleased]
- Update to `libp2p-core` `v0.38.0`.
- Update to `libp2p-swarm` `v0.41.0`.
# 0.22.0
- Bump rand to 0.8 and quickcheck to 1. See [PR 2857].

View File

@ -3,7 +3,7 @@ name = "libp2p-request-response"
edition = "2021"
rust-version = "1.56.1"
description = "Generic Request/Response Protocols"
version = "0.22.1"
version = "0.23.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -15,8 +15,8 @@ async-trait = "0.1"
bytes = "1"
futures = "0.3.1"
instant = "0.1.11"
libp2p-core = { version = "0.37.0", path = "../../core" }
libp2p-swarm = { version = "0.40.0", path = "../../swarm" }
libp2p-core = { version = "0.38.0", path = "../../core" }
libp2p-swarm = { version = "0.41.0", path = "../../swarm" }
log = "0.4.11"
rand = "0.8"
smallvec = "1.6.1"

View File

@ -1,3 +1,7 @@
# 0.41.0 [unreleased]
- Update to `libp2p-core` `v0.38.0`.
# 0.40.0
- Bump rand to 0.8 and quickcheck to 1. See [PR 2857].

View File

@ -3,7 +3,7 @@ name = "libp2p-swarm"
edition = "2021"
rust-version = "1.56.1"
description = "The libp2p swarm"
version = "0.40.1"
version = "0.41.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -16,7 +16,7 @@ fnv = "1.0"
futures = "0.3.1"
futures-timer = "3.0.2"
instant = "0.1.11"
libp2p-core = { version = "0.37.0", path = "../core" }
libp2p-core = { version = "0.38.0", path = "../core" }
log = "0.4"
pin-project = "1.0.0"
rand = "0.8"

View File

@ -1,3 +1,7 @@
# 0.38.0 [unreleased]
- Update to `libp2p-core` `v0.38.0`.
# 0.37.0
- Update to `libp2p-core` `v0.37.0`.

View File

@ -3,7 +3,7 @@ name = "libp2p-deflate"
edition = "2021"
rust-version = "1.56.1"
description = "Deflate encryption protocol for libp2p"
version = "0.37.0"
version = "0.38.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"]
[dependencies]
futures = "0.3.1"
libp2p-core = { version = "0.37.0", path = "../../core" }
libp2p-core = { version = "0.38.0", path = "../../core" }
flate2 = "1.0"
[dev-dependencies]

View File

@ -1,3 +1,7 @@
# 0.38.0 [unreleased]
- Update to `libp2p-core` `v0.38.0`.
# 0.37.0
- Remove default features. If you previously depended on `async-std` you need to enable this explicitly now. See [PR 2918].

View File

@ -3,7 +3,7 @@ name = "libp2p-dns"
edition = "2021"
rust-version = "1.56.1"
description = "DNS transport implementation for libp2p"
version = "0.37.0"
version = "0.38.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -11,7 +11,7 @@ keywords = ["peer-to-peer", "libp2p", "networking"]
categories = ["network-programming", "asynchronous"]
[dependencies]
libp2p-core = { version = "0.37.0", path = "../../core" }
libp2p-core = { version = "0.38.0", path = "../../core" }
log = "0.4.1"
futures = "0.3.1"
async-std-resolver = { version = "0.22", optional = true }

View File

@ -1,3 +1,11 @@
# 0.41.0 [unreleased]
- Remove `prost::Error` from public API. See [PR 3058].
- Update to `libp2p-core` `v0.38.0`.
[PR 3058]: https://github.com/libp2p/rust-libp2p/pull/3058
# 0.40.0
- Update to `libp2p-core` `v0.37.0`.

View File

@ -3,7 +3,7 @@ name = "libp2p-noise"
edition = "2021"
rust-version = "1.56.1"
description = "Cryptographic handshake protocol using the noise framework."
version = "0.40.0"
version = "0.41.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -13,7 +13,7 @@ bytes = "1"
curve25519-dalek = "3.0.0"
futures = "0.3.1"
lazy_static = "1.2"
libp2p-core = { version = "0.37.0", path = "../../core" }
libp2p-core = { version = "0.38.0", path = "../../core" }
log = "0.4"
prost = "0.11"
rand = "0.8.3"

View File

@ -36,11 +36,26 @@ pub enum NoiseError {
/// upgrade failed.
AuthenticationFailed,
/// A handshake payload is invalid.
InvalidPayload(prost::DecodeError),
InvalidPayload(DecodeError),
/// A signature was required and could not be created.
SigningError(identity::error::SigningError),
}
#[derive(Debug)]
pub struct DecodeError(prost::DecodeError);
impl fmt::Display for DecodeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl Error for DecodeError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
self.0.source()
}
}
impl fmt::Display for NoiseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
@ -81,7 +96,7 @@ impl From<SnowError> for NoiseError {
impl From<prost::DecodeError> for NoiseError {
fn from(e: prost::DecodeError) -> Self {
NoiseError::InvalidPayload(e)
NoiseError::InvalidPayload(DecodeError(e))
}
}

View File

@ -1,3 +1,11 @@
# 0.38.0 [unreleased]
- Add more specific error reporting and remove `prost::Error` from public API. See [PR 3058].
- Update to `libp2p-core` `v0.38.0`.
[PR 3058]: https://github.com/libp2p/rust-libp2p/pull/3058
# 0.37.0
- Update to `libp2p-core` `v0.37.0`.

View File

@ -3,7 +3,7 @@ name = "libp2p-plaintext"
edition = "2021"
rust-version = "1.56.1"
description = "Plaintext encryption dummy protocol for libp2p"
version = "0.37.0"
version = "0.38.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -11,10 +11,10 @@ keywords = ["peer-to-peer", "libp2p", "networking"]
categories = ["network-programming", "asynchronous"]
[dependencies]
asynchronous-codec = "0.6"
bytes = "1"
futures = "0.3.1"
asynchronous-codec = "0.6"
libp2p-core = { version = "0.37.0", path = "../../core" }
libp2p-core = { version = "0.38.0", path = "../../core" }
log = "0.4.8"
prost = "0.11"
unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] }

View File

@ -28,17 +28,40 @@ pub enum PlainTextError {
IoError(IoError),
/// Failed to parse the handshake protobuf message.
InvalidPayload(Option<prost::DecodeError>),
InvalidPayload(DecodeError),
/// Failed to parse public key from bytes in protobuf message.
InvalidPublicKey(libp2p_core::identity::error::DecodingError),
/// Failed to parse the [`PeerId`](libp2p_core::PeerId) from bytes in the protobuf message.
InvalidPeerId(libp2p_core::multihash::Error),
/// The peer id of the exchange isn't consistent with the remote public key.
InvalidPeerId,
PeerIdMismatch,
}
#[derive(Debug)]
pub struct DecodeError(prost::DecodeError);
impl fmt::Display for DecodeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl error::Error for DecodeError {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
self.0.source()
}
}
impl error::Error for PlainTextError {
fn cause(&self) -> Option<&dyn error::Error> {
match *self {
PlainTextError::IoError(ref err) => Some(err),
PlainTextError::InvalidPayload(Some(ref err)) => Some(err),
PlainTextError::InvalidPayload(ref err) => Some(err),
PlainTextError::InvalidPublicKey(ref err) => Some(err),
PlainTextError::InvalidPeerId(ref err) => Some(err),
_ => None,
}
}
@ -48,13 +71,12 @@ impl fmt::Display for PlainTextError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match self {
PlainTextError::IoError(e) => write!(f, "I/O error: {}", e),
PlainTextError::InvalidPayload(protobuf_error) => match protobuf_error {
Some(e) => write!(f, "Protobuf error: {}", e),
None => f.write_str("Failed to parse one of the handshake protobuf messages"),
},
PlainTextError::InvalidPeerId => f.write_str(
PlainTextError::InvalidPayload(_) => f.write_str("Failed to decode protobuf"),
PlainTextError::PeerIdMismatch => f.write_str(
"The peer id of the exchange isn't consistent with the remote public key",
),
PlainTextError::InvalidPublicKey(_) => f.write_str("Failed to decode public key"),
PlainTextError::InvalidPeerId(_) => f.write_str("Failed to decode PeerId"),
}
}
}
@ -67,6 +89,18 @@ impl From<IoError> for PlainTextError {
impl From<prost::DecodeError> for PlainTextError {
fn from(err: prost::DecodeError) -> PlainTextError {
PlainTextError::InvalidPayload(Some(err))
PlainTextError::InvalidPayload(DecodeError(err))
}
}
impl From<libp2p_core::identity::error::DecodingError> for PlainTextError {
fn from(err: libp2p_core::identity::error::DecodingError) -> PlainTextError {
PlainTextError::InvalidPublicKey(err)
}
}
impl From<libp2p_core::multihash::Error> for PlainTextError {
fn from(err: libp2p_core::multihash::Error) -> PlainTextError {
PlainTextError::InvalidPeerId(err)
}
}

View File

@ -73,34 +73,14 @@ impl HandshakeContext<Local> {
self,
exchange_bytes: BytesMut,
) -> Result<HandshakeContext<Remote>, PlainTextError> {
let prop = match Exchange::decode(exchange_bytes) {
Ok(prop) => prop,
Err(e) => {
debug!("failed to parse remote's exchange protobuf message");
return Err(PlainTextError::InvalidPayload(Some(e)));
}
};
let prop = Exchange::decode(exchange_bytes)?;
let pb_pubkey = prop.pubkey.unwrap_or_default();
let public_key = match PublicKey::from_protobuf_encoding(pb_pubkey.as_slice()) {
Ok(p) => p,
Err(_) => {
debug!("failed to parse remote's exchange's pubkey protobuf");
return Err(PlainTextError::InvalidPayload(None));
}
};
let peer_id = match PeerId::from_bytes(&prop.id.unwrap_or_default()) {
Ok(p) => p,
Err(_) => {
debug!("failed to parse remote's exchange's id protobuf");
return Err(PlainTextError::InvalidPayload(None));
}
};
let public_key = PublicKey::from_protobuf_encoding(&prop.pubkey.unwrap_or_default())?;
let peer_id = PeerId::from_bytes(&prop.id.unwrap_or_default())?;
// Check the validity of the remote's `Exchange`.
if peer_id != public_key.to_peer_id() {
debug!("the remote's `PeerId` isn't consistent with the remote's public key");
return Err(PlainTextError::InvalidPeerId);
return Err(PlainTextError::PeerIdMismatch);
}
Ok(HandshakeContext {

View File

@ -4,6 +4,8 @@
- Remove `TcpListenStream` and `TcpListenerEvent` from public API. See [PR 2961].
- Update to `libp2p-core` `v0.38.0`.
[PR 2961]: https://github.com/libp2p/rust-libp2p/pull/2961
# 0.37.0

View File

@ -16,7 +16,7 @@ futures = "0.3.8"
futures-timer = "3.0"
if-watch = "2.0.0"
libc = "0.2.80"
libp2p-core = { version = "0.37.0", path = "../../core" }
libp2p-core = { version = "0.38.0", path = "../../core" }
log = "0.4.11"
socket2 = { version = "0.4.0", features = ["all"] }
tokio-crate = { package = "tokio", version = "1.19.0", default-features = false, features = ["net"], optional = true }

View File

@ -8,7 +8,7 @@ exclude = ["src/test_assets"]
[dependencies]
futures = { version = "0.3.24", default-features = false }
futures-rustls = "0.22.2"
libp2p-core = { version = "0.37.0", path = "../../core" }
libp2p-core = { version = "0.38.0", path = "../../core" }
rcgen = "0.9.2"
ring = "0.16.20"
thiserror = "1.0.36"

View File

@ -1,3 +1,5 @@
# 0.37.0 [unreleased]
# 0.36.0
- Remove default features. If you previously depended on `async-std` you need to enable this explicitly now. See [PR 2918].

View File

@ -3,7 +3,7 @@ name = "libp2p-uds"
edition = "2021"
rust-version = "1.56.1"
description = "Unix domain sockets transport for libp2p"
version = "0.36.0"
version = "0.37.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"]
[target.'cfg(all(unix, not(target_os = "emscripten")))'.dependencies]
async-std = { version = "1.6.2", optional = true }
libp2p-core = { version = "0.37.0", path = "../../core" }
libp2p-core = { version = "0.38.0", path = "../../core" }
log = "0.4.1"
futures = "0.3.1"
tokio = { version = "1.15", default-features = false, features = ["net"], optional = true }

View File

@ -1,3 +1,7 @@
# 0.38.0 [unreleased]
- Update to `libp2p-core` `v0.38.0`.
# 0.37.0
- Update to `libp2p-core` `v0.37.0`.

View File

@ -3,7 +3,7 @@ name = "libp2p-wasm-ext"
edition = "2021"
rust-version = "1.56.1"
description = "Allows passing in an external transport in a WASM environment"
version = "0.37.0"
version = "0.38.0"
authors = ["Pierre Krieger <pierre.krieger1708@gmail.com>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -13,7 +13,7 @@ categories = ["network-programming", "asynchronous"]
[dependencies]
futures = "0.3.1"
js-sys = "0.3.50"
libp2p-core = { version = "0.37.0", path = "../../core" }
libp2p-core = { version = "0.38.0", path = "../../core" }
parity-send-wrapper = "0.1.0"
wasm-bindgen = "0.2.42"
wasm-bindgen-futures = "0.4.4"

View File

@ -1,3 +1,7 @@
# 0.40.0 [unreleased]
- Update to `libp2p-core` `v0.38.0`.
# 0.39.0
- Update to `libp2p-core` `v0.37.0`.

View File

@ -3,7 +3,7 @@ name = "libp2p-websocket"
edition = "2021"
rust-version = "1.56.1"
description = "WebSocket transport for libp2p"
version = "0.39.0"
version = "0.40.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -14,7 +14,7 @@ categories = ["network-programming", "asynchronous"]
futures-rustls = "0.22"
either = "1.5.3"
futures = "0.3.1"
libp2p-core = { version = "0.37.0", path = "../../core" }
libp2p-core = { version = "0.38.0", path = "../../core" }
log = "0.4.8"
parking_lot = "0.12.0"
quicksink = "0.1"