Trait libp2p_swarm_test::SwarmExt
source · pub trait SwarmExt {
type NB: NetworkBehaviour;
// Required methods
fn new_ephemeral(behaviour_fn: impl FnOnce(Keypair) -> Self::NB) -> Self
where Self: Sized;
fn connect<'life0, 'life1, 'async_trait, T>(
&'life0 mut self,
other: &'life1 mut Swarm<T>
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where T: NetworkBehaviour + Send + 'async_trait,
<T as NetworkBehaviour>::ToSwarm: Debug,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn dial_and_wait<'life0, 'async_trait>(
&'life0 mut self,
addr: Multiaddr
) -> Pin<Box<dyn Future<Output = PeerId> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn wait<'life0, 'async_trait, E, P>(
&'life0 mut self,
predicate: P
) -> Pin<Box<dyn Future<Output = E> + Send + 'async_trait>>
where P: Fn(SwarmEvent<<Self::NB as NetworkBehaviour>::ToSwarm>) -> Option<E> + Send + 'async_trait,
E: 'async_trait,
Self: 'async_trait,
'life0: 'async_trait;
fn listen(&mut self) -> ListenFuture<&mut Self>;
fn next_swarm_event<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = SwarmEvent<<Self::NB as NetworkBehaviour>::ToSwarm>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn next_behaviour_event<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = <Self::NB as NetworkBehaviour>::ToSwarm> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn loop_on_next<'async_trait>(
self
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait;
}
Expand description
Required Associated Types§
type NB: NetworkBehaviour
Required Methods§
sourcefn new_ephemeral(behaviour_fn: impl FnOnce(Keypair) -> Self::NB) -> Selfwhere
Self: Sized,
fn new_ephemeral(behaviour_fn: impl FnOnce(Keypair) -> Self::NB) -> Selfwhere
Self: Sized,
Create a new Swarm
with an ephemeral identity.
The swarm will use a MemoryTransport
together with a plaintext::Config
authentication layer and
yamux::Config
as the multiplexer. However, these details should not be relied upon by the test
and may change at any time.
sourcefn connect<'life0, 'life1, 'async_trait, T>(
&'life0 mut self,
other: &'life1 mut Swarm<T>
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
T: NetworkBehaviour + Send + 'async_trait,
<T as NetworkBehaviour>::ToSwarm: Debug,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn connect<'life0, 'life1, 'async_trait, T>(
&'life0 mut self,
other: &'life1 mut Swarm<T>
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
T: NetworkBehaviour + Send + 'async_trait,
<T as NetworkBehaviour>::ToSwarm: Debug,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Establishes a connection to the given Swarm
, polling both of them until the connection is established.
This will take addresses from the other
Swarm
via Swarm::external_addresses
.
By default, this iterator will not yield any addresses.
To add listen addresses as external addresses, use ListenFuture::with_memory_addr_external
or ListenFuture::with_tcp_addr_external
.
sourcefn dial_and_wait<'life0, 'async_trait>(
&'life0 mut self,
addr: Multiaddr
) -> Pin<Box<dyn Future<Output = PeerId> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn dial_and_wait<'life0, 'async_trait>(
&'life0 mut self,
addr: Multiaddr
) -> Pin<Box<dyn Future<Output = PeerId> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Dial the provided address and wait until a connection has been established.
In a normal test scenario, you should prefer SwarmExt::connect
but that is not always possible.
This function only abstracts away the “dial and wait for ConnectionEstablished
event” part.
Because we don’t have access to the other Swarm
, we can’t guarantee that it makes progress.
sourcefn wait<'life0, 'async_trait, E, P>(
&'life0 mut self,
predicate: P
) -> Pin<Box<dyn Future<Output = E> + Send + 'async_trait>>where
P: Fn(SwarmEvent<<Self::NB as NetworkBehaviour>::ToSwarm>) -> Option<E> + Send + 'async_trait,
E: 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
fn wait<'life0, 'async_trait, E, P>(
&'life0 mut self,
predicate: P
) -> Pin<Box<dyn Future<Output = E> + Send + 'async_trait>>where
P: Fn(SwarmEvent<<Self::NB as NetworkBehaviour>::ToSwarm>) -> Option<E> + Send + 'async_trait,
E: 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
Wait for specified condition to return Some
.
sourcefn listen(&mut self) -> ListenFuture<&mut Self>
fn listen(&mut self) -> ListenFuture<&mut Self>
Listens for incoming connections, polling the Swarm
until the transport is ready to accept connections.
The first address is for the memory transport, the second one for the TCP transport.
sourcefn next_swarm_event<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = SwarmEvent<<Self::NB as NetworkBehaviour>::ToSwarm>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn next_swarm_event<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = SwarmEvent<<Self::NB as NetworkBehaviour>::ToSwarm>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Returns the next SwarmEvent
or times out after 10 seconds.
If the 10s timeout does not fit your usecase, please fall back to StreamExt::next
.
sourcefn next_behaviour_event<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = <Self::NB as NetworkBehaviour>::ToSwarm> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn next_behaviour_event<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = <Self::NB as NetworkBehaviour>::ToSwarm> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Returns the next behaviour event or times out after 10 seconds.
If the 10s timeout does not fit your usecase, please fall back to StreamExt::next
.