mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-28 17:21:34 +00:00
swarm/: Enable advanced dialing requests (#2317)
Enable advanced dialing requests both on `Swarm` and via `NetworkBehaviourAction`. Users can now trigger a dial with a specific set of addresses, optionally extended via `NetworkBehaviour::addresses_of_peer`. In addition the whole process is now modelled in a type safe way via the builder pattern. Example of a `NetworkBehaviour` requesting a dial to a specific peer with a set of addresses additionally extended through `NetworkBehaviour::addresses_of_peer`: ```rust NetworkBehaviourAction::Dial { opts: DialOpts::peer_id(peer_id) .condition(PeerCondition::Always) .addresses(addresses) .extend_addresses_through_behaviour() .build(), handler, } ``` Example of a user requesting a dial to an unknown peer with a single address via `Swarm`: ```rust swarm1.dial( DialOpts::unknown_peer_id() .address(addr2.clone()) .build() ) ```
This commit is contained in:
@ -26,7 +26,7 @@
|
||||
//! ```rust
|
||||
//! # use libp2p_core::transport::memory::MemoryTransport;
|
||||
//! # use libp2p_relay::{RelayConfig, new_transport_and_behaviour};
|
||||
//! # use libp2p_swarm::Swarm;
|
||||
//! # use libp2p_swarm::{Swarm, dial_opts::DialOpts};
|
||||
//! # use libp2p_core::{identity, Multiaddr, multiaddr::Protocol, PeerId, upgrade, Transport};
|
||||
//! # use libp2p_yamux::YamuxConfig;
|
||||
//! # use libp2p_plaintext::PlainText2Config;
|
||||
@ -62,7 +62,7 @@
|
||||
//! swarm.listen_on(relay_addr).unwrap();
|
||||
//!
|
||||
//! // Dial node (5678) via relay node (1234).
|
||||
//! swarm.dial_addr(dst_addr).unwrap();
|
||||
//! swarm.dial(dst_addr).unwrap();
|
||||
//! ```
|
||||
//!
|
||||
//! ## Terminology
|
||||
|
Reference in New Issue
Block a user