2018-05-18 14:56:11 +02:00
|
|
|
// Copyright 2018 Parity Technologies (UK) Ltd.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2018-08-22 10:46:23 +02:00
|
|
|
//! Libp2p is a peer-to-peer framework.
|
|
|
|
//!
|
|
|
|
//! # Major libp2p concepts
|
|
|
|
//!
|
|
|
|
//! Here is a list of all the major concepts of libp2p.
|
|
|
|
//!
|
|
|
|
//! ## Multiaddr
|
2018-09-12 09:10:05 +02:00
|
|
|
//!
|
2018-08-22 10:46:23 +02:00
|
|
|
//! A `Multiaddr` is a way to reach a node. Examples:
|
2018-09-12 09:10:05 +02:00
|
|
|
//!
|
2018-08-22 10:46:23 +02:00
|
|
|
//! * `/ip4/80.123.90.4/tcp/5432`
|
2018-12-04 13:33:07 +01:00
|
|
|
//! * `/ip6/[::1]/udp/10560/quic`
|
2018-08-22 10:46:23 +02:00
|
|
|
//! * `/unix//path/to/socket`
|
|
|
|
//!
|
|
|
|
//! ## Transport
|
|
|
|
//!
|
|
|
|
//! `Transport` is a trait that represents an object capable of dialing multiaddresses or
|
|
|
|
//! listening on multiaddresses. The `Transport` produces an output which varies depending on the
|
|
|
|
//! object that implements the trait.
|
|
|
|
//!
|
|
|
|
//! Each implementation of `Transport` typically supports only some multiaddresses. For example
|
|
|
|
//! the `TcpConfig` type (which implements `Transport`) only supports multiaddresses of the format
|
|
|
|
//! `/ip4/.../tcp/...`.
|
|
|
|
//!
|
|
|
|
//! Example:
|
|
|
|
//!
|
|
|
|
//! ```rust
|
|
|
|
//! use libp2p::{Multiaddr, Transport, tcp::TcpConfig};
|
2018-12-10 13:39:11 +01:00
|
|
|
//! let tcp = TcpConfig::new();
|
2018-08-22 10:46:23 +02:00
|
|
|
//! let addr: Multiaddr = "/ip4/98.97.96.95/tcp/20500".parse().expect("invalid multiaddr");
|
2018-12-10 13:39:11 +01:00
|
|
|
//! let _outgoing_connec = tcp.dial(addr);
|
2018-08-22 10:46:23 +02:00
|
|
|
//! // Note that `_outgoing_connec` is a `Future`, and therefore doesn't do anything by itself
|
|
|
|
//! // unless it is run through a tokio runtime.
|
|
|
|
//! ```
|
|
|
|
//!
|
2018-12-14 10:41:54 +01:00
|
|
|
//! The easiest way to create a transport is to use the `build_development_transport` function.
|
|
|
|
//! This function provides support for the most common protocols.
|
2018-08-22 10:46:23 +02:00
|
|
|
//!
|
|
|
|
//! Example:
|
|
|
|
//!
|
|
|
|
//! ```rust
|
2018-12-14 10:41:54 +01:00
|
|
|
//! let key = libp2p::secio::SecioKeyPair::ed25519_generated().unwrap();
|
|
|
|
//! let _transport = libp2p::build_development_transport(key);
|
2018-08-22 10:46:23 +02:00
|
|
|
//! // _transport.dial(...);
|
|
|
|
//! ```
|
|
|
|
//!
|
|
|
|
//! See the documentation of the `libp2p-core` crate for more details about transports.
|
|
|
|
//!
|
|
|
|
//! # Connection upgrades
|
|
|
|
//!
|
|
|
|
//! Once a connection has been opened with a remote through a `Transport`, it can be *upgraded*.
|
2018-12-04 13:33:07 +01:00
|
|
|
//! This consists in negotiating a protocol with the remote (through a negotiation protocol
|
|
|
|
//! `multistream-select`), and applying that protocol on the socket.
|
2018-08-22 10:46:23 +02:00
|
|
|
//!
|
|
|
|
//! Example:
|
|
|
|
//!
|
|
|
|
//! ```rust
|
2019-01-02 15:50:08 +01:00
|
|
|
//! # #[cfg(all(any(target_os = "emscripten", target_os = "unknown"), feature = "libp2p-secio"))] {
|
2018-08-22 10:46:23 +02:00
|
|
|
//! use libp2p::{Transport, tcp::TcpConfig, secio::{SecioConfig, SecioKeyPair}};
|
2018-12-10 13:39:11 +01:00
|
|
|
//! let tcp = TcpConfig::new();
|
2018-09-12 09:10:05 +02:00
|
|
|
//! let secio_upgrade = SecioConfig::new(SecioKeyPair::ed25519_generated().unwrap());
|
2018-12-10 13:39:11 +01:00
|
|
|
//! let with_security = tcp.with_upgrade(secio_upgrade);
|
2018-08-22 10:46:23 +02:00
|
|
|
//! // let _ = with_security.dial(...);
|
|
|
|
//! // `with_security` also implements the `Transport` trait, and all the connections opened
|
|
|
|
//! // through it will automatically negotiate the `secio` protocol.
|
2018-08-29 11:24:44 +02:00
|
|
|
//! # }
|
2018-08-22 10:46:23 +02:00
|
|
|
//! ```
|
|
|
|
//!
|
|
|
|
//! See the documentation of the `libp2p-core` crate for more details about upgrades.
|
|
|
|
//!
|
2018-12-04 13:33:07 +01:00
|
|
|
//! ## Topology
|
|
|
|
//!
|
|
|
|
//! The `Topology` trait is implemented for types that hold the layout of a network. When other
|
|
|
|
//! components need the network layout to operate, they are passed an instance of a `Topology`.
|
|
|
|
//!
|
|
|
|
//! The most basic implementation of `Topology` is the `MemoryTopology`, which is essentially a
|
|
|
|
//! `HashMap`. Creating your own `Topology` makes it possible to add for example a reputation
|
|
|
|
//! system.
|
|
|
|
//!
|
|
|
|
//! ## Network behaviour
|
|
|
|
//!
|
|
|
|
//! The `NetworkBehaviour` trait is implemented on types that provide some capability to the
|
|
|
|
//! network. Examples of network behaviours include: periodically ping the nodes we are connected
|
|
|
|
//! to, periodically ask for information from the nodes we are connected to, connect to a DHT and
|
|
|
|
//! make queries to it, propagate messages to the nodes we are connected to (pubsub), and so on.
|
|
|
|
//!
|
2018-08-22 10:46:23 +02:00
|
|
|
//! ## Swarm
|
|
|
|
//!
|
2018-12-04 13:33:07 +01:00
|
|
|
//! The `Swarm` struct contains all active and pending connections to remotes and manages the
|
|
|
|
//! state of all the substreams that have been opened, and all the upgrades that were built upon
|
|
|
|
//! these substreams.
|
2019-01-14 14:10:51 +01:00
|
|
|
//!
|
2018-12-04 13:33:07 +01:00
|
|
|
//! It combines a `Transport`, a `NetworkBehaviour` and a `Topology` together.
|
2018-08-22 10:46:23 +02:00
|
|
|
//!
|
|
|
|
//! See the documentation of the `libp2p-core` crate for more details about creating a swarm.
|
|
|
|
//!
|
|
|
|
//! # Using libp2p
|
|
|
|
//!
|
|
|
|
//! This section contains details about how to use libp2p in practice.
|
|
|
|
//!
|
|
|
|
//! The most simple way to use libp2p consists in the following steps:
|
|
|
|
//!
|
|
|
|
//! - Create a *base* implementation of `Transport` that combines all the protocols you want and
|
|
|
|
//! the upgrades you want, such as the security layer and multiplexing.
|
2018-12-04 13:33:07 +01:00
|
|
|
//! - Create a struct that implements the `NetworkBehaviour` trait and that combines all the
|
|
|
|
//! network behaviours that you want.
|
|
|
|
//! - Create and implement the `Topology` trait that to store the topology of the network.
|
|
|
|
//! - Create a swarm that combines your base transport, the network behaviour, and the topology.
|
|
|
|
//! - This swarm can now be polled with the `tokio` library in order to start the network.
|
2018-08-22 10:46:23 +02:00
|
|
|
//!
|
|
|
|
|
2019-01-14 14:10:51 +01:00
|
|
|
#![doc(html_logo_url = "https://libp2p.io/img/logo_small.png")]
|
|
|
|
#![doc(html_favicon_url = "https://libp2p.io/img/favicon.png")]
|
|
|
|
|
2018-05-18 14:56:11 +02:00
|
|
|
pub extern crate bytes;
|
|
|
|
pub extern crate futures;
|
|
|
|
pub extern crate multiaddr;
|
2018-10-31 08:31:15 +01:00
|
|
|
pub extern crate multihash;
|
2018-05-23 16:27:55 +02:00
|
|
|
pub extern crate tokio_io;
|
2018-06-22 16:12:23 +02:00
|
|
|
pub extern crate tokio_codec;
|
2018-05-18 14:56:11 +02:00
|
|
|
|
2018-11-12 17:12:47 +01:00
|
|
|
extern crate libp2p_core_derive;
|
2018-10-26 11:07:59 +02:00
|
|
|
extern crate tokio_executor;
|
|
|
|
|
2019-01-14 14:10:51 +01:00
|
|
|
#[doc(inline)]
|
|
|
|
pub use libp2p_core as core;
|
2019-01-02 15:50:08 +01:00
|
|
|
#[cfg(not(any(target_os = "emscripten", target_os = "unknown")))]
|
2019-01-14 14:10:51 +01:00
|
|
|
#[doc(inline)]
|
|
|
|
pub use libp2p_dns as dns;
|
|
|
|
#[doc(inline)]
|
|
|
|
pub use libp2p_identify as identify;
|
|
|
|
#[doc(inline)]
|
|
|
|
pub use libp2p_kad as kad;
|
|
|
|
#[doc(inline)]
|
|
|
|
pub use libp2p_floodsub as floodsub;
|
|
|
|
#[doc(inline)]
|
|
|
|
pub use libp2p_mplex as mplex;
|
2019-01-02 15:50:08 +01:00
|
|
|
#[cfg(not(any(target_os = "emscripten", target_os = "unknown")))]
|
2019-01-14 14:10:51 +01:00
|
|
|
#[doc(inline)]
|
|
|
|
pub use libp2p_mdns as mdns;
|
2019-01-30 11:36:00 +01:00
|
|
|
#[cfg(not(any(target_os = "emscripten", target_os = "unknown")))]
|
|
|
|
#[doc(inline)]
|
|
|
|
pub use libp2p_noise as noise;
|
2019-01-14 14:10:51 +01:00
|
|
|
#[doc(inline)]
|
|
|
|
pub use libp2p_ping as ping;
|
|
|
|
#[doc(inline)]
|
|
|
|
pub use libp2p_plaintext as plaintext;
|
|
|
|
#[doc(inline)]
|
|
|
|
pub use libp2p_ratelimit as ratelimit;
|
|
|
|
#[doc(inline)]
|
|
|
|
pub use libp2p_secio as secio;
|
2019-01-02 15:50:08 +01:00
|
|
|
#[cfg(not(any(target_os = "emscripten", target_os = "unknown")))]
|
2019-01-14 14:10:51 +01:00
|
|
|
#[doc(inline)]
|
|
|
|
pub use libp2p_tcp as tcp;
|
|
|
|
#[doc(inline)]
|
|
|
|
pub use libp2p_uds as uds;
|
2018-11-12 11:42:42 +01:00
|
|
|
#[cfg(feature = "libp2p-websocket")]
|
2019-01-14 14:10:51 +01:00
|
|
|
#[doc(inline)]
|
|
|
|
pub use libp2p_websocket as websocket;
|
|
|
|
#[doc(inline)]
|
|
|
|
pub use libp2p_yamux as yamux;
|
2018-05-18 14:56:11 +02:00
|
|
|
|
2018-10-26 11:07:59 +02:00
|
|
|
mod transport_ext;
|
|
|
|
|
2018-05-23 16:27:55 +02:00
|
|
|
pub mod simple;
|
|
|
|
|
2018-11-15 17:41:11 +01:00
|
|
|
pub use self::core::{
|
2018-11-20 10:35:22 +01:00
|
|
|
Transport, PeerId, Swarm,
|
2019-01-10 11:27:06 +01:00
|
|
|
transport::TransportError,
|
2018-11-15 17:41:11 +01:00
|
|
|
upgrade::{InboundUpgrade, InboundUpgradeExt, OutboundUpgrade, OutboundUpgradeExt}
|
|
|
|
};
|
2018-11-12 17:12:47 +01:00
|
|
|
pub use libp2p_core_derive::NetworkBehaviour;
|
2018-05-18 14:56:11 +02:00
|
|
|
pub use self::multiaddr::Multiaddr;
|
2018-05-23 16:27:55 +02:00
|
|
|
pub use self::simple::SimpleProtocol;
|
2018-10-26 11:07:59 +02:00
|
|
|
pub use self::transport_ext::TransportExt;
|
2018-05-18 14:56:11 +02:00
|
|
|
|
2018-12-14 10:41:54 +01:00
|
|
|
use futures::prelude::*;
|
2019-01-10 11:27:06 +01:00
|
|
|
use std::{error, time::Duration};
|
2018-12-14 10:41:54 +01:00
|
|
|
|
|
|
|
/// Builds a `Transport` that supports the most commonly-used protocols that libp2p supports.
|
|
|
|
///
|
|
|
|
/// > **Note**: This `Transport` is not suitable for production usage, as its implementation
|
|
|
|
/// > reserves the right to support additional protocols or remove deprecated protocols.
|
|
|
|
#[inline]
|
|
|
|
pub fn build_development_transport(local_private_key: secio::SecioKeyPair)
|
2019-01-10 11:27:06 +01:00
|
|
|
-> impl Transport<Output = (PeerId, impl core::muxing::StreamMuxer<OutboundSubstream = impl Send, Substream = impl Send> + Send + Sync), Error = impl error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone
|
2018-12-14 10:41:54 +01:00
|
|
|
{
|
|
|
|
build_tcp_ws_secio_mplex_yamux(local_private_key)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Builds an implementation of `Transport` that is suitable for usage with the `Swarm`.
|
|
|
|
///
|
|
|
|
/// The implementation supports TCP/IP, WebSockets over TCP/IP, secio as the encryption layer,
|
|
|
|
/// and mplex or yamux as the multiplexing layer.
|
|
|
|
///
|
|
|
|
/// > **Note**: If you ever need to express the type of this `Transport`.
|
|
|
|
pub fn build_tcp_ws_secio_mplex_yamux(local_private_key: secio::SecioKeyPair)
|
2019-01-10 11:27:06 +01:00
|
|
|
-> impl Transport<Output = (PeerId, impl core::muxing::StreamMuxer<OutboundSubstream = impl Send, Substream = impl Send> + Send + Sync), Error = impl error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone
|
2018-12-14 10:41:54 +01:00
|
|
|
{
|
|
|
|
CommonTransport::new()
|
|
|
|
.with_upgrade(secio::SecioConfig::new(local_private_key))
|
|
|
|
.and_then(move |out, endpoint| {
|
|
|
|
let peer_id = out.remote_key.into_peer_id();
|
|
|
|
let peer_id2 = peer_id.clone();
|
|
|
|
let upgrade = core::upgrade::SelectUpgrade::new(yamux::Config::default(), mplex::MplexConfig::new())
|
|
|
|
// TODO: use a single `.map` instead of two maps
|
|
|
|
.map_inbound(move |muxer| (peer_id, muxer))
|
|
|
|
.map_outbound(move |muxer| (peer_id2, muxer));
|
|
|
|
|
|
|
|
core::upgrade::apply(out.stream, upgrade, endpoint)
|
|
|
|
.map(|(id, muxer)| (id, core::muxing::StreamMuxerBox::new(muxer)))
|
|
|
|
})
|
|
|
|
.with_timeout(Duration::from_secs(20))
|
|
|
|
}
|
|
|
|
|
2018-05-18 14:56:11 +02:00
|
|
|
/// Implementation of `Transport` that supports the most common protocols.
|
|
|
|
///
|
|
|
|
/// The list currently is TCP/IP, DNS, and WebSockets. However this list could change in the
|
|
|
|
/// future to get new transports.
|
|
|
|
#[derive(Debug, Clone)]
|
2018-12-14 10:41:54 +01:00
|
|
|
struct CommonTransport {
|
2018-05-18 14:56:11 +02:00
|
|
|
// The actual implementation of everything.
|
2018-05-23 11:22:49 +02:00
|
|
|
inner: CommonTransportInner
|
|
|
|
}
|
|
|
|
|
2019-01-02 15:50:08 +01:00
|
|
|
#[cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "libp2p-websocket"))]
|
2018-12-14 10:41:54 +01:00
|
|
|
type InnerImplementation = core::transport::OrTransport<dns::DnsConfig<tcp::TcpConfig>, websocket::WsConfig<dns::DnsConfig<tcp::TcpConfig>>>;
|
2019-01-02 15:50:08 +01:00
|
|
|
#[cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), not(feature = "libp2p-websocket")))]
|
2018-12-14 10:41:54 +01:00
|
|
|
type InnerImplementation = dns::DnsConfig<tcp::TcpConfig>;
|
2019-01-02 15:50:08 +01:00
|
|
|
#[cfg(any(target_os = "emscripten", target_os = "unknown"))]
|
2018-12-14 10:41:54 +01:00
|
|
|
type InnerImplementation = websocket::BrowserWsConfig;
|
2018-05-31 17:16:23 +02:00
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
2018-05-23 11:22:49 +02:00
|
|
|
struct CommonTransportInner {
|
2018-05-31 17:16:23 +02:00
|
|
|
inner: InnerImplementation,
|
2018-05-23 11:22:49 +02:00
|
|
|
}
|
2018-05-18 14:56:11 +02:00
|
|
|
|
|
|
|
impl CommonTransport {
|
|
|
|
/// Initializes the `CommonTransport`.
|
|
|
|
#[inline]
|
2019-01-02 15:50:08 +01:00
|
|
|
#[cfg(not(any(target_os = "emscripten", target_os = "unknown")))]
|
2018-07-16 12:15:27 +02:00
|
|
|
pub fn new() -> CommonTransport {
|
2018-11-12 11:42:42 +01:00
|
|
|
let transport = tcp::TcpConfig::new();
|
|
|
|
let transport = dns::DnsConfig::new(transport);
|
|
|
|
#[cfg(feature = "libp2p-websocket")]
|
|
|
|
let transport = {
|
|
|
|
let trans_clone = transport.clone();
|
|
|
|
transport.or_transport(websocket::WsConfig::new(trans_clone))
|
|
|
|
};
|
2018-05-23 11:22:49 +02:00
|
|
|
|
|
|
|
CommonTransport {
|
2018-11-12 11:42:42 +01:00
|
|
|
inner: CommonTransportInner { inner: transport }
|
2018-05-23 11:22:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Initializes the `CommonTransport`.
|
|
|
|
#[inline]
|
2019-01-02 15:50:08 +01:00
|
|
|
#[cfg(any(target_os = "emscripten", target_os = "unknown"))]
|
2018-05-23 11:22:49 +02:00
|
|
|
pub fn new() -> CommonTransport {
|
|
|
|
let inner = websocket::BrowserWsConfig::new();
|
|
|
|
CommonTransport {
|
2019-01-30 15:41:54 +01:00
|
|
|
inner: CommonTransportInner { inner }
|
2018-05-23 11:22:49 +02:00
|
|
|
}
|
2018-05-18 14:56:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Transport for CommonTransport {
|
2018-05-23 11:22:49 +02:00
|
|
|
type Output = <InnerImplementation as Transport>::Output;
|
2019-01-10 11:27:06 +01:00
|
|
|
type Error = <InnerImplementation as Transport>::Error;
|
2018-05-23 11:22:49 +02:00
|
|
|
type Listener = <InnerImplementation as Transport>::Listener;
|
|
|
|
type ListenerUpgrade = <InnerImplementation as Transport>::ListenerUpgrade;
|
|
|
|
type Dial = <InnerImplementation as Transport>::Dial;
|
2018-05-18 14:56:11 +02:00
|
|
|
|
|
|
|
#[inline]
|
2019-01-10 11:27:06 +01:00
|
|
|
fn listen_on(self, addr: Multiaddr) -> Result<(Self::Listener, Multiaddr), TransportError<Self::Error>> {
|
|
|
|
self.inner.inner.listen_on(addr)
|
2018-05-18 14:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2019-01-10 11:27:06 +01:00
|
|
|
fn dial(self, addr: Multiaddr) -> Result<Self::Dial, TransportError<Self::Error>> {
|
|
|
|
self.inner.inner.dial(addr)
|
2018-05-18 14:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn nat_traversal(&self, server: &Multiaddr, observed: &Multiaddr) -> Option<Multiaddr> {
|
2018-05-23 11:22:49 +02:00
|
|
|
self.inner.inner.nat_traversal(server, observed)
|
2018-05-18 14:56:11 +02:00
|
|
|
}
|
|
|
|
}
|
2018-08-15 17:19:19 +02:00
|
|
|
|
|
|
|
/// The `multiaddr!` macro is an easy way for a user to create a `Multiaddr`.
|
|
|
|
///
|
|
|
|
/// Example:
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// # #[macro_use]
|
|
|
|
/// # extern crate libp2p;
|
|
|
|
/// # fn main() {
|
2018-09-20 19:51:00 +02:00
|
|
|
/// let _addr = multiaddr![Ip4([127, 0, 0, 1]), Tcp(10500u16)];
|
2018-08-15 17:19:19 +02:00
|
|
|
/// # }
|
|
|
|
/// ```
|
|
|
|
///
|
2018-09-20 19:51:00 +02:00
|
|
|
/// Each element passed to `multiaddr![]` should be a variant of the `Protocol` enum. The
|
2018-08-15 17:19:19 +02:00
|
|
|
/// optional parameter is casted into the proper type with the `Into` trait.
|
|
|
|
///
|
2018-09-20 19:51:00 +02:00
|
|
|
/// For example, `Ip4([127, 0, 0, 1])` works because `Ipv4Addr` implements `From<[u8; 4]>`.
|
2018-08-15 17:19:19 +02:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! multiaddr {
|
|
|
|
($($comp:ident $(($param:expr))*),+) => {
|
|
|
|
{
|
|
|
|
use std::iter;
|
2018-09-20 19:51:00 +02:00
|
|
|
let elem = iter::empty::<$crate::multiaddr::Protocol>();
|
2018-08-15 17:19:19 +02:00
|
|
|
$(
|
|
|
|
let elem = {
|
2018-09-20 19:51:00 +02:00
|
|
|
let cmp = $crate::multiaddr::Protocol::$comp $(( $param.into() ))*;
|
2018-08-15 17:19:19 +02:00
|
|
|
elem.chain(iter::once(cmp))
|
|
|
|
};
|
|
|
|
)+
|
|
|
|
elem.collect::<$crate::Multiaddr>()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|