diff --git a/CHANGELOG.md b/CHANGELOG.md index 65d2620d62b..a70dd5bc145 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,11 +36,34 @@ ## Utilities -- [`parity-multiaddr` CHANGELOG](misc/multiaddr/CHANGELOG.md) - [`multistream-select` CHANGELOG](misc/multistream-select/CHANGELOG.md) # `libp2p` facade crate +## Version 0.39.0 [unreleased] + +- Update individual crates. + - `libp2p-core` + - `libp2p-deflate` + - `libp2p-dns` + - `libp2p-floodsub` + - `libp2p-gossipsub` + - `libp2p-identify` + - `libp2p-kad` + - `libp2p-mdns` + - `libp2p-mplex` + - `libp2p-noise` + - `libp2p-ping` + - `libp2p-plaintext` + - `libp2p-relay` + - `libp2p-request-response` + - `libp2p-swarm` + - `libp2p-tcp` + - `libp2p-uds` + - `libp2p-wasm-ext` + - `libp2p-websocket` + - `libp2p-yamux` + ## Version 0.38.0 [2021-05-17] - Update individual crates. diff --git a/Cargo.toml b/Cargo.toml index 487249ff400..32380b103fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p" edition = "2018" description = "Peer-to-peer networking library" -version = "0.38.0" +version = "0.39.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -64,35 +64,35 @@ atomic = "0.5.0" bytes = "1" futures = "0.3.1" lazy_static = "1.2" -libp2p-core = { version = "0.28.3", path = "core", default-features = false } -libp2p-floodsub = { version = "0.29.0", path = "protocols/floodsub", optional = true } -libp2p-gossipsub = { version = "0.31.0", path = "./protocols/gossipsub", optional = true } -libp2p-identify = { version = "0.29.0", path = "protocols/identify", optional = true } -libp2p-kad = { version = "0.30.0", path = "protocols/kad", optional = true } -libp2p-mplex = { version = "0.28.0", path = "muxers/mplex", optional = true } -libp2p-noise = { version = "0.31.0", path = "transports/noise", optional = true } -libp2p-ping = { version = "0.29.0", path = "protocols/ping", optional = true } -libp2p-plaintext = { version = "0.28.0", path = "transports/plaintext", optional = true } +libp2p-core = { version = "0.29.0", path = "core", default-features = false } +libp2p-floodsub = { version = "0.30.0", path = "protocols/floodsub", optional = true } +libp2p-gossipsub = { version = "0.32.0", path = "./protocols/gossipsub", optional = true } +libp2p-identify = { version = "0.30.0", path = "protocols/identify", optional = true } +libp2p-kad = { version = "0.31.0", path = "protocols/kad", optional = true } +libp2p-mplex = { version = "0.29.0", path = "muxers/mplex", optional = true } +libp2p-noise = { version = "0.32.0", path = "transports/noise", optional = true } +libp2p-ping = { version = "0.30.0", path = "protocols/ping", optional = true } +libp2p-plaintext = { version = "0.29.0", path = "transports/plaintext", optional = true } libp2p-pnet = { version = "0.21.0", path = "transports/pnet", optional = true } -libp2p-relay = { version = "0.2.0", path = "protocols/relay", optional = true } -libp2p-request-response = { version = "0.11.0", path = "protocols/request-response", optional = true } -libp2p-swarm = { version = "0.29.0", path = "swarm" } +libp2p-relay = { version = "0.3.0", path = "protocols/relay", optional = true } +libp2p-request-response = { version = "0.12.0", path = "protocols/request-response", optional = true } +libp2p-swarm = { version = "0.30.0", path = "swarm" } libp2p-swarm-derive = { version = "0.23.0", path = "swarm-derive" } -libp2p-uds = { version = "0.28.0", path = "transports/uds", optional = true } -libp2p-wasm-ext = { version = "0.28.2", path = "transports/wasm-ext", default-features = false, optional = true } -libp2p-yamux = { version = "0.32.0", path = "muxers/yamux", optional = true } -multiaddr = { package = "parity-multiaddr", version = "0.11.2", path = "misc/multiaddr" } +libp2p-uds = { version = "0.29.0", path = "transports/uds", optional = true } +libp2p-wasm-ext = { version = "0.29.0", path = "transports/wasm-ext", default-features = false, optional = true } +libp2p-yamux = { version = "0.33.0", path = "muxers/yamux", optional = true } +multiaddr = { version = "0.12.0" } parking_lot = "0.11.0" pin-project = "1.0.0" smallvec = "1.6.1" wasm-timer = "0.2.4" [target.'cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))'.dependencies] -libp2p-deflate = { version = "0.28.0", path = "transports/deflate", optional = true } -libp2p-dns = { version = "0.28.1", path = "transports/dns", optional = true, default-features = false } -libp2p-mdns = { version = "0.30.0", path = "protocols/mdns", optional = true } -libp2p-tcp = { version = "0.28.0", path = "transports/tcp", default-features = false, optional = true } -libp2p-websocket = { version = "0.29.0", path = "transports/websocket", optional = true } +libp2p-deflate = { version = "0.29.0", path = "transports/deflate", optional = true } +libp2p-dns = { version = "0.29.0", path = "transports/dns", optional = true, default-features = false } +libp2p-mdns = { version = "0.31.0", path = "protocols/mdns", optional = true } +libp2p-tcp = { version = "0.29.0", path = "transports/tcp", default-features = false, optional = true } +libp2p-websocket = { version = "0.30.0", path = "transports/websocket", optional = true } [dev-dependencies] async-std = { version = "1.6.2", features = ["attributes"] } @@ -103,7 +103,6 @@ tokio = { version = "1.0.1", features = ["io-util", "io-std", "macros", "rt", "r resolver = "2" members = [ "core", - "misc/multiaddr", "misc/multistream-select", "misc/peer-id-generator", "muxers/mplex", diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index dcdbee6b631..57dbe841396 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -1,4 +1,6 @@ -# 0.28.4 [unreleased] +# 0.29.0 [unreleased] + +- Switch from `parity-multiaddr` to upstream `multiaddr`. - Update dependencies. diff --git a/core/Cargo.toml b/core/Cargo.toml index 7500afdca2c..e4c0a3fdc32 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-core" edition = "2018" description = "Core traits and structs of libp2p" -version = "0.28.4" +version = "0.29.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -20,7 +20,7 @@ futures-timer = "3" lazy_static = "1.2" libsecp256k1 = { version = "0.5.0", optional = true } log = "0.4" -multiaddr = { package = "parity-multiaddr", version = "0.11.2", path = "../misc/multiaddr" } +multiaddr = { version = "0.12.0" } multihash = { version = "0.13", default-features = false, features = ["std", "multihash-impl", "identity", "sha2"] } multistream-select = { version = "0.10", path = "../misc/multistream-select" } parking_lot = "0.11.0" diff --git a/misc/multiaddr/.gitignore b/misc/multiaddr/.gitignore deleted file mode 100644 index 5071d14c5a1..00000000000 --- a/misc/multiaddr/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -target -Cargo.lock -*.rs.bk \ No newline at end of file diff --git a/misc/multiaddr/.travis.yml b/misc/multiaddr/.travis.yml deleted file mode 100644 index a40d6ee8a0c..00000000000 --- a/misc/multiaddr/.travis.yml +++ /dev/null @@ -1,31 +0,0 @@ -sudo: false -language: rust -addons: - apt: - packages: - - libcurl4-openssl-dev - - libelf-dev - - libdw-dev - - binutils-dev -rust: -# - nightly # enable when passing -- beta -- stable - -before_script: -- | - pip install 'travis-cargo<0.2' --user && - export PATH=$HOME/.local/bin:$PATH -script: -- | - travis-cargo build && - travis-cargo test && - travis-cargo bench && - travis-cargo --only stable doc -after_success: -- travis-cargo --only stable doc-upload -- travis-cargo coveralls --no-sudo --verify -env: - global: - - TRAVIS_CARGO_NIGHTLY_FEATURE=nightly - - secure: f/VDWCDpQazAB1TX4QlwGDumT7ft4uip5isALquR3TUT/WyKScnXe9JCAMp5/kJaVzSUeQgbqbBXsNmkzMpqBGj5Cu8GqUDIPf2TbqfFJ/wNzzQXrvwB2n3fA5affbSLBvLBw1R9Jonv14tPduYgnfkGDi89UbxMhXDRhpmwrFlKxHLcbz36+pYG5Qg3ftAGDrNDWprh5W0J1RgwyXGj56fUKLcHDzZoyvNEEzkSM3WV4OdWixCDESrS3SZLaYCjLNHLbCsbaa6AWUlGZMJXj5mrNDDxeCFU6Z9euUWG9ypJkiRA6eMo1zqXZrHYvPJM2ivqWqEYUXtKGHpugH2Sa34C/PvXOiuYkC2yXLO6TmSaAYWo5x6z1I2WrgMKSbhpqsrV0ZRKywCBuMooyQw85tQJRFPqSxbaJYPjsVhZ4yZEDnbsCvr8puhKtWAYOhz/0d15Pyom+yJ3roT4eSt4VyPVifEFAKC4/tLxbXkzB44PvOg0Ur+HxUUoAxi0dgrb1MTOwgkDxUl3iIdQtn6bAjM2D84ciCtYvlcTQAp7Rohgoda3FU99Hoxujj7YJ3eRLfBpLOclXTqUFBU0JFRDlec1xcD4MnwsLz9oWdw/hIhyh4PGfm6wuvfBKkJdQ4JhzIS7UcDCUdrsTx7LqMtA5M1CkN53mw+HNXfUncOOyLw= diff --git a/misc/multiaddr/CHANGELOG.md b/misc/multiaddr/CHANGELOG.md deleted file mode 100644 index f0f9b3ef309..00000000000 --- a/misc/multiaddr/CHANGELOG.md +++ /dev/null @@ -1,47 +0,0 @@ -# 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. diff --git a/misc/multiaddr/Cargo.toml b/misc/multiaddr/Cargo.toml deleted file mode 100644 index 12b7a75a135..00000000000 --- a/misc/multiaddr/Cargo.toml +++ /dev/null @@ -1,30 +0,0 @@ -[package] -name = "parity-multiaddr" -edition = "2018" -authors = ["dignifiedquire ", "Parity Technologies "] -description = "Implementation of the multiaddr format" -homepage = "https://github.com/libp2p/rust-libp2p" -keywords = ["multiaddr", "ipfs"] -license = "MIT" -version = "0.11.2" - -[features] -default = ["url"] - -[dependencies] -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] -bincode = "1" -quickcheck = "0.9.0" -rand = "0.7.2" -serde_json = "1.0" diff --git a/misc/multiaddr/LICENSE b/misc/multiaddr/LICENSE deleted file mode 100644 index 233fd7bd7d5..00000000000 --- a/misc/multiaddr/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License - -Copyright (C) 2015-2016 Friedel Ziegelmayer - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -Status API Training Shop Blog About Pricing diff --git a/misc/multiaddr/README.md b/misc/multiaddr/README.md new file mode 100644 index 00000000000..e745a6f601b --- /dev/null +++ b/misc/multiaddr/README.md @@ -0,0 +1 @@ +Moved to https://github.com/multiformats/rust-multiaddr. \ No newline at end of file diff --git a/misc/multiaddr/src/errors.rs b/misc/multiaddr/src/errors.rs deleted file mode 100644 index cb27e3d6acc..00000000000 --- a/misc/multiaddr/src/errors.rs +++ /dev/null @@ -1,90 +0,0 @@ -use std::{net, fmt, error, io, num, str, string}; -use unsigned_varint::decode; - -pub type Result = ::std::result::Result; - -/// Error types -#[derive(Debug)] -#[non_exhaustive] -pub enum Error { - DataLessThanLen, - InvalidMultiaddr, - InvalidProtocolString, - InvalidUvar(decode::Error), - ParsingError(Box), - UnknownProtocolId(u32), - UnknownProtocolString(String), -} - -impl fmt::Display for Error { - 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 { - #[inline] - fn cause(&self) -> Option<&dyn error::Error> { - if let Error::ParsingError(e) = self { - Some(&**e) - } else { - None - } - } -} - -impl From for Error { - fn from(err: io::Error) -> Error { - Error::ParsingError(err.into()) - } -} - -impl From for Error { - fn from(err: multihash::Error) -> Error { - Error::ParsingError(err.into()) - } -} - -impl From for Error { - fn from(err: bs58::decode::Error) -> Error { - Error::ParsingError(err.into()) - } -} - -impl From for Error { - fn from(err: net::AddrParseError) -> Error { - Error::ParsingError(err.into()) - } -} - -impl From for Error { - fn from(err: num::ParseIntError) -> Error { - Error::ParsingError(err.into()) - } -} - -impl From for Error { - fn from(err: string::FromUtf8Error) -> Error { - Error::ParsingError(err.into()) - } -} - -impl From for Error { - fn from(err: str::Utf8Error) -> Error { - Error::ParsingError(err.into()) - } -} - -impl From for Error { - fn from(e: decode::Error) -> Error { - Error::InvalidUvar(e) - } -} diff --git a/misc/multiaddr/src/from_url.rs b/misc/multiaddr/src/from_url.rs deleted file mode 100644 index fa5acfacc01..00000000000 --- a/misc/multiaddr/src/from_url.rs +++ /dev/null @@ -1,285 +0,0 @@ -use crate::{Multiaddr, Protocol}; -use std::{error, fmt, iter, net::IpAddr}; - -/// Attempts to parse an URL into a multiaddress. -/// -/// This function will return an error if some information in the URL cannot be retained in the -/// generated multiaddress. This includes a username, password, path (if not supported by the -/// multiaddr), and query string. -/// -/// This function is only present if the `url` feature is enabled, and it is -/// enabled by default. -/// -/// The supported URL schemes are: -/// -/// - `ws://example.com/` -/// - `wss://example.com/` -/// - `http://example.com/` -/// - `https://example.com/` -/// - `unix:/foo/bar` -/// -/// # Example -/// -/// ``` -/// let addr = parity_multiaddr::from_url("ws://127.0.0.1:8080/").unwrap(); -/// assert_eq!(addr, "/ip4/127.0.0.1/tcp/8080/ws".parse().unwrap()); -/// ``` -/// -pub fn from_url(url: &str) -> std::result::Result { - from_url_inner(url, false) -} - -/// Attempts to parse an URL into a multiaddress. Ignores possible loss of information. -/// -/// This function is similar to [`from_url`], except that we don't return an error if some -/// information in the URL cannot be retain in the generated multiaddres. -/// -/// This function is only present if the `url` feature is enabled, and it is -/// enabled by default. -/// -/// # Example -/// -/// ``` -/// let addr = "ws://user:pass@127.0.0.1:8080/"; -/// assert!(parity_multiaddr::from_url(addr).is_err()); -/// assert!(parity_multiaddr::from_url_lossy(addr).is_ok()); -/// ``` -/// -pub fn from_url_lossy(url: &str) -> std::result::Result { - from_url_inner(url, true) -} - -/// Underlying implementation of `from_url` and `from_url_lossy`. -fn from_url_inner(url: &str, lossy: bool) -> std::result::Result { - let url = url::Url::parse(url).map_err(|_| FromUrlErr::BadUrl)?; - - match url.scheme() { - // Note: if you add support for a new scheme, please update the documentation as well. - "ws" | "wss" | "http" | "https" => from_url_inner_http_ws(url, lossy), - "unix" => from_url_inner_path(url, lossy), - _ => Err(FromUrlErr::UnsupportedScheme) - } -} - -/// Called when `url.scheme()` is an Internet-like URL. -fn from_url_inner_http_ws(url: url::Url, lossy: bool) -> std::result::Result { - let (protocol, lost_path, default_port) = match url.scheme() { - "ws" => (Protocol::Ws(url.path().to_owned().into()), false, 80), - "wss" => (Protocol::Wss(url.path().to_owned().into()), false, 443), - "http" => (Protocol::Http, true, 80), - "https" => (Protocol::Https, true, 443), - _ => unreachable!("We only call this function for one of the given schemes; qed") - }; - - let port = Protocol::Tcp(url.port().unwrap_or(default_port)); - let ip = if let Some(hostname) = url.host_str() { - if let Ok(ip) = hostname.parse::() { - Protocol::from(ip) - } else { - Protocol::Dns(hostname.into()) - } - } else { - return Err(FromUrlErr::BadUrl); - }; - - if !lossy && ( - !url.username().is_empty() || - url.password().is_some() || - (lost_path && url.path() != "/" && !url.path().is_empty()) || - url.query().is_some() || url.fragment().is_some() - ) { - return Err(FromUrlErr::InformationLoss); - } - - Ok(iter::once(ip) - .chain(iter::once(port)) - .chain(iter::once(protocol)) - .collect()) -} - -/// Called when `url.scheme()` is a path-like URL. -fn from_url_inner_path(url: url::Url, lossy: bool) -> std::result::Result { - let protocol = match url.scheme() { - "unix" => Protocol::Unix(url.path().to_owned().into()), - _ => unreachable!("We only call this function for one of the given schemes; qed") - }; - - if !lossy && ( - !url.username().is_empty() || - url.password().is_some() || - url.query().is_some() || - url.fragment().is_some() - ) { - return Err(FromUrlErr::InformationLoss); - } - - Ok(Multiaddr::from(protocol)) -} - -/// Error while parsing an URL. -#[derive(Debug)] -pub enum FromUrlErr { - /// Failed to parse the URL. - BadUrl, - /// The URL scheme was not recognized. - UnsupportedScheme, - /// Some information in the URL would be lost. Never returned by `from_url_lossy`. - InformationLoss, -} - -impl fmt::Display for FromUrlErr { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - FromUrlErr::BadUrl => write!(f, "Bad URL"), - FromUrlErr::UnsupportedScheme => write!(f, "Unrecognized URL scheme"), - FromUrlErr::InformationLoss => write!(f, "Some information in the URL would be lost"), - } - } -} - -impl error::Error for FromUrlErr { -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn parse_garbage_doesnt_panic() { - for _ in 0 .. 50 { - let url = (0..16).map(|_| rand::random::()).collect::>(); - let url = String::from_utf8_lossy(&url); - assert!(from_url(&url).is_err()); - } - } - - #[test] - fn normal_usage_ws() { - let addr = from_url("ws://127.0.0.1:8000").unwrap(); - assert_eq!(addr, "/ip4/127.0.0.1/tcp/8000/ws".parse().unwrap()); - } - - #[test] - fn normal_usage_wss() { - let addr = from_url("wss://127.0.0.1:8000").unwrap(); - assert_eq!(addr, "/ip4/127.0.0.1/tcp/8000/wss".parse().unwrap()); - } - - #[test] - fn default_ws_port() { - let addr = from_url("ws://127.0.0.1").unwrap(); - assert_eq!(addr, "/ip4/127.0.0.1/tcp/80/ws".parse().unwrap()); - } - - #[test] - fn default_http_port() { - let addr = from_url("http://127.0.0.1").unwrap(); - assert_eq!(addr, "/ip4/127.0.0.1/tcp/80/http".parse().unwrap()); - } - - #[test] - fn default_wss_port() { - let addr = from_url("wss://127.0.0.1").unwrap(); - assert_eq!(addr, "/ip4/127.0.0.1/tcp/443/wss".parse().unwrap()); - } - - #[test] - fn default_https_port() { - let addr = from_url("https://127.0.0.1").unwrap(); - assert_eq!(addr, "/ip4/127.0.0.1/tcp/443/https".parse().unwrap()); - } - - #[test] - fn dns_addr_ws() { - let addr = from_url("ws://example.com").unwrap(); - assert_eq!(addr, "/dns/example.com/tcp/80/ws".parse().unwrap()); - } - - #[test] - fn dns_addr_http() { - let addr = from_url("http://example.com").unwrap(); - assert_eq!(addr, "/dns/example.com/tcp/80/http".parse().unwrap()); - } - - #[test] - fn dns_addr_wss() { - let addr = from_url("wss://example.com").unwrap(); - assert_eq!(addr, "/dns/example.com/tcp/443/wss".parse().unwrap()); - } - - #[test] - fn dns_addr_https() { - let addr = from_url("https://example.com").unwrap(); - assert_eq!(addr, "/dns/example.com/tcp/443/https".parse().unwrap()); - } - - #[test] - fn bad_hostname() { - let addr = from_url("wss://127.0.0.1x").unwrap(); - assert_eq!(addr, "/dns/127.0.0.1x/tcp/443/wss".parse().unwrap()); - } - - #[test] - fn wrong_scheme() { - match from_url("foo://127.0.0.1") { - Err(FromUrlErr::UnsupportedScheme) => {} - _ => panic!() - } - } - - #[test] - fn dns_and_port() { - let addr = from_url("http://example.com:1000").unwrap(); - assert_eq!(addr, "/dns/example.com/tcp/1000/http".parse().unwrap()); - } - - #[test] - fn username_lossy() { - let addr = "http://foo@example.com:1000/"; - assert!(from_url(addr).is_err()); - assert!(from_url_lossy(addr).is_ok()); - assert!(from_url("http://@example.com:1000/").is_ok()); - } - - #[test] - fn password_lossy() { - let addr = "http://:bar@example.com:1000/"; - assert!(from_url(addr).is_err()); - assert!(from_url_lossy(addr).is_ok()); - } - - #[test] - fn path_lossy() { - let addr = "http://example.com:1000/foo"; - assert!(from_url(addr).is_err()); - assert!(from_url_lossy(addr).is_ok()); - } - - #[test] - fn fragment_lossy() { - let addr = "http://example.com:1000/#foo"; - assert!(from_url(addr).is_err()); - assert!(from_url_lossy(addr).is_ok()); - } - - #[test] - fn unix() { - let addr = from_url("unix:/foo/bar").unwrap(); - assert_eq!(addr, Multiaddr::from(Protocol::Unix("/foo/bar".into()))); - } - - #[test] - fn ws_path() { - let addr = from_url("ws://1.2.3.4:1000/foo/bar").unwrap(); - assert_eq!(addr, "/ip4/1.2.3.4/tcp/1000/x-parity-ws/%2ffoo%2fbar".parse().unwrap()); - - let addr = from_url("ws://1.2.3.4:1000/").unwrap(); - assert_eq!(addr, "/ip4/1.2.3.4/tcp/1000/ws".parse().unwrap()); - - let addr = from_url("wss://1.2.3.4:1000/foo/bar").unwrap(); - assert_eq!(addr, "/ip4/1.2.3.4/tcp/1000/x-parity-wss/%2ffoo%2fbar".parse().unwrap()); - - let addr = from_url("wss://1.2.3.4:1000").unwrap(); - assert_eq!(addr, "/ip4/1.2.3.4/tcp/1000/wss".parse().unwrap()); - } -} diff --git a/misc/multiaddr/src/lib.rs b/misc/multiaddr/src/lib.rs deleted file mode 100644 index 6279a0f9236..00000000000 --- a/misc/multiaddr/src/lib.rs +++ /dev/null @@ -1,434 +0,0 @@ -///! Implementation of [multiaddr](https://github.com/jbenet/multiaddr) in Rust. - -pub use multihash; - -mod protocol; -mod onion_addr; -mod errors; - -#[cfg(feature = "url")] -mod from_url; - -use serde::{ - Deserialize, - Deserializer, - Serialize, - Serializer, - de::{self, Error as DeserializerError} -}; -use std::{ - convert::TryFrom, - fmt, - io, - iter::FromIterator, - net::{IpAddr, Ipv4Addr, Ipv6Addr}, - result::Result as StdResult, - str::FromStr, - sync::Arc -}; -pub use self::errors::{Result, Error}; -pub use self::protocol::Protocol; -pub use self::onion_addr::Onion3Addr; - -#[cfg(feature = "url")] -pub use self::from_url::{FromUrlErr, from_url, from_url_lossy}; - -static_assertions::const_assert! { - // This check is most certainly overkill right now, but done here - // anyway to ensure the `as u64` casts in this crate are safe. - std::mem::size_of::() <= std::mem::size_of::() -} - -/// Representation of a Multiaddr. -#[allow(clippy::rc_buffer)] -#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Hash)] -pub struct Multiaddr { bytes: Arc> } - -impl Multiaddr { - /// Create a new, empty multiaddress. - pub fn empty() -> Self { - Self { bytes: Arc::new(Vec::new()) } - } - - /// Create a new, empty multiaddress with the given capacity. - pub fn with_capacity(n: usize) -> Self { - Self { bytes: Arc::new(Vec::with_capacity(n)) } - } - - /// Return the length in bytes of this multiaddress. - pub fn len(&self) -> usize { - self.bytes.len() - } - - /// Returns true if the length of this multiaddress is 0. - pub fn is_empty(&self) -> bool { - self.bytes.len() == 0 - } - - /// Return a copy of this [`Multiaddr`]'s byte representation. - pub fn to_vec(&self) -> Vec { - Vec::from(&self.bytes[..]) - } - - /// Adds an already-parsed address component to the end of this multiaddr. - /// - /// # Examples - /// - /// ``` - /// use parity_multiaddr::{Multiaddr, Protocol}; - /// - /// let mut address: Multiaddr = "/ip4/127.0.0.1".parse().unwrap(); - /// address.push(Protocol::Tcp(10000)); - /// assert_eq!(address, "/ip4/127.0.0.1/tcp/10000".parse().unwrap()); - /// ``` - /// - pub fn push(&mut self, p: Protocol<'_>) { - let mut w = io::Cursor::<&mut Vec>::new(Arc::make_mut(&mut self.bytes)); - w.set_position(w.get_ref().len() as u64); - p.write_bytes(&mut w).expect("Writing to a `io::Cursor<&mut Vec>` never fails.") - } - - /// Pops the last `Protocol` of this multiaddr, or `None` if the multiaddr is empty. - /// ``` - /// use parity_multiaddr::{Multiaddr, Protocol}; - /// - /// let mut address: Multiaddr = "/ip4/127.0.0.1/udt/sctp/5678".parse().unwrap(); - /// - /// assert_eq!(address.pop().unwrap(), Protocol::Sctp(5678)); - /// assert_eq!(address.pop().unwrap(), Protocol::Udt); - /// ``` - /// - pub fn pop<'a>(&mut self) -> Option> { - let mut slice = &self.bytes[..]; // the remaining multiaddr slice - if slice.is_empty() { - return None - } - let protocol = loop { - let (p, s) = Protocol::from_bytes(slice).expect("`slice` is a valid `Protocol`."); - if s.is_empty() { - break p.acquire() - } - slice = s - }; - let remaining_len = self.bytes.len() - slice.len(); - Arc::make_mut(&mut self.bytes).truncate(remaining_len); - Some(protocol) - } - - /// Like [`Multiaddr::push`] but consumes `self`. - pub fn with(mut self, p: Protocol<'_>) -> Self { - let mut w = io::Cursor::<&mut Vec>::new(Arc::make_mut(&mut self.bytes)); - w.set_position(w.get_ref().len() as u64); - p.write_bytes(&mut w).expect("Writing to a `io::Cursor<&mut Vec>` never fails."); - self - } - - /// Returns the components of this multiaddress. - /// - /// # Example - /// - /// ```rust - /// use std::net::Ipv4Addr; - /// use parity_multiaddr::{Multiaddr, Protocol}; - /// - /// let address: Multiaddr = "/ip4/127.0.0.1/udt/sctp/5678".parse().unwrap(); - /// - /// let components = address.iter().collect::>(); - /// assert_eq!(components[0], Protocol::Ip4(Ipv4Addr::new(127, 0, 0, 1))); - /// assert_eq!(components[1], Protocol::Udt); - /// assert_eq!(components[2], Protocol::Sctp(5678)); - /// ``` - /// - pub fn iter(&self) -> Iter<'_> { - Iter(&self.bytes) - } - - /// Replace a [`Protocol`] at some position in this `Multiaddr`. - /// - /// The parameter `at` denotes the index of the protocol at which the function - /// `by` will be applied to the current protocol, returning an optional replacement. - /// - /// If `at` is out of bounds or `by` does not yield a replacement value, - /// `None` will be returned. Otherwise a copy of this `Multiaddr` with the - /// updated `Protocol` at position `at` will be returned. - pub fn replace<'a, F>(&self, at: usize, by: F) -> Option - where - F: FnOnce(&Protocol<'_>) -> Option> - { - let mut address = Multiaddr::with_capacity(self.len()); - let mut fun = Some(by); - let mut replaced = false; - - for (i, p) in self.iter().enumerate() { - if i == at { - let f = fun.take().expect("i == at only happens once"); - if let Some(q) = f(&p) { - address = address.with(q); - replaced = true; - continue - } - return None - } - address = address.with(p) - } - - if replaced { Some(address) } else { None } - } - - /// Checks whether the given `Multiaddr` is a suffix of this `Multiaddr`. - pub fn ends_with(&self, other: &Multiaddr) -> bool { - let n = self.bytes.len(); - let m = other.bytes.len(); - if n < m { - return false - } - self.bytes[(n - m) ..] == other.bytes[..] - } -} - -impl fmt::Debug for Multiaddr { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - self.to_string().fmt(f) - } -} - -impl fmt::Display for Multiaddr { - /// Convert a Multiaddr to a string - /// - /// # Example - /// - /// ``` - /// use parity_multiaddr::Multiaddr; - /// - /// let address: Multiaddr = "/ip4/127.0.0.1/udt".parse().unwrap(); - /// assert_eq!(address.to_string(), "/ip4/127.0.0.1/udt"); - /// ``` - /// - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - for s in self.iter() { - s.to_string().fmt(f)?; - } - Ok(()) - } -} - -impl AsRef<[u8]> for Multiaddr { - fn as_ref(&self) -> &[u8] { - self.bytes.as_ref() - } -} - -impl<'a> IntoIterator for &'a Multiaddr { - type Item = Protocol<'a>; - type IntoIter = Iter<'a>; - - fn into_iter(self) -> Iter<'a> { - Iter(&self.bytes) - } -} - -impl<'a> FromIterator> for Multiaddr { - fn from_iter(iter: T) -> Self - where - T: IntoIterator>, - { - let mut writer = Vec::new(); - for cmp in iter { - cmp.write_bytes(&mut writer).expect("Writing to a `Vec` never fails."); - } - Multiaddr { bytes: Arc::new(writer) } - } -} - -impl FromStr for Multiaddr { - type Err = Error; - - fn from_str(input: &str) -> Result { - let mut writer = Vec::new(); - let mut parts = input.split('/').peekable(); - - if Some("") != parts.next() { - // A multiaddr must start with `/` - return Err(Error::InvalidMultiaddr) - } - - while parts.peek().is_some() { - let p = Protocol::from_str_parts(&mut parts)?; - p.write_bytes(&mut writer).expect("Writing to a `Vec` never fails."); - } - - Ok(Multiaddr { bytes: Arc::new(writer) }) - } -} - -/// Iterator over `Multiaddr` [`Protocol`]s. -pub struct Iter<'a>(&'a [u8]); - -impl<'a> Iterator for Iter<'a> { - type Item = Protocol<'a>; - - fn next(&mut self) -> Option { - if self.0.is_empty() { - return None; - } - - let (p, next_data) = - Protocol::from_bytes(self.0).expect("`Multiaddr` is known to be valid."); - - self.0 = next_data; - Some(p) - } -} - -impl<'a> From> for Multiaddr { - fn from(p: Protocol<'a>) -> Multiaddr { - let mut w = Vec::new(); - p.write_bytes(&mut w).expect("Writing to a `Vec` never fails."); - Multiaddr { bytes: Arc::new(w) } - } -} - -impl From for Multiaddr { - fn from(v: IpAddr) -> Multiaddr { - match v { - IpAddr::V4(a) => a.into(), - IpAddr::V6(a) => a.into() - } - } -} - -impl From for Multiaddr { - fn from(v: Ipv4Addr) -> Multiaddr { - Protocol::Ip4(v).into() - } -} - -impl From for Multiaddr { - fn from(v: Ipv6Addr) -> Multiaddr { - Protocol::Ip6(v).into() - } -} - -impl TryFrom> for Multiaddr { - type Error = Error; - - fn try_from(v: Vec) -> Result { - // Check if the argument is a valid `Multiaddr` by reading its protocols. - let mut slice = &v[..]; - while !slice.is_empty() { - let (_, s) = Protocol::from_bytes(slice)?; - slice = s - } - Ok(Multiaddr { bytes: Arc::new(v) }) - } -} - -impl TryFrom for Multiaddr { - type Error = Error; - - fn try_from(s: String) -> Result { - s.parse() - } -} - -impl<'a> TryFrom<&'a str> for Multiaddr { - type Error = Error; - - fn try_from(s: &'a str) -> Result { - s.parse() - } -} - -impl Serialize for Multiaddr { - fn serialize(&self, serializer: S) -> StdResult - where - S: Serializer, - { - if serializer.is_human_readable() { - serializer.serialize_str(&self.to_string()) - } else { - serializer.serialize_bytes(self.as_ref()) - } - } -} - -impl<'de> Deserialize<'de> for Multiaddr { - fn deserialize(deserializer: D) -> StdResult - where - D: Deserializer<'de>, - { - struct Visitor { is_human_readable: bool } - - impl<'de> de::Visitor<'de> for Visitor { - type Value = Multiaddr; - - fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { - formatter.write_str("multiaddress") - } - fn visit_seq>(self, mut seq: A) -> StdResult { - let mut buf: Vec = Vec::with_capacity(std::cmp::min(seq.size_hint().unwrap_or(0), 4096)); - while let Some(e) = seq.next_element()? { buf.push(e); } - if self.is_human_readable { - let s = String::from_utf8(buf).map_err(DeserializerError::custom)?; - s.parse().map_err(DeserializerError::custom) - } else { - Multiaddr::try_from(buf).map_err(DeserializerError::custom) - } - } - fn visit_str(self, v: &str) -> StdResult { - v.parse().map_err(DeserializerError::custom) - } - fn visit_borrowed_str(self, v: &'de str) -> StdResult { - self.visit_str(v) - } - fn visit_string(self, v: String) -> StdResult { - self.visit_str(&v) - } - fn visit_bytes(self, v: &[u8]) -> StdResult { - self.visit_byte_buf(v.into()) - } - fn visit_borrowed_bytes(self, v: &'de [u8]) -> StdResult { - self.visit_byte_buf(v.into()) - } - fn visit_byte_buf(self, v: Vec) -> StdResult { - Multiaddr::try_from(v).map_err(DeserializerError::custom) - } - } - - if deserializer.is_human_readable() { - deserializer.deserialize_str(Visitor { is_human_readable: true }) - } else { - deserializer.deserialize_bytes(Visitor { is_human_readable: false }) - } - } -} - -/// Easy way for a user to create a `Multiaddr`. -/// -/// Example: -/// -/// ```rust -/// # use parity_multiaddr::multiaddr; -/// let addr = multiaddr!(Ip4([127, 0, 0, 1]), Tcp(10500u16)); -/// ``` -/// -/// Each element passed to `multiaddr!` should be a variant of the `Protocol` enum. The -/// optional parameter is turned into the proper type with the `Into` trait. -/// -/// For example, `Ip4([127, 0, 0, 1])` works because `Ipv4Addr` implements `From<[u8; 4]>`. -#[macro_export] -macro_rules! multiaddr { - ($($comp:ident $(($param:expr))*),+) => { - { - use std::iter; - let elem = iter::empty::<$crate::Protocol>(); - $( - let elem = { - let cmp = $crate::Protocol::$comp $(( $param.into() ))*; - elem.chain(iter::once(cmp)) - }; - )+ - elem.collect::<$crate::Multiaddr>() - } - } -} diff --git a/misc/multiaddr/src/onion_addr.rs b/misc/multiaddr/src/onion_addr.rs deleted file mode 100644 index 29261287749..00000000000 --- a/misc/multiaddr/src/onion_addr.rs +++ /dev/null @@ -1,51 +0,0 @@ -use std::{borrow::Cow, fmt}; - -/// Represents an Onion v3 address -#[derive(Clone)] -pub struct Onion3Addr<'a>(Cow<'a, [u8; 35]>, u16); - -impl<'a> Onion3Addr<'a> { - /// Return the hash of the public key as bytes - pub fn hash(&self) -> &[u8; 35] { - self.0.as_ref() - } - - /// Return the port - pub fn port(&self) -> u16 { - self.1 - } - - /// Consume this instance and create an owned version containing the same address - pub fn acquire<'b>(self) -> Onion3Addr<'b> { - Onion3Addr(Cow::Owned(self.0.into_owned()), self.1) - } -} - -impl PartialEq for Onion3Addr<'_> { - fn eq(&self, other: &Self) -> bool { - self.1 == other.1 && self.0[..] == other.0[..] - } -} - -impl Eq for Onion3Addr<'_> { } - -impl From<([u8; 35], u16)> for Onion3Addr<'_> { - fn from(parts: ([u8; 35], u16)) -> Self { - Self(Cow::Owned(parts.0), parts.1) - } -} - -impl<'a> From<(&'a [u8; 35], u16)> for Onion3Addr<'a> { - fn from(parts: (&'a [u8; 35], u16)) -> Self { - Self(Cow::Borrowed(parts.0), parts.1) - } -} - -impl fmt::Debug for Onion3Addr<'_> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { - f.debug_tuple("Onion3Addr") - .field(&format!("{:02x?}", &self.0[..])) - .field(&self.1) - .finish() - } -} diff --git a/misc/multiaddr/src/protocol.rs b/misc/multiaddr/src/protocol.rs deleted file mode 100644 index d1a5ab9562e..00000000000 --- a/misc/multiaddr/src/protocol.rs +++ /dev/null @@ -1,586 +0,0 @@ - -use arrayref::array_ref; -use byteorder::{BigEndian, ByteOrder, ReadBytesExt, WriteBytesExt}; -use crate::{Result, Error}; -use data_encoding::BASE32; -use multihash::Multihash; -use std::{ - borrow::Cow, - convert::From, - fmt, - io::{Cursor, Write}, - net::{IpAddr, Ipv4Addr, Ipv6Addr}, - str::{self, FromStr} -}; -use unsigned_varint::{encode, decode}; -use crate::onion_addr::Onion3Addr; - -const DCCP: u32 = 33; -const DNS: u32 = 53; -const DNS4: u32 = 54; -const DNS6: u32 = 55; -const DNSADDR: u32 = 56; -const HTTP: u32 = 480; -const HTTPS: u32 = 443; -const IP4: u32 = 4; -const IP6: u32 = 41; -const P2P_WEBRTC_DIRECT: u32 = 276; -const P2P_WEBRTC_STAR: u32 = 275; -const P2P_WEBSOCKET_STAR: u32 = 479; -const MEMORY: u32 = 777; -const ONION: u32 = 444; -const ONION3: u32 = 445; -const P2P: u32 = 421; -const P2P_CIRCUIT: u32 = 290; -const QUIC: u32 = 460; -const SCTP: u32 = 132; -const TCP: u32 = 6; -const UDP: u32 = 273; -const UDT: u32 = 301; -const UNIX: u32 = 400; -const UTP: u32 = 302; -const WS: u32 = 477; -const WS_WITH_PATH: u32 = 4770; // Note: not standard -const WSS: u32 = 478; -const WSS_WITH_PATH: u32 = 4780; // Note: not standard - -const PATH_SEGMENT_ENCODE_SET: &percent_encoding::AsciiSet = &percent_encoding::CONTROLS - .add(b'%') - .add(b'/') - .add(b'`') - .add(b'?') - .add(b'{') - .add(b'}') - .add(b' ') - .add(b'"') - .add(b'#') - .add(b'<') - .add(b'>'); - -/// `Protocol` describes all possible multiaddress protocols. -/// -/// For `Unix`, `Ws` and `Wss` we use `&str` instead of `Path` to allow -/// cross-platform usage of `Protocol` since encoding `Paths` to bytes is -/// platform-specific. This means that the actual validation of paths needs to -/// happen separately. -#[derive(PartialEq, Eq, Clone, Debug)] -pub enum Protocol<'a> { - Dccp(u16), - Dns(Cow<'a, str>), - Dns4(Cow<'a, str>), - Dns6(Cow<'a, str>), - Dnsaddr(Cow<'a, str>), - Http, - Https, - Ip4(Ipv4Addr), - Ip6(Ipv6Addr), - P2pWebRtcDirect, - P2pWebRtcStar, - P2pWebSocketStar, - /// Contains the "port" to contact. Similar to TCP or UDP, 0 means "assign me a port". - Memory(u64), - Onion(Cow<'a, [u8; 10]>, u16), - Onion3(Onion3Addr<'a>), - P2p(Multihash), - P2pCircuit, - Quic, - Sctp(u16), - Tcp(u16), - Udp(u16), - Udt, - Unix(Cow<'a, str>), - Utp, - Ws(Cow<'a, str>), - Wss(Cow<'a, str>), -} - -impl<'a> Protocol<'a> { - /// Parse a protocol value from the given iterator of string slices. - /// - /// The parsing only consumes the minimum amount of string slices necessary to - /// produce a well-formed protocol. The same iterator can thus be used to parse - /// a sequence of protocols in succession. It is up to client code to check - /// that iteration has finished whenever appropriate. - pub fn from_str_parts(mut iter: I) -> Result - where - I: Iterator - { - match iter.next().ok_or(Error::InvalidProtocolString)? { - "ip4" => { - let s = iter.next().ok_or(Error::InvalidProtocolString)?; - Ok(Protocol::Ip4(Ipv4Addr::from_str(s)?)) - } - "tcp" => { - let s = iter.next().ok_or(Error::InvalidProtocolString)?; - Ok(Protocol::Tcp(s.parse()?)) - } - "udp" => { - let s = iter.next().ok_or(Error::InvalidProtocolString)?; - Ok(Protocol::Udp(s.parse()?)) - } - "dccp" => { - let s = iter.next().ok_or(Error::InvalidProtocolString)?; - Ok(Protocol::Dccp(s.parse()?)) - } - "ip6" => { - let s = iter.next().ok_or(Error::InvalidProtocolString)?; - Ok(Protocol::Ip6(Ipv6Addr::from_str(s)?)) - } - "dns" => { - let s = iter.next().ok_or(Error::InvalidProtocolString)?; - Ok(Protocol::Dns(Cow::Borrowed(s))) - } - "dns4" => { - let s = iter.next().ok_or(Error::InvalidProtocolString)?; - Ok(Protocol::Dns4(Cow::Borrowed(s))) - } - "dns6" => { - let s = iter.next().ok_or(Error::InvalidProtocolString)?; - Ok(Protocol::Dns6(Cow::Borrowed(s))) - } - "dnsaddr" => { - let s = iter.next().ok_or(Error::InvalidProtocolString)?; - Ok(Protocol::Dnsaddr(Cow::Borrowed(s))) - } - "sctp" => { - let s = iter.next().ok_or(Error::InvalidProtocolString)?; - Ok(Protocol::Sctp(s.parse()?)) - } - "udt" => Ok(Protocol::Udt), - "utp" => Ok(Protocol::Utp), - "unix" => { - let s = iter.next().ok_or(Error::InvalidProtocolString)?; - Ok(Protocol::Unix(Cow::Borrowed(s))) - } - "p2p" => { - let s = iter.next().ok_or(Error::InvalidProtocolString)?; - let decoded = bs58::decode(s).into_vec()?; - Ok(Protocol::P2p(Multihash::from_bytes(&decoded)?)) - } - "http" => Ok(Protocol::Http), - "https" => Ok(Protocol::Https), - "onion" => - iter.next() - .ok_or(Error::InvalidProtocolString) - .and_then(|s| read_onion(&s.to_uppercase())) - .map(|(a, p)| Protocol::Onion(Cow::Owned(a), p)), - "onion3" => - iter.next() - .ok_or(Error::InvalidProtocolString) - .and_then(|s| read_onion3(&s.to_uppercase())) - .map(|(a, p)| Protocol::Onion3((a, p).into())), - "quic" => Ok(Protocol::Quic), - "ws" => Ok(Protocol::Ws(Cow::Borrowed("/"))), - "wss" => Ok(Protocol::Wss(Cow::Borrowed("/"))), - "x-parity-ws" => { - let s = iter.next().ok_or(Error::InvalidProtocolString)?; - let decoded = percent_encoding::percent_decode(s.as_bytes()).decode_utf8()?; - Ok(Protocol::Ws(decoded)) - } - "x-parity-wss" => { - let s = iter.next().ok_or(Error::InvalidProtocolString)?; - let decoded = percent_encoding::percent_decode(s.as_bytes()).decode_utf8()?; - Ok(Protocol::Wss(decoded)) - } - "p2p-websocket-star" => Ok(Protocol::P2pWebSocketStar), - "p2p-webrtc-star" => Ok(Protocol::P2pWebRtcStar), - "p2p-webrtc-direct" => Ok(Protocol::P2pWebRtcDirect), - "p2p-circuit" => Ok(Protocol::P2pCircuit), - "memory" => { - let s = iter.next().ok_or(Error::InvalidProtocolString)?; - Ok(Protocol::Memory(s.parse()?)) - } - unknown => Err(Error::UnknownProtocolString(unknown.to_string())) - } - } - - /// Parse a single `Protocol` value from its byte slice representation, - /// returning the protocol as well as the remaining byte slice. - pub fn from_bytes(input: &'a [u8]) -> Result<(Self, &'a [u8])> { - fn split_at(n: usize, input: &[u8]) -> Result<(&[u8], &[u8])> { - if input.len() < n { - return Err(Error::DataLessThanLen) - } - Ok(input.split_at(n)) - } - let (id, input) = decode::u32(input)?; - match id { - DCCP => { - let (data, rest) = split_at(2, input)?; - let mut rdr = Cursor::new(data); - let num = rdr.read_u16::()?; - Ok((Protocol::Dccp(num), rest)) - } - DNS => { - let (n, input) = decode::usize(input)?; - let (data, rest) = split_at(n, input)?; - Ok((Protocol::Dns(Cow::Borrowed(str::from_utf8(data)?)), rest)) - } - DNS4 => { - let (n, input) = decode::usize(input)?; - let (data, rest) = split_at(n, input)?; - Ok((Protocol::Dns4(Cow::Borrowed(str::from_utf8(data)?)), rest)) - } - DNS6 => { - let (n, input) = decode::usize(input)?; - let (data, rest) = split_at(n, input)?; - Ok((Protocol::Dns6(Cow::Borrowed(str::from_utf8(data)?)), rest)) - } - DNSADDR => { - let (n, input) = decode::usize(input)?; - let (data, rest) = split_at(n, input)?; - Ok((Protocol::Dnsaddr(Cow::Borrowed(str::from_utf8(data)?)), rest)) - } - HTTP => Ok((Protocol::Http, input)), - HTTPS => Ok((Protocol::Https, input)), - IP4 => { - let (data, rest) = split_at(4, input)?; - Ok((Protocol::Ip4(Ipv4Addr::new(data[0], data[1], data[2], data[3])), rest)) - } - IP6 => { - let (data, rest) = split_at(16, input)?; - let mut rdr = Cursor::new(data); - let mut seg = [0_u16; 8]; - - for x in seg.iter_mut() { - *x = rdr.read_u16::()?; - } - - let addr = Ipv6Addr::new(seg[0], - seg[1], - seg[2], - seg[3], - seg[4], - seg[5], - seg[6], - seg[7]); - - Ok((Protocol::Ip6(addr), rest)) - } - P2P_WEBRTC_DIRECT => Ok((Protocol::P2pWebRtcDirect, input)), - P2P_WEBRTC_STAR => Ok((Protocol::P2pWebRtcStar, input)), - P2P_WEBSOCKET_STAR => Ok((Protocol::P2pWebSocketStar, input)), - MEMORY => { - let (data, rest) = split_at(8, input)?; - let mut rdr = Cursor::new(data); - let num = rdr.read_u64::()?; - Ok((Protocol::Memory(num), rest)) - } - ONION => { - let (data, rest) = split_at(12, input)?; - let port = BigEndian::read_u16(&data[10 ..]); - Ok((Protocol::Onion(Cow::Borrowed(array_ref!(data, 0, 10)), port), rest)) - } - ONION3 => { - let (data, rest) = split_at(37, input)?; - let port = BigEndian::read_u16(&data[35 ..]); - Ok((Protocol::Onion3((array_ref!(data, 0, 35), port).into()), rest)) - } - P2P => { - let (n, input) = decode::usize(input)?; - let (data, rest) = split_at(n, input)?; - Ok((Protocol::P2p(Multihash::from_bytes(data)?), rest)) - } - P2P_CIRCUIT => Ok((Protocol::P2pCircuit, input)), - QUIC => Ok((Protocol::Quic, input)), - SCTP => { - let (data, rest) = split_at(2, input)?; - let mut rdr = Cursor::new(data); - let num = rdr.read_u16::()?; - Ok((Protocol::Sctp(num), rest)) - } - TCP => { - let (data, rest) = split_at(2, input)?; - let mut rdr = Cursor::new(data); - let num = rdr.read_u16::()?; - Ok((Protocol::Tcp(num), rest)) - } - UDP => { - let (data, rest) = split_at(2, input)?; - let mut rdr = Cursor::new(data); - let num = rdr.read_u16::()?; - Ok((Protocol::Udp(num), rest)) - } - UDT => Ok((Protocol::Udt, input)), - UNIX => { - let (n, input) = decode::usize(input)?; - let (data, rest) = split_at(n, input)?; - Ok((Protocol::Unix(Cow::Borrowed(str::from_utf8(data)?)), rest)) - } - UTP => Ok((Protocol::Utp, input)), - WS => Ok((Protocol::Ws(Cow::Borrowed("/")), input)), - WS_WITH_PATH => { - let (n, input) = decode::usize(input)?; - let (data, rest) = split_at(n, input)?; - Ok((Protocol::Ws(Cow::Borrowed(str::from_utf8(data)?)), rest)) - } - WSS => Ok((Protocol::Wss(Cow::Borrowed("/")), input)), - WSS_WITH_PATH => { - let (n, input) = decode::usize(input)?; - let (data, rest) = split_at(n, input)?; - Ok((Protocol::Wss(Cow::Borrowed(str::from_utf8(data)?)), rest)) - } - _ => Err(Error::UnknownProtocolId(id)) - } - } - - /// Encode this protocol by writing its binary representation into - /// the given `Write` impl. - pub fn write_bytes(&self, w: &mut W) -> Result<()> { - let mut buf = encode::u32_buffer(); - match self { - Protocol::Ip4(addr) => { - w.write_all(encode::u32(IP4, &mut buf))?; - w.write_all(&addr.octets())? - } - Protocol::Ip6(addr) => { - w.write_all(encode::u32(IP6, &mut buf))?; - for &segment in &addr.segments() { - w.write_u16::(segment)? - } - } - Protocol::Tcp(port) => { - w.write_all(encode::u32(TCP, &mut buf))?; - w.write_u16::(*port)? - } - Protocol::Udp(port) => { - w.write_all(encode::u32(UDP, &mut buf))?; - w.write_u16::(*port)? - } - Protocol::Dccp(port) => { - w.write_all(encode::u32(DCCP, &mut buf))?; - w.write_u16::(*port)? - } - Protocol::Sctp(port) => { - w.write_all(encode::u32(SCTP, &mut buf))?; - w.write_u16::(*port)? - } - Protocol::Dns(s) => { - w.write_all(encode::u32(DNS, &mut buf))?; - let bytes = s.as_bytes(); - w.write_all(encode::usize(bytes.len(), &mut encode::usize_buffer()))?; - w.write_all(&bytes)? - } - Protocol::Dns4(s) => { - w.write_all(encode::u32(DNS4, &mut buf))?; - let bytes = s.as_bytes(); - w.write_all(encode::usize(bytes.len(), &mut encode::usize_buffer()))?; - w.write_all(&bytes)? - } - Protocol::Dns6(s) => { - w.write_all(encode::u32(DNS6, &mut buf))?; - let bytes = s.as_bytes(); - w.write_all(encode::usize(bytes.len(), &mut encode::usize_buffer()))?; - w.write_all(&bytes)? - } - Protocol::Dnsaddr(s) => { - w.write_all(encode::u32(DNSADDR, &mut buf))?; - let bytes = s.as_bytes(); - w.write_all(encode::usize(bytes.len(), &mut encode::usize_buffer()))?; - w.write_all(&bytes)? - } - Protocol::Unix(s) => { - w.write_all(encode::u32(UNIX, &mut buf))?; - let bytes = s.as_bytes(); - w.write_all(encode::usize(bytes.len(), &mut encode::usize_buffer()))?; - w.write_all(&bytes)? - } - Protocol::P2p(multihash) => { - w.write_all(encode::u32(P2P, &mut buf))?; - let bytes = multihash.to_bytes(); - w.write_all(encode::usize(bytes.len(), &mut encode::usize_buffer()))?; - w.write_all(&bytes)? - } - Protocol::Onion(addr, port) => { - w.write_all(encode::u32(ONION, &mut buf))?; - w.write_all(addr.as_ref())?; - w.write_u16::(*port)? - } - Protocol::Onion3(addr) => { - w.write_all(encode::u32(ONION3, &mut buf))?; - w.write_all(addr.hash().as_ref())?; - w.write_u16::(addr.port())? - } - Protocol::Quic => w.write_all(encode::u32(QUIC, &mut buf))?, - Protocol::Utp => w.write_all(encode::u32(UTP, &mut buf))?, - Protocol::Udt => w.write_all(encode::u32(UDT, &mut buf))?, - Protocol::Http => w.write_all(encode::u32(HTTP, &mut buf))?, - Protocol::Https => w.write_all(encode::u32(HTTPS, &mut buf))?, - Protocol::Ws(ref s) if s == "/" => w.write_all(encode::u32(WS, &mut buf))?, - Protocol::Ws(s) => { - w.write_all(encode::u32(WS_WITH_PATH, &mut buf))?; - let bytes = s.as_bytes(); - w.write_all(encode::usize(bytes.len(), &mut encode::usize_buffer()))?; - w.write_all(&bytes)? - }, - Protocol::Wss(ref s) if s == "/" => w.write_all(encode::u32(WSS, &mut buf))?, - Protocol::Wss(s) => { - w.write_all(encode::u32(WSS_WITH_PATH, &mut buf))?; - let bytes = s.as_bytes(); - w.write_all(encode::usize(bytes.len(), &mut encode::usize_buffer()))?; - w.write_all(&bytes)? - }, - Protocol::P2pWebSocketStar => w.write_all(encode::u32(P2P_WEBSOCKET_STAR, &mut buf))?, - Protocol::P2pWebRtcStar => w.write_all(encode::u32(P2P_WEBRTC_STAR, &mut buf))?, - Protocol::P2pWebRtcDirect => w.write_all(encode::u32(P2P_WEBRTC_DIRECT, &mut buf))?, - Protocol::P2pCircuit => w.write_all(encode::u32(P2P_CIRCUIT, &mut buf))?, - Protocol::Memory(port) => { - w.write_all(encode::u32(MEMORY, &mut buf))?; - w.write_u64::(*port)? - } - } - Ok(()) - } - - /// Turn this `Protocol` into one that owns its data, thus being valid for any lifetime. - pub fn acquire<'b>(self) -> Protocol<'b> { - use self::Protocol::*; - match self { - Dccp(a) => Dccp(a), - Dns(cow) => Dns(Cow::Owned(cow.into_owned())), - Dns4(cow) => Dns4(Cow::Owned(cow.into_owned())), - Dns6(cow) => Dns6(Cow::Owned(cow.into_owned())), - Dnsaddr(cow) => Dnsaddr(Cow::Owned(cow.into_owned())), - Http => Http, - Https => Https, - Ip4(a) => Ip4(a), - Ip6(a) => Ip6(a), - P2pWebRtcDirect => P2pWebRtcDirect, - P2pWebRtcStar => P2pWebRtcStar, - P2pWebSocketStar => P2pWebSocketStar, - Memory(a) => Memory(a), - Onion(addr, port) => Onion(Cow::Owned(addr.into_owned()), port), - Onion3(addr) => Onion3(addr.acquire()), - P2p(a) => P2p(a), - P2pCircuit => P2pCircuit, - Quic => Quic, - Sctp(a) => Sctp(a), - Tcp(a) => Tcp(a), - Udp(a) => Udp(a), - Udt => Udt, - Unix(cow) => Unix(Cow::Owned(cow.into_owned())), - Utp => Utp, - Ws(cow) => Ws(Cow::Owned(cow.into_owned())), - Wss(cow) => Wss(Cow::Owned(cow.into_owned())), - } - } -} - -impl<'a> fmt::Display for Protocol<'a> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - use self::Protocol::*; - match self { - Dccp(port) => write!(f, "/dccp/{}", port), - Dns(s) => write!(f, "/dns/{}", s), - Dns4(s) => write!(f, "/dns4/{}", s), - Dns6(s) => write!(f, "/dns6/{}", s), - Dnsaddr(s) => write!(f, "/dnsaddr/{}", s), - Http => f.write_str("/http"), - Https => f.write_str("/https"), - Ip4(addr) => write!(f, "/ip4/{}", addr), - Ip6(addr) => write!(f, "/ip6/{}", addr), - P2pWebRtcDirect => f.write_str("/p2p-webrtc-direct"), - P2pWebRtcStar => f.write_str("/p2p-webrtc-star"), - P2pWebSocketStar => f.write_str("/p2p-websocket-star"), - Memory(port) => write!(f, "/memory/{}", port), - Onion(addr, port) => { - let s = BASE32.encode(addr.as_ref()); - write!(f, "/onion/{}:{}", s.to_lowercase(), port) - } - Onion3(addr ) => { - let s = BASE32.encode(addr.hash()); - write!(f, "/onion3/{}:{}", s.to_lowercase(), addr.port()) - } - P2p(c) => write!(f, "/p2p/{}", bs58::encode(c.to_bytes()).into_string()), - P2pCircuit => f.write_str("/p2p-circuit"), - Quic => f.write_str("/quic"), - Sctp(port) => write!(f, "/sctp/{}", port), - Tcp(port) => write!(f, "/tcp/{}", port), - Udp(port) => write!(f, "/udp/{}", port), - Udt => f.write_str("/udt"), - Unix(s) => write!(f, "/unix/{}", s), - Utp => f.write_str("/utp"), - Ws(ref s) if s == "/" => f.write_str("/ws"), - Ws(s) => { - let encoded = percent_encoding::percent_encode(s.as_bytes(), PATH_SEGMENT_ENCODE_SET); - write!(f, "/x-parity-ws/{}", encoded) - }, - Wss(ref s) if s == "/" => f.write_str("/wss"), - Wss(s) => { - let encoded = percent_encoding::percent_encode(s.as_bytes(), PATH_SEGMENT_ENCODE_SET); - write!(f, "/x-parity-wss/{}", encoded) - }, - } - } -} - -impl<'a> From for Protocol<'a> { - #[inline] - fn from(addr: IpAddr) -> Self { - match addr { - IpAddr::V4(addr) => Protocol::Ip4(addr), - IpAddr::V6(addr) => Protocol::Ip6(addr), - } - } -} - -impl<'a> From for Protocol<'a> { - #[inline] - fn from(addr: Ipv4Addr) -> Self { - Protocol::Ip4(addr) - } -} - -impl<'a> From for Protocol<'a> { - #[inline] - fn from(addr: Ipv6Addr) -> Self { - Protocol::Ip6(addr) - } -} - -macro_rules! read_onion_impl { - ($name:ident, $len:expr, $encoded_len:expr) => { - fn $name(s: &str) -> Result<([u8; $len], u16)> { - let mut parts = s.split(':'); - - // address part (without ".onion") - let b32 = parts.next().ok_or(Error::InvalidMultiaddr)?; - if b32.len() != $encoded_len { - return Err(Error::InvalidMultiaddr) - } - - // port number - let port = parts.next() - .ok_or(Error::InvalidMultiaddr) - .and_then(|p| str::parse(p).map_err(From::from))?; - - // port == 0 is not valid for onion - if port == 0 { - return Err(Error::InvalidMultiaddr); - } - - // nothing else expected - if parts.next().is_some() { - return Err(Error::InvalidMultiaddr) - } - - if $len != BASE32.decode_len(b32.len()).map_err(|_| Error::InvalidMultiaddr)? { - return Err(Error::InvalidMultiaddr) - } - - let mut buf = [0u8; $len]; - BASE32.decode_mut(b32.as_bytes(), &mut buf).map_err(|_| Error::InvalidMultiaddr)?; - - Ok((buf, port)) - } - } -} - -// Parse a version 2 onion address and return its binary representation. -// -// Format: ":" -read_onion_impl!(read_onion, 10, 16); -// Parse a version 3 onion address and return its binary representation. -// -// Format: ":" -read_onion_impl!(read_onion3, 35, 56); diff --git a/misc/multiaddr/tests/lib.rs b/misc/multiaddr/tests/lib.rs deleted file mode 100644 index 15993e4672b..00000000000 --- a/misc/multiaddr/tests/lib.rs +++ /dev/null @@ -1,389 +0,0 @@ - -use data_encoding::HEXUPPER; -use multihash::Multihash; -use parity_multiaddr::*; -use quickcheck::{Arbitrary, Gen, QuickCheck}; -use rand::Rng; -use std::{ - borrow::Cow, - convert::TryFrom, - iter::FromIterator, - net::{Ipv4Addr, Ipv6Addr}, - str::FromStr -}; - -// Property tests - -#[test] -fn to_from_bytes_identity() { - fn prop(a: Ma) -> bool { - let b = a.0.to_vec(); - Some(a) == Multiaddr::try_from(b).ok().map(Ma) - } - QuickCheck::new().quickcheck(prop as fn(Ma) -> bool) -} - -#[test] -fn to_from_str_identity() { - fn prop(a: Ma) -> bool { - let b = a.0.to_string(); - Some(a) == Multiaddr::from_str(&b).ok().map(Ma) - } - QuickCheck::new().quickcheck(prop as fn(Ma) -> bool) -} - -#[test] -fn byteswriter() { - fn prop(a: Ma, b: Ma) -> bool { - let mut x = a.0.clone(); - for p in b.0.iter() { - x = x.with(p) - } - x.iter().zip(a.0.iter().chain(b.0.iter())).all(|(x, y)| x == y) - } - QuickCheck::new().quickcheck(prop as fn(Ma, Ma) -> bool) -} - -#[test] -fn push_pop_identity() { - fn prop(a: Ma, p: Proto) -> bool { - let mut b = a.clone(); - let q = p.clone(); - b.0.push(q.0); - assert_ne!(a.0, b.0); - Some(p.0) == b.0.pop() && a.0 == b.0 - } - QuickCheck::new().quickcheck(prop as fn(Ma, Proto) -> bool) -} - -#[test] -fn ends_with() { - fn prop(Ma(m): Ma) { - let n = m.iter().count(); - for i in 0 .. n { - let suffix = m.iter().skip(i).collect::(); - assert!(m.ends_with(&suffix)); - } - } - QuickCheck::new().quickcheck(prop as fn(_)) -} - - -// Arbitrary impls - - -#[derive(PartialEq, Eq, Clone, Hash, Debug)] -struct Ma(Multiaddr); - -impl Arbitrary for Ma { - fn arbitrary(g: &mut G) -> Self { - let iter = (0 .. g.next_u32() % 128).map(|_| Proto::arbitrary(g).0); - Ma(Multiaddr::from_iter(iter)) - } -} - -#[derive(PartialEq, Eq, Clone, Debug)] -struct Proto(Protocol<'static>); - -impl Arbitrary for Proto { - fn arbitrary(g: &mut G) -> Self { - use Protocol::*; - match g.gen_range(0, 25) { // TODO: Add Protocol::Quic - 0 => Proto(Dccp(g.gen())), - 1 => Proto(Dns(Cow::Owned(SubString::arbitrary(g).0))), - 2 => Proto(Dns4(Cow::Owned(SubString::arbitrary(g).0))), - 3 => Proto(Dns6(Cow::Owned(SubString::arbitrary(g).0))), - 4 => Proto(Http), - 5 => Proto(Https), - 6 => Proto(Ip4(Ipv4Addr::arbitrary(g))), - 7 => Proto(Ip6(Ipv6Addr::arbitrary(g))), - 8 => Proto(P2pWebRtcDirect), - 9 => Proto(P2pWebRtcStar), - 10 => Proto(P2pWebSocketStar), - 11 => Proto(Memory(g.gen())), - // TODO: impl Arbitrary for Multihash: - 12 => Proto(P2p(multihash("QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC"))), - 13 => Proto(P2pCircuit), - 14 => Proto(Quic), - 15 => Proto(Sctp(g.gen())), - 16 => Proto(Tcp(g.gen())), - 17 => Proto(Udp(g.gen())), - 18 => Proto(Udt), - 19 => Proto(Unix(Cow::Owned(SubString::arbitrary(g).0))), - 20 => Proto(Utp), - 21 => Proto(Ws("/".into())), - 22 => Proto(Wss("/".into())), - 23 => { - let mut a = [0; 10]; - g.fill(&mut a); - Proto(Onion(Cow::Owned(a), g.gen_range(1, std::u16::MAX))) - }, - 24 => { - let mut a = [0; 35]; - g.fill_bytes(&mut a); - Proto(Onion3((a, g.gen_range(1, std::u16::MAX)).into())) - }, - _ => panic!("outside range") - } - } -} - -#[derive(PartialEq, Eq, Clone, Debug)] -struct SubString(String); // ASCII string without '/' - -impl Arbitrary for SubString { - fn arbitrary(g: &mut G) -> Self { - let mut s = String::arbitrary(g); - s.retain(|c| c.is_ascii() && c != '/'); - SubString(s) - } -} - - -// other unit tests - - -fn ma_valid(source: &str, target: &str, protocols: Vec>) { - let parsed = source.parse::().unwrap(); - assert_eq!(HEXUPPER.encode(&parsed.to_vec()[..]), target); - assert_eq!(parsed.iter().collect::>(), protocols); - assert_eq!(source.parse::().unwrap().to_string(), source); - assert_eq!(Multiaddr::try_from(HEXUPPER.decode(target.as_bytes()).unwrap()).unwrap(), parsed); -} - -fn multihash(s: &str) -> Multihash { - Multihash::from_bytes(&bs58::decode(s).into_vec().unwrap()).unwrap() -} - -#[test] -fn multiaddr_eq() { - let m1 = "/ip4/127.0.0.1/udp/1234".parse::().unwrap(); - let m2 = "/ip4/127.0.0.1/tcp/1234".parse::().unwrap(); - let m3 = "/ip4/127.0.0.1/tcp/1234".parse::().unwrap(); - - assert_ne!(m1, m2); - assert_ne!(m2, m1); - assert_eq!(m2, m3); - assert_eq!(m1, m1); -} - -#[test] -fn construct_success() { - use Protocol::*; - - let local: Ipv4Addr = "127.0.0.1".parse().unwrap(); - let addr6: Ipv6Addr = "2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095".parse().unwrap(); - - ma_valid("/ip4/1.2.3.4", "0401020304", vec![Ip4("1.2.3.4".parse().unwrap())]); - ma_valid("/ip4/0.0.0.0", "0400000000", vec![Ip4("0.0.0.0".parse().unwrap())]); - ma_valid("/ip6/::1", "2900000000000000000000000000000001", vec![Ip6("::1".parse().unwrap())]); - ma_valid("/ip6/2601:9:4f81:9700:803e:ca65:66e8:c21", - "29260100094F819700803ECA6566E80C21", - vec![Ip6("2601:9:4f81:9700:803e:ca65:66e8:c21".parse().unwrap())]); - ma_valid("/udp/0", "91020000", vec![Udp(0)]); - ma_valid("/tcp/0", "060000", vec![Tcp(0)]); - ma_valid("/sctp/0", "84010000", vec![Sctp(0)]); - ma_valid("/udp/1234", "910204D2", vec![Udp(1234)]); - ma_valid("/tcp/1234", "0604D2", vec![Tcp(1234)]); - ma_valid("/sctp/1234", "840104D2", vec![Sctp(1234)]); - ma_valid("/udp/65535", "9102FFFF", vec![Udp(65535)]); - ma_valid("/tcp/65535", "06FFFF", vec![Tcp(65535)]); - ma_valid("/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC", - "A503221220D52EBB89D85B02A284948203A62FF28389C57C9F42BEEC4EC20DB76A68911C0B", - vec![P2p(multihash("QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC"))]); - ma_valid("/udp/1234/sctp/1234", "910204D2840104D2", vec![Udp(1234), Sctp(1234)]); - ma_valid("/udp/1234/udt", "910204D2AD02", vec![Udp(1234), Udt]); - ma_valid("/udp/1234/utp", "910204D2AE02", vec![Udp(1234), Utp]); - ma_valid("/tcp/1234/http", "0604D2E003", vec![Tcp(1234), Http]); - ma_valid("/tcp/1234/https", "0604D2BB03", vec![Tcp(1234), Https]); - ma_valid("/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234", - "A503221220D52EBB89D85B02A284948203A62FF28389C57C9F42BEEC4EC20DB76A68911C0B0604D2", - vec![P2p(multihash("QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC")), Tcp(1234)]); - ma_valid("/ip4/127.0.0.1/udp/1234", "047F000001910204D2", vec![Ip4(local.clone()), Udp(1234)]); - ma_valid("/ip4/127.0.0.1/udp/0", "047F00000191020000", vec![Ip4(local.clone()), Udp(0)]); - ma_valid("/ip4/127.0.0.1/tcp/1234", "047F0000010604D2", vec![Ip4(local.clone()), Tcp(1234)]); - ma_valid("/ip4/127.0.0.1/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC", - "047F000001A503221220D52EBB89D85B02A284948203A62FF28389C57C9F42BEEC4EC20DB76A68911C0B", - vec![Ip4(local.clone()), P2p(multihash("QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC"))]); - ma_valid("/ip4/127.0.0.1/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234", - "047F000001A503221220D52EBB89D85B02A284948203A62FF28389C57C9F42BEEC4EC20DB76A68911C0B0604D2", - vec![Ip4(local.clone()), P2p(multihash("QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC")), Tcp(1234)]); - // /unix/a/b/c/d/e, - // /unix/stdio, - // /ip4/1.2.3.4/tcp/80/unix/a/b/c/d/e/f, - // /ip4/127.0.0.1/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234/unix/stdio - ma_valid("/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095/tcp/8000/ws/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC", - "29200108A07AC542013AC986FFFE317095061F40DD03A503221220D52EBB89D85B02A284948203A62FF28389C57C9F42BEEC4EC20DB76A68911C0B", - vec![Ip6(addr6.clone()), Tcp(8000), Ws("/".into()), P2p(multihash("QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC")) - ]); - ma_valid("/p2p-webrtc-star/ip4/127.0.0.1/tcp/9090/ws/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC", - "9302047F000001062382DD03A503221220D52EBB89D85B02A284948203A62FF28389C57C9F42BEEC4EC20DB76A68911C0B", - vec![P2pWebRtcStar, Ip4(local.clone()), Tcp(9090), Ws("/".into()), P2p(multihash("QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC")) - ]); - ma_valid("/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095/tcp/8000/wss/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC", - "29200108A07AC542013AC986FFFE317095061F40DE03A503221220D52EBB89D85B02A284948203A62FF28389C57C9F42BEEC4EC20DB76A68911C0B", - vec![Ip6(addr6.clone()), Tcp(8000), Wss("/".into()), P2p(multihash("QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC"))]); - ma_valid("/ip4/127.0.0.1/tcp/9090/p2p-circuit/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC", - "047F000001062382A202A503221220D52EBB89D85B02A284948203A62FF28389C57C9F42BEEC4EC20DB76A68911C0B", - vec![Ip4(local.clone()), Tcp(9090), P2pCircuit, P2p(multihash("QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC"))]); - - ma_valid( - "/onion/aaimaq4ygg2iegci:80", - "BC030010C0439831B48218480050", - vec![Onion(Cow::Owned([0, 16, 192, 67, 152, 49, 180, 130, 24, 72]), 80)], - ); - ma_valid( - "/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:1234", - "BD03ADADEC040BE047F9658668B11A504F3155001F231A37F54C4476C07FB4CC139ED7E30304D2", - vec![Onion3(([173, 173, 236, 4, 11, 224, 71, 249, 101, 134, 104, 177, 26, 80, 79, 49, 85, 0, 31, 35, 26, 55, 245, 76, 68, 118, 192, 127, 180, 204, 19, 158, 215, 227, 3], 1234).into())], - ); - ma_valid( - "/dnsaddr/sjc-1.bootstrap.libp2p.io", - "3819736A632D312E626F6F7473747261702E6C69627032702E696F", - vec![Dnsaddr(Cow::Borrowed("sjc-1.bootstrap.libp2p.io"))] - ); - ma_valid( - "/dnsaddr/sjc-1.bootstrap.libp2p.io/tcp/1234/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN", - "3819736A632D312E626F6F7473747261702E6C69627032702E696F0604D2A50322122006B3608AA000274049EB28AD8E793A26FF6FAB281A7D3BD77CD18EB745DFAABB", - vec![Dnsaddr(Cow::Borrowed("sjc-1.bootstrap.libp2p.io")), Tcp(1234), P2p(multihash("QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN"))] - ); -} - -#[test] -fn construct_fail() { - let addresses = [ - "/ip4", - "/ip4/::1", - "/ip4/fdpsofodsajfdoisa", - "/ip6", - "/udp", - "/tcp", - "/sctp", - "/udp/65536", - "/tcp/65536", - "/onion/9imaq4ygg2iegci7:80", - "/onion/aaimaq4ygg2iegci7:80", - "/onion/timaq4ygg2iegci7:0", - "/onion/timaq4ygg2iegci7:-1", - "/onion/timaq4ygg2iegci7", - "/onion/timaq4ygg2iegci@:666", - "/onion3/9ww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:80", - "/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd7:80", - "/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:0", - "/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:-1", - "/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd", - "/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyy@:666", - "/udp/1234/sctp", - "/udp/1234/udt/1234", - "/udp/1234/utp/1234", - "/ip4/127.0.0.1/udp/jfodsajfidosajfoidsa", - "/ip4/127.0.0.1/udp", - "/ip4/127.0.0.1/tcp/jfodsajfidosajfoidsa", - "/ip4/127.0.0.1/tcp", - "/ip4/127.0.0.1/p2p", - "/ip4/127.0.0.1/p2p/tcp", - "/p2p-circuit/50" - ]; - - for address in &addresses { - assert!(address.parse::().is_err(), address.to_string()); - } -} - - -#[test] -fn to_multiaddr() { - assert_eq!(Multiaddr::from(Ipv4Addr::new(127, 0, 0, 1)), "/ip4/127.0.0.1".parse().unwrap()); - assert_eq!(Multiaddr::from(Ipv6Addr::new(0x2601, 0x9, 0x4f81, 0x9700, 0x803e, 0xca65, 0x66e8, 0xc21)), - "/ip6/2601:9:4f81:9700:803e:ca65:66e8:c21".parse().unwrap()); - assert_eq!(Multiaddr::try_from("/ip4/127.0.0.1/tcp/1234".to_string()).unwrap(), - "/ip4/127.0.0.1/tcp/1234".parse::().unwrap()); - assert_eq!(Multiaddr::try_from("/ip6/2601:9:4f81:9700:803e:ca65:66e8:c21").unwrap(), - "/ip6/2601:9:4f81:9700:803e:ca65:66e8:c21".parse::().unwrap()); - assert_eq!(Multiaddr::from(Ipv4Addr::new(127, 0, 0, 1)).with(Protocol::Tcp(1234)), - "/ip4/127.0.0.1/tcp/1234".parse::().unwrap()); - assert_eq!(Multiaddr::from(Ipv6Addr::new(0x2601, 0x9, 0x4f81, 0x9700, 0x803e, 0xca65, 0x66e8, 0xc21)) - .with(Protocol::Tcp(1234)), - "/ip6/2601:9:4f81:9700:803e:ca65:66e8:c21/tcp/1234".parse::().unwrap()); -} - -#[test] -fn from_bytes_fail() { - let bytes = vec![1, 2, 3, 4]; - assert!(Multiaddr::try_from(bytes).is_err()); -} - - -#[test] -fn ser_and_deser_json() { - let addr : Multiaddr = "/ip4/0.0.0.0/tcp/0".parse::().unwrap(); - let serialized = serde_json::to_string(&addr).unwrap(); - assert_eq!(serialized, "\"/ip4/0.0.0.0/tcp/0\""); - let deserialized: Multiaddr = serde_json::from_str(&serialized).unwrap(); - assert_eq!(addr, deserialized); -} - - -#[test] -fn ser_and_deser_bincode() { - let addr : Multiaddr = "/ip4/0.0.0.0/tcp/0".parse::().unwrap(); - let serialized = bincode::serialize(&addr).unwrap(); - // compact addressing - assert_eq!(serialized, vec![8, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 6, 0, 0]); - let deserialized: Multiaddr = bincode::deserialize(&serialized).unwrap(); - assert_eq!(addr, deserialized); -} - -#[test] -fn append() { - let mut a: Multiaddr = Protocol::Ip4(Ipv4Addr::new(1, 2, 3, 4)).into(); - a.push(Protocol::Tcp(80)); - a.push(Protocol::Http); - - let mut i = a.iter(); - assert_eq!(Some(Protocol::Ip4(Ipv4Addr::new(1, 2, 3, 4))), i.next()); - assert_eq!(Some(Protocol::Tcp(80)), i.next()); - assert_eq!(Some(Protocol::Http), i.next()); - assert_eq!(None, i.next()) -} - -fn replace_ip_addr(a: &Multiaddr, p: Protocol<'_>) -> Option { - a.replace(0, move |x| match x { - Protocol::Ip4(_) | Protocol::Ip6(_) => Some(p), - _ => None - }) -} - -#[test] -fn replace_ip4_with_ip4() { - let server = multiaddr!(Ip4(Ipv4Addr::LOCALHOST), Tcp(10000u16)); - let result = replace_ip_addr(&server, Protocol::Ip4([80, 81, 82, 83].into())).unwrap(); - assert_eq!(result, multiaddr!(Ip4([80, 81, 82, 83]), Tcp(10000u16))) -} - -#[test] -fn replace_ip6_with_ip4() { - let server = multiaddr!(Ip6(Ipv6Addr::LOCALHOST), Tcp(10000u16)); - let result = replace_ip_addr(&server, Protocol::Ip4([80, 81, 82, 83].into())).unwrap(); - assert_eq!(result, multiaddr!(Ip4([80, 81, 82, 83]), Tcp(10000u16))) -} - -#[test] -fn replace_ip4_with_ip6() { - let server = multiaddr!(Ip4(Ipv4Addr::LOCALHOST), Tcp(10000u16)); - let result = replace_ip_addr(&server, "2001:db8::1".parse::().unwrap().into()); - assert_eq!(result.unwrap(), "/ip6/2001:db8::1/tcp/10000".parse::().unwrap()) -} - -#[test] -fn unknown_protocol_string() { - match "/unknown/1.2.3.4".parse::() { - Ok(_) => assert!(false, "The UnknownProtocolString error should be caused"), - Err(e) => match e { - crate::Error::UnknownProtocolString(protocol) => { - assert_eq!(protocol, "unknown") - }, - _ => assert!(false, "The UnknownProtocolString error should be caused") - } - } -} diff --git a/muxers/mplex/CHANGELOG.md b/muxers/mplex/CHANGELOG.md index fc4af02b2e4..ec1679f87d4 100644 --- a/muxers/mplex/CHANGELOG.md +++ b/muxers/mplex/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.29.0 [unreleased] + +- Update dependencies. + # 0.28.0 [2021-03-17] - Update dependencies. diff --git a/muxers/mplex/Cargo.toml b/muxers/mplex/Cargo.toml index 4a90d7b4255..ae668ac92d4 100644 --- a/muxers/mplex/Cargo.toml +++ b/muxers/mplex/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-mplex" edition = "2018" description = "Mplex multiplexing protocol for libp2p" -version = "0.28.0" +version = "0.29.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -13,7 +13,7 @@ categories = ["network-programming", "asynchronous"] bytes = "1" futures = "0.3.1" asynchronous-codec = "0.6" -libp2p-core = { version = "0.28.0", path = "../../core" } +libp2p-core = { version = "0.29.0", path = "../../core" } log = "0.4" nohash-hasher = "0.2" parking_lot = "0.11" diff --git a/muxers/yamux/CHANGELOG.md b/muxers/yamux/CHANGELOG.md index 8d73dcf37b8..9698f9f40dd 100644 --- a/muxers/yamux/CHANGELOG.md +++ b/muxers/yamux/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.33.0 [unreleased] + +- Update dependencies. + # 0.32.0 [2021-04-13] - Update to `yamux` `v0.9.0` [PR diff --git a/muxers/yamux/Cargo.toml b/muxers/yamux/Cargo.toml index 536309e39c3..d4278d75516 100644 --- a/muxers/yamux/Cargo.toml +++ b/muxers/yamux/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-yamux" edition = "2018" description = "Yamux multiplexing protocol for libp2p" -version = "0.32.0" +version = "0.33.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -11,7 +11,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] futures = "0.3.1" -libp2p-core = { version = "0.28.0", path = "../../core" } +libp2p-core = { version = "0.29.0", path = "../../core" } parking_lot = "0.11" thiserror = "1.0" yamux = "0.9.0" diff --git a/protocols/floodsub/CHANGELOG.md b/protocols/floodsub/CHANGELOG.md index 691982d4d5a..e31da085208 100644 --- a/protocols/floodsub/CHANGELOG.md +++ b/protocols/floodsub/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.30.0 [unreleased] + +- Update dependencies. + # 0.29.0 [2021-04-13] - Update `libp2p-swarm`. diff --git a/protocols/floodsub/Cargo.toml b/protocols/floodsub/Cargo.toml index 52d5c54f7c9..2ff1677461e 100644 --- a/protocols/floodsub/Cargo.toml +++ b/protocols/floodsub/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-floodsub" edition = "2018" description = "Floodsub protocol for libp2p" -version = "0.29.0" +version = "0.30.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -13,8 +13,8 @@ categories = ["network-programming", "asynchronous"] cuckoofilter = "0.5.0" fnv = "1.0" futures = "0.3.1" -libp2p-core = { version = "0.28.0", path = "../../core" } -libp2p-swarm = { version = "0.29.0", path = "../../swarm" } +libp2p-core = { version = "0.29.0", path = "../../core" } +libp2p-swarm = { version = "0.30.0", path = "../../swarm" } log = "0.4" prost = "0.7" rand = "0.7" @@ -22,4 +22,3 @@ smallvec = "1.6.1" [build-dependencies] prost-build = "0.7" - diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index 20f004d5a56..8479e17399f 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.32.0 [unreleased] + +- Update dependencies. + # 0.31.0 [2021-05-17] - Keep connections to peers in a mesh alive. Allow closing idle connections to peers not in a mesh diff --git a/protocols/gossipsub/Cargo.toml b/protocols/gossipsub/Cargo.toml index 2d6c7c6a748..a4845f06580 100644 --- a/protocols/gossipsub/Cargo.toml +++ b/protocols/gossipsub/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-gossipsub" edition = "2018" description = "Gossipsub protocol for libp2p" -version = "0.31.0" +version = "0.32.0" authors = ["Age Manning "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -10,8 +10,8 @@ keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [dependencies] -libp2p-swarm = { version = "0.29.0", path = "../../swarm" } -libp2p-core = { version = "0.28.0", path = "../../core" } +libp2p-swarm = { version = "0.30.0", path = "../../swarm" } +libp2p-core = { version = "0.29.0", path = "../../core" } bytes = "1.0" byteorder = "1.3.4" fnv = "1.0.7" diff --git a/protocols/identify/CHANGELOG.md b/protocols/identify/CHANGELOG.md index ae3c5ba1c19..567823594d6 100644 --- a/protocols/identify/CHANGELOG.md +++ b/protocols/identify/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.30.0 [unreleased] + +- Update dependencies. + # 0.29.0 [2021-04-13] - Add support for configurable automatic push to connected peers diff --git a/protocols/identify/Cargo.toml b/protocols/identify/Cargo.toml index 2166b2ff40a..c772de78864 100644 --- a/protocols/identify/Cargo.toml +++ b/protocols/identify/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-identify" edition = "2018" description = "Nodes identifcation protocol for libp2p" -version = "0.29.0" +version = "0.30.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -11,8 +11,8 @@ categories = ["network-programming", "asynchronous"] [dependencies] futures = "0.3.1" -libp2p-core = { version = "0.28.0", path = "../../core" } -libp2p-swarm = { version = "0.29.0", path = "../../swarm" } +libp2p-core = { version = "0.29.0", path = "../../core" } +libp2p-swarm = { version = "0.30.0", path = "../../swarm" } log = "0.4.1" prost = "0.7" smallvec = "1.6.1" diff --git a/protocols/kad/CHANGELOG.md b/protocols/kad/CHANGELOG.md index 3ebbd9b6405..7497cbe7246 100644 --- a/protocols/kad/CHANGELOG.md +++ b/protocols/kad/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.31.0 [unreleased] + +- Update dependencies. + # 0.30.0 [2021-04-13] - Update `libp2p-swarm`. diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index b72c64cfb3a..5e45a80ed64 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-kad" edition = "2018" description = "Kademlia protocol for libp2p" -version = "0.30.0" +version = "0.31.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -17,8 +17,8 @@ fnv = "1.0" asynchronous-codec = "0.6" futures = "0.3.1" log = "0.4" -libp2p-core = { version = "0.28.0", path = "../../core" } -libp2p-swarm = { version = "0.29.0", path = "../../swarm" } +libp2p-core = { version = "0.29.0", path = "../../core" } +libp2p-swarm = { version = "0.30.0", path = "../../swarm" } prost = "0.7" rand = "0.7.2" sha2 = "0.9.1" @@ -36,4 +36,3 @@ quickcheck = "0.9.0" [build-dependencies] prost-build = "0.7" - diff --git a/protocols/mdns/CHANGELOG.md b/protocols/mdns/CHANGELOG.md index 53c5b3830e4..010c57cb6b1 100644 --- a/protocols/mdns/CHANGELOG.md +++ b/protocols/mdns/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.31.0 [unreleased] + +- Update dependencies. + # 0.30.2 [2021-05-06] - Fix discovered event emission. diff --git a/protocols/mdns/Cargo.toml b/protocols/mdns/Cargo.toml index 8b438ce1033..d4cbed718b8 100644 --- a/protocols/mdns/Cargo.toml +++ b/protocols/mdns/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "libp2p-mdns" edition = "2018" -version = "0.30.2" +version = "0.31.0" description = "Implementation of the libp2p mDNS discovery method" authors = ["Parity Technologies "] license = "MIT" @@ -16,8 +16,8 @@ dns-parser = "0.8.0" futures = "0.3.13" if-watch = "0.2.0" lazy_static = "1.4.0" -libp2p-core = { version = "0.28.0", path = "../../core" } -libp2p-swarm = { version = "0.29.0", path = "../../swarm" } +libp2p-core = { version = "0.29.0", path = "../../core" } +libp2p-swarm = { version = "0.30.0", path = "../../swarm" } log = "0.4.14" rand = "0.8.3" smallvec = "1.6.1" diff --git a/protocols/ping/CHANGELOG.md b/protocols/ping/CHANGELOG.md index 0026d9f6ca3..c656e9aeb6c 100644 --- a/protocols/ping/CHANGELOG.md +++ b/protocols/ping/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.30.0 [unreleased] + +- Update dependencies. + # 0.29.0 [2021-04-13] - Update `libp2p-swarm`. @@ -55,4 +59,3 @@ a single substream for outbound pings, addressing - Close substream in inbound upgrade [PR 1606](https://github.com/libp2p/rust-libp2p/pull/1606). - diff --git a/protocols/ping/Cargo.toml b/protocols/ping/Cargo.toml index b8c9894a38c..6062574b172 100644 --- a/protocols/ping/Cargo.toml +++ b/protocols/ping/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-ping" edition = "2018" description = "Ping protocol for libp2p" -version = "0.29.0" +version = "0.30.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -11,8 +11,8 @@ categories = ["network-programming", "asynchronous"] [dependencies] futures = "0.3.1" -libp2p-core = { version = "0.28.0", path = "../../core" } -libp2p-swarm = { version = "0.29.0", path = "../../swarm" } +libp2p-core = { version = "0.29.0", path = "../../core" } +libp2p-swarm = { version = "0.30.0", path = "../../swarm" } log = "0.4.1" rand = "0.7.2" void = "1.0" diff --git a/protocols/relay/CHANGELOG.md b/protocols/relay/CHANGELOG.md index 3f054ca7511..c644204da9f 100644 --- a/protocols/relay/CHANGELOG.md +++ b/protocols/relay/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.3.0 [unreleased] + +- Update dependencies. + # 0.2.0 [2021-04-13] - Update `libp2p-swarm`. diff --git a/protocols/relay/Cargo.toml b/protocols/relay/Cargo.toml index 10d957dbe0c..27c68fc2c88 100644 --- a/protocols/relay/Cargo.toml +++ b/protocols/relay/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-relay" edition = "2018" description = "Communications relaying for libp2p" -version = "0.2.0" +version = "0.3.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -14,8 +14,8 @@ asynchronous-codec = "0.6" bytes = "1" futures = "0.3.1" futures-timer = "3" -libp2p-core = { version = "0.28", path = "../../core" } -libp2p-swarm = { version = "0.29", path = "../../swarm" } +libp2p-core = { version = "0.29", path = "../../core" } +libp2p-swarm = { version = "0.30", path = "../../swarm" } log = "0.4" pin-project = "1" prost = "0.7" diff --git a/protocols/request-response/CHANGELOG.md b/protocols/request-response/CHANGELOG.md index 9d70cfebb08..093f5b4580d 100644 --- a/protocols/request-response/CHANGELOG.md +++ b/protocols/request-response/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.12.0 [unreleased] + +- Update dependencies. + # 0.11.0 [2021-04-13] - Update `libp2p-swarm`. diff --git a/protocols/request-response/Cargo.toml b/protocols/request-response/Cargo.toml index 1661338f63d..577f8f72b9c 100644 --- a/protocols/request-response/Cargo.toml +++ b/protocols/request-response/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-request-response" edition = "2018" description = "Generic Request/Response Protocols" -version = "0.11.0" +version = "0.12.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -13,8 +13,8 @@ categories = ["network-programming", "asynchronous"] async-trait = "0.1" bytes = "1" futures = "0.3.1" -libp2p-core = { version = "0.28.0", path = "../../core" } -libp2p-swarm = { version = "0.29.0", path = "../../swarm" } +libp2p-core = { version = "0.29.0", path = "../../core" } +libp2p-swarm = { version = "0.30.0", path = "../../swarm" } log = "0.4.11" lru = "0.6" minicbor = { version = "0.8", features = ["std", "derive"] } diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index daf41304b25..422220fe922 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.30.0 [unreleased] + +- Update dependencies. + # 0.29.0 [2021-04-13] - Remove `Deref` and `DerefMut` implementations previously dereferencing to the @@ -6,12 +10,12 @@ be accessed directly, e.g. via `my_swarm.local_peer_id()`. You may use the command below to transform fully qualified method calls on `Swarm` to simple method calls [PR 1995](https://github.com/libp2p/rust-libp2p/pull/1995). - + ``` bash # Go from e.g. `Swarm::local_peer_id(&my_swarm)` to `my_swarm.local_peer_id()`. grep -RiIl --include \*.rs --exclude-dir target . --exclude-dir .git | xargs sed -i "s/\(libp2p::\)*Swarm::\([a-z_]*\)(&mut \([a-z_0-9]*\), /\3.\2(/g" ``` - + - Extend `NetworkBehaviour` callbacks, more concretely introducing new `fn inject_new_listener` and `fn inject_expired_external_addr` and have `fn inject_{new,expired}_listen_addr` provide a `ListenerId` [PR diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index 2a8dbdb3f23..90865fce530 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-swarm" edition = "2018" description = "The libp2p swarm" -version = "0.29.0" +version = "0.30.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] either = "1.6.0" futures = "0.3.1" -libp2p-core = { version = "0.28.0", path = "../core" } +libp2p-core = { version = "0.29.0", path = "../core" } log = "0.4" rand = "0.7" smallvec = "1.6.1" diff --git a/transports/deflate/CHANGELOG.md b/transports/deflate/CHANGELOG.md index 9d8b852e1fd..f6932517139 100644 --- a/transports/deflate/CHANGELOG.md +++ b/transports/deflate/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.29.0 [unreleased] + +- Update dependencies. + # 0.28.0 [2021-03-17] - Update `libp2p-core`. diff --git a/transports/deflate/Cargo.toml b/transports/deflate/Cargo.toml index a25bf4f5c34..6c43b792e1d 100644 --- a/transports/deflate/Cargo.toml +++ b/transports/deflate/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-deflate" edition = "2018" description = "Deflate encryption protocol for libp2p" -version = "0.28.0" +version = "0.29.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -11,7 +11,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] futures = "0.3.1" -libp2p-core = { version = "0.28.0", path = "../../core" } +libp2p-core = { version = "0.29.0", path = "../../core" } flate2 = "1.0" [dev-dependencies] diff --git a/transports/dns/CHANGELOG.md b/transports/dns/CHANGELOG.md index 7510a328a2d..736e25c67ed 100644 --- a/transports/dns/CHANGELOG.md +++ b/transports/dns/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.29.0 [unreleased] + +- Update dependencies. + # 0.28.1 [2021-04-01] - Update dependencies. @@ -48,4 +52,3 @@ # 0.20.0 [2020-07-01] - Dependency and documentation updates. - diff --git a/transports/dns/Cargo.toml b/transports/dns/Cargo.toml index c5db0710dff..e0d3fa83a27 100644 --- a/transports/dns/Cargo.toml +++ b/transports/dns/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-dns" edition = "2018" description = "DNS transport implementation for libp2p" -version = "0.28.1" +version = "0.29.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -10,7 +10,7 @@ keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [dependencies] -libp2p-core = { version = "0.28.1", path = "../../core" } +libp2p-core = { version = "0.29.0", path = "../../core" } log = "0.4.1" futures = "0.3.1" trust-dns-resolver = { version = "0.20", default-features = false, features = ["system-config"] } @@ -31,4 +31,3 @@ tokio = ["trust-dns-resolver/tokio-runtime"] # available for `tokio`. tokio-dns-over-rustls = ["tokio", "trust-dns-resolver/dns-over-rustls"] tokio-dns-over-https-rustls = ["tokio", "trust-dns-resolver/dns-over-https-rustls"] - diff --git a/transports/noise/CHANGELOG.md b/transports/noise/CHANGELOG.md index 7363a697a1a..92e9c1e6621 100644 --- a/transports/noise/CHANGELOG.md +++ b/transports/noise/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.32.0 [unreleased] + +- Update dependencies. + # 0.31.0 [2021-05-17] - Update to `snow` `v0.8.0` ([PR-2068]). diff --git a/transports/noise/Cargo.toml b/transports/noise/Cargo.toml index 1f568f629d4..3114bbceee0 100644 --- a/transports/noise/Cargo.toml +++ b/transports/noise/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "libp2p-noise" description = "Cryptographic handshake protocol using the noise framework." -version = "0.31.0" +version = "0.32.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -12,7 +12,7 @@ bytes = "1" curve25519-dalek = "3.0.0" futures = "0.3.1" lazy_static = "1.2" -libp2p-core = { version = "0.28.0", path = "../../core" } +libp2p-core = { version = "0.29.0", path = "../../core" } log = "0.4" prost = "0.7" rand = "0.8.3" diff --git a/transports/plaintext/CHANGELOG.md b/transports/plaintext/CHANGELOG.md index d05a84c9dd7..3b6a67e6930 100644 --- a/transports/plaintext/CHANGELOG.md +++ b/transports/plaintext/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.29.0 [unreleased] + +- Update dependencies. + # 0.28.0 [2021-03-17] - Update `libp2p-core`. diff --git a/transports/plaintext/Cargo.toml b/transports/plaintext/Cargo.toml index 7507579bebe..3ef638e4b31 100644 --- a/transports/plaintext/Cargo.toml +++ b/transports/plaintext/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-plaintext" edition = "2018" description = "Plaintext encryption dummy protocol for libp2p" -version = "0.28.0" +version = "0.29.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -13,7 +13,7 @@ categories = ["network-programming", "asynchronous"] bytes = "1" futures = "0.3.1" asynchronous-codec = "0.6" -libp2p-core = { version = "0.28.0", path = "../../core" } +libp2p-core = { version = "0.29.0", path = "../../core" } log = "0.4.8" prost = "0.7" unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] } @@ -26,4 +26,3 @@ rand = "0.7" [build-dependencies] prost-build = "0.7" - diff --git a/transports/tcp/CHANGELOG.md b/transports/tcp/CHANGELOG.md index 863869654f6..ebf67d0857c 100644 --- a/transports/tcp/CHANGELOG.md +++ b/transports/tcp/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.29.0 [unreleased] + +- Update dependencies. + # 0.28.0 [2021-03-17] - Update `libp2p-core`. diff --git a/transports/tcp/Cargo.toml b/transports/tcp/Cargo.toml index 54698d76a6b..04eaa28079d 100644 --- a/transports/tcp/Cargo.toml +++ b/transports/tcp/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-tcp" edition = "2018" description = "TCP/IP transport protocol for libp2p" -version = "0.28.0" +version = "0.29.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -17,7 +17,7 @@ if-watch = { version = "0.2.0", optional = true } if-addrs = { version = "0.6.4", optional = true } ipnet = "2.0.0" libc = "0.2.80" -libp2p-core = { version = "0.28.0", path = "../../core" } +libp2p-core = { version = "0.29.0", path = "../../core" } log = "0.4.11" socket2 = { version = "0.4.0", features = ["all"] } tokio-crate = { package = "tokio", version = "1.0.1", default-features = false, features = ["net"], optional = true } diff --git a/transports/uds/CHANGELOG.md b/transports/uds/CHANGELOG.md index 48da84cf5e7..a14aaf82f33 100644 --- a/transports/uds/CHANGELOG.md +++ b/transports/uds/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.29.0 [unreleased] + +- Update dependencies. + # 0.28.0 [2021-03-17] - Update `libp2p-core`. diff --git a/transports/uds/Cargo.toml b/transports/uds/Cargo.toml index db582c56ecc..22efbe2d1ca 100644 --- a/transports/uds/Cargo.toml +++ b/transports/uds/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-uds" edition = "2018" description = "Unix domain sockets transport for libp2p" -version = "0.28.0" +version = "0.29.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -11,7 +11,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.28.0", path = "../../core" } +libp2p-core = { version = "0.29.0", path = "../../core" } log = "0.4.1" futures = "0.3.1" tokio = { version = "1.0.1", default-features = false, features = ["net"], optional = true } diff --git a/transports/wasm-ext/CHANGELOG.md b/transports/wasm-ext/CHANGELOG.md index 4db7ba5e39c..c8331b7d2e1 100644 --- a/transports/wasm-ext/CHANGELOG.md +++ b/transports/wasm-ext/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.29.0 [unreleased] + +- Update dependencies. + # 0.28.2 [2021-04-27] - Support dialing `Multiaddr` with `/p2p` protocol [PR diff --git a/transports/wasm-ext/Cargo.toml b/transports/wasm-ext/Cargo.toml index 4825256dce9..8decb921731 100644 --- a/transports/wasm-ext/Cargo.toml +++ b/transports/wasm-ext/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libp2p-wasm-ext" -version = "0.28.2" +version = "0.29.0" authors = ["Pierre Krieger "] edition = "2018" description = "Allows passing in an external transport in a WASM environment" @@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] futures = "0.3.1" js-sys = "0.3.50" -libp2p-core = { version = "0.28.0", path = "../../core" } +libp2p-core = { version = "0.29.0", path = "../../core" } parity-send-wrapper = "0.1.0" wasm-bindgen = "0.2.42" wasm-bindgen-futures = "0.4.4" diff --git a/transports/websocket/CHANGELOG.md b/transports/websocket/CHANGELOG.md index 69dc925a76b..5b7bfb023a0 100644 --- a/transports/websocket/CHANGELOG.md +++ b/transports/websocket/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.30.0 [unreleased] + +- Update dependencies. + # 0.29.0 [2021-03-17] - Update `libp2p-core`. diff --git a/transports/websocket/Cargo.toml b/transports/websocket/Cargo.toml index 64458370347..a7a378a5fdc 100644 --- a/transports/websocket/Cargo.toml +++ b/transports/websocket/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-websocket" edition = "2018" description = "WebSocket transport for libp2p" -version = "0.29.0" +version = "0.30.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -13,7 +13,7 @@ categories = ["network-programming", "asynchronous"] futures-rustls = "0.21" either = "1.5.3" futures = "0.3.1" -libp2p-core = { version = "0.28.0", path = "../../core" } +libp2p-core = { version = "0.29.0", path = "../../core" } log = "0.4.8" quicksink = "0.1" rw-stream-sink = "0.2.0"