Skip to content

Commit

Permalink
Merge pull request #40 from mxinden/parity-multiaddr
Browse files Browse the repository at this point in the history
*: Upstream parity-multiaddr changes
  • Loading branch information
mxinden authored May 26, 2021
2 parents 9682623 + 11d6fcf commit 0548298
Show file tree
Hide file tree
Showing 8 changed files with 1,617 additions and 914 deletions.
63 changes: 63 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# 0.12.0 [unreleased]

- Merge [multiaddr] and [parity-multiaddr] (see [PR 40]).

- Functionality to go from a `u64` to a `multiadddr::Protocol` and back is
removed. Please open an issue on [multiaddr] in case this is still needed.

- Given that `multiaddr::Protocol` now represents both the protocol
identifier as well as the protocol data (e.g. protocol identifier `55`
(`dns6`) and protocol data `some-domain.example`) `multiaddr::Protocol` is
no longer `Copy`.

[multiaddr]: https://github.com/multiformats/rust-multiaddr
[parity-multiaddr]: https://github.com/libp2p/rust-libp2p/blob/master/misc/multiaddr/
[PR 40]: https://github.com/multiformats/rust-multiaddr/pull/40

# 0.11.2 [2021-03-17]

- Add `Multiaddr::ends_with()`.

# 0.11.1 [2021-02-15]

- Update dependencies

# 0.11.0 [2021-01-12]

- Update dependencies

# 0.10.1 [2021-01-12]

- Fix compilation with serde-1.0.119.
[PR 1912](https://github.com/libp2p/rust-libp2p/pull/1912)

# 0.10.0 [2020-11-25]

- Upgrade multihash to `0.13`.

# 0.9.6 [2020-11-17]

- Move the `from_url` module and functionality behind the `url` feature,
enabled by default.
[PR 1843](https://github.com/libp2p/rust-libp2p/pull/1843).

# 0.9.5 [2020-11-14]

- Limit initial memory allocation in `visit_seq`.
[PR 1833](https://github.com/libp2p/rust-libp2p/pull/1833).

# 0.9.4 [2020-11-09]

- Update dependencies.

# 0.9.3 [2020-10-16]

- Update dependencies.

# 0.9.2 [2020-08-31]

- Add `Ord` instance for `Multiaddr`.

# 0.9.1 [2020-06-22]

- Updated dependencies.
26 changes: 20 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
[package]
authors = ["dignifiedquire <dignifiedquire@gmail.com>"]
authors = ["dignifiedquire <dignifiedquire@gmail.com>", "Parity Technologies <admin@parity.io>"]
description = "Implementation of the multiaddr format"
edition = "2018"
homepage = "https://github.com/multiformats/rust-multiaddr"
keywords = ["multiaddr", "ipfs"]
license = "MIT"
name = "multiaddr"
readme = "README.md"
version = "0.3.1"
version = "0.12.0"

[features]
default = ["url"]

[dependencies]
byteorder = "1.0"
cid = "~0.3"
integer-encoding = "1.0.3"
arrayref = "0.3"
bs58 = "0.4.0"
byteorder = "1.3.1"
data-encoding = "2.1"
multihash = { version = "0.13", default-features = false, features = ["std", "multihash-impl", "identity"] }
percent-encoding = "2.1.0"
serde = "1.0.70"
static_assertions = "1.1"
unsigned-varint = "0.7"
url = { version = "2.1.0", optional = true, default-features = false }

[dev-dependencies]
data-encoding = "2.0.0"
bincode = "1"
quickcheck = "0.9.0"
rand = "0.7.2"
serde_json = "1.0"
68 changes: 44 additions & 24 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
use cid;
use std::{error, fmt, io, net, num, string};
use std::{net, fmt, error, io, num, str, string};
use unsigned_varint::decode;

pub type Result<T> = ::std::result::Result<T, Error>;

/// Error types
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
UnknownProtocol,
UnknownProtocolString,
DataLessThanLen,
InvalidMultiaddr,
MissingAddress,
ParsingError(Box<error::Error + Send + Sync>),
InvalidProtocolString,
InvalidUvar(decode::Error),
ParsingError(Box<dyn error::Error + Send + Sync>),
UnknownProtocolId(u32),
UnknownProtocolString(String),
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(error::Error::description(self))
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::DataLessThanLen => f.write_str("we have less data than indicated by length"),
Error::InvalidMultiaddr => f.write_str("invalid multiaddr"),
Error::InvalidProtocolString => f.write_str("invalid protocol string"),
Error::InvalidUvar(e) => write!(f, "failed to decode unsigned varint: {}", e),
Error::ParsingError(e) => write!(f, "failed to parse: {}", e),
Error::UnknownProtocolId(id) => write!(f, "unknown protocol id: {}", id),
Error::UnknownProtocolString(string) => write!(f, "unknown protocol string: {}", string),
}
}
}

impl error::Error for Error {
fn description(&self) -> &str {
match *self {
Error::UnknownProtocol => "unknown protocol",
Error::UnknownProtocolString => "unknown protocol string",
Error::InvalidMultiaddr => "invalid multiaddr",
Error::MissingAddress => "protocol requires address, none given",
Error::ParsingError(_) => "failed to parse",
}
}

#[inline]
fn cause(&self) -> Option<&error::Error> {
match *self {
Error::ParsingError(ref err) => Some(&**err),
_ => None,
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
if let Error::ParsingError(e) = self {
Some(&**e)
} else {
None
}
}
}
Expand All @@ -45,8 +47,14 @@ impl From<io::Error> for Error {
}
}

impl From<cid::Error> for Error {
fn from(err: cid::Error) -> Error {
impl From<multihash::Error> for Error {
fn from(err: multihash::Error) -> Error {
Error::ParsingError(err.into())
}
}

impl From<bs58::decode::Error> for Error {
fn from(err: bs58::decode::Error) -> Error {
Error::ParsingError(err.into())
}
}
Expand All @@ -68,3 +76,15 @@ impl From<string::FromUtf8Error> for Error {
Error::ParsingError(err.into())
}
}

impl From<str::Utf8Error> for Error {
fn from(err: str::Utf8Error) -> Error {
Error::ParsingError(err.into())
}
}

impl From<decode::Error> for Error {
fn from(e: decode::Error) -> Error {
Error::InvalidUvar(e)
}
}
Loading

0 comments on commit 0548298

Please sign in to comment.