Struct libp2p::SwarmBuilder
source · pub struct SwarmBuilder<Provider, Phase> { /* private fields */ }
Expand description
Build a Swarm
by combining an identity, a set of
Transport
s and a
NetworkBehaviour
.
let swarm = SwarmBuilder::with_new_identity()
.with_tokio()
.with_tcp(
Default::default(),
(libp2p_tls::Config::new, libp2p_noise::Config::new),
libp2p_yamux::Config::default,
)?
.with_quic()
.with_other_transport(|_key| DummyTransport::<(PeerId, StreamMuxerBox)>::new())?
.with_dns()?
.with_websocket(
(libp2p_tls::Config::new, libp2p_noise::Config::new),
libp2p_yamux::Config::default,
)
.await?
.with_relay_client(
(libp2p_tls::Config::new, libp2p_noise::Config::new),
libp2p_yamux::Config::default,
)?
.with_behaviour(|_key, relay| MyBehaviour { relay })?
.build();
Implementations§
source§impl<T: AuthenticatedMultiplexedTransport, Provider, R> SwarmBuilder<Provider, BandwidthLoggingPhase<T, R>>
impl<T: AuthenticatedMultiplexedTransport, Provider, R> SwarmBuilder<Provider, BandwidthLoggingPhase<T, R>>
pub fn with_bandwidth_logging( self, ) -> (SwarmBuilder<Provider, BehaviourPhase<impl AuthenticatedMultiplexedTransport, R>>, Arc<BandwidthSinks>)
pub fn without_bandwidth_logging( self, ) -> SwarmBuilder<Provider, BehaviourPhase<T, R>>
source§impl<Provider, T: AuthenticatedMultiplexedTransport> SwarmBuilder<Provider, BandwidthLoggingPhase<T, NoRelayBehaviour>>
impl<Provider, T: AuthenticatedMultiplexedTransport> SwarmBuilder<Provider, BandwidthLoggingPhase<T, NoRelayBehaviour>>
pub fn with_behaviour<B, R: TryIntoBehaviour<B>>( self, constructor: impl FnOnce(&Keypair) -> R, ) -> Result<SwarmBuilder<Provider, SwarmPhase<T, B>>, R::Error>
source§impl<T, Provider> SwarmBuilder<Provider, BehaviourPhase<T, NoRelayBehaviour>>
impl<T, Provider> SwarmBuilder<Provider, BehaviourPhase<T, NoRelayBehaviour>>
pub fn with_behaviour<B, R: TryIntoBehaviour<B>>( self, constructor: impl FnOnce(&Keypair) -> R, ) -> Result<SwarmBuilder<Provider, SwarmPhase<T, B>>, R::Error>
source§impl<Provider, T: AuthenticatedMultiplexedTransport, B: NetworkBehaviour> SwarmBuilder<Provider, BuildPhase<T, B>>
impl<Provider, T: AuthenticatedMultiplexedTransport, B: NetworkBehaviour> SwarmBuilder<Provider, BuildPhase<T, B>>
source§impl<T: AuthenticatedMultiplexedTransport> SwarmBuilder<Tokio, DnsPhase<T>>
impl<T: AuthenticatedMultiplexedTransport> SwarmBuilder<Tokio, DnsPhase<T>>
pub fn with_dns( self, ) -> Result<SwarmBuilder<Tokio, WebsocketPhase<impl AuthenticatedMultiplexedTransport>>, Error>
Available on non-WebAssembly and crate feature
tokio
and crate feature dns
only.source§impl<Provider, T: AuthenticatedMultiplexedTransport> SwarmBuilder<Provider, DnsPhase<T>>
impl<Provider, T: AuthenticatedMultiplexedTransport> SwarmBuilder<Provider, DnsPhase<T>>
pub fn with_behaviour<B, R: TryIntoBehaviour<B>>( self, constructor: impl FnOnce(&Keypair) -> R, ) -> Result<SwarmBuilder<Provider, SwarmPhase<T, B>>, R::Error>
source§impl SwarmBuilder<NoProviderSpecified, IdentityPhase>
impl SwarmBuilder<NoProviderSpecified, IdentityPhase>
pub fn with_new_identity() -> SwarmBuilder<NoProviderSpecified, ProviderPhase>
pub fn with_existing_identity( keypair: Keypair, ) -> SwarmBuilder<NoProviderSpecified, ProviderPhase>
source§impl<Provider, T: AuthenticatedMultiplexedTransport> SwarmBuilder<Provider, OtherTransportPhase<T>>
impl<Provider, T: AuthenticatedMultiplexedTransport> SwarmBuilder<Provider, OtherTransportPhase<T>>
pub fn with_other_transport<Muxer: StreamMuxer + Send + 'static, OtherTransport: Transport<Output = (PeerId, Muxer)> + Send + Unpin + 'static, R: TryIntoTransport<OtherTransport>>( self, constructor: impl FnOnce(&Keypair) -> R, ) -> Result<SwarmBuilder<Provider, OtherTransportPhase<impl AuthenticatedMultiplexedTransport>>, R::Error>
source§impl<T: AuthenticatedMultiplexedTransport> SwarmBuilder<Tokio, OtherTransportPhase<T>>
impl<T: AuthenticatedMultiplexedTransport> SwarmBuilder<Tokio, OtherTransportPhase<T>>
pub fn with_dns( self, ) -> Result<SwarmBuilder<Tokio, WebsocketPhase<impl AuthenticatedMultiplexedTransport>>, Error>
Available on non-WebAssembly and crate feature
tokio
and crate feature dns
only.source§impl<Provider, T: AuthenticatedMultiplexedTransport> SwarmBuilder<Provider, OtherTransportPhase<T>>
impl<Provider, T: AuthenticatedMultiplexedTransport> SwarmBuilder<Provider, OtherTransportPhase<T>>
pub fn with_bandwidth_logging( self, ) -> (SwarmBuilder<Provider, BehaviourPhase<impl AuthenticatedMultiplexedTransport, NoRelayBehaviour>>, Arc<BandwidthSinks>)
source§impl<Provider, T: AuthenticatedMultiplexedTransport> SwarmBuilder<Provider, OtherTransportPhase<T>>
impl<Provider, T: AuthenticatedMultiplexedTransport> SwarmBuilder<Provider, OtherTransportPhase<T>>
pub fn with_behaviour<B, R: TryIntoBehaviour<B>>( self, constructor: impl FnOnce(&Keypair) -> R, ) -> Result<SwarmBuilder<Provider, SwarmPhase<T, B>>, R::Error>
source§impl SwarmBuilder<NoProviderSpecified, ProviderPhase>
impl SwarmBuilder<NoProviderSpecified, ProviderPhase>
pub fn with_tokio(self) -> SwarmBuilder<Tokio, TcpPhase>
Available on non-WebAssembly and crate feature
tokio
only.source§impl<Provider, T: AuthenticatedMultiplexedTransport> SwarmBuilder<Provider, QuicPhase<T>>
impl<Provider, T: AuthenticatedMultiplexedTransport> SwarmBuilder<Provider, QuicPhase<T>>
pub fn with_other_transport<Muxer: StreamMuxer + Send + 'static, OtherTransport: Transport<Output = (PeerId, Muxer)> + Send + Unpin + 'static, R: TryIntoTransport<OtherTransport>>( self, constructor: impl FnOnce(&Keypair) -> R, ) -> Result<SwarmBuilder<Provider, OtherTransportPhase<impl AuthenticatedMultiplexedTransport>>, R::Error>
pub fn with_behaviour<B, R: TryIntoBehaviour<B>>( self, constructor: impl FnOnce(&Keypair) -> R, ) -> Result<SwarmBuilder<Provider, SwarmPhase<T, B>>, R::Error>
source§impl<T: AuthenticatedMultiplexedTransport> SwarmBuilder<Tokio, QuicPhase<T>>
impl<T: AuthenticatedMultiplexedTransport> SwarmBuilder<Tokio, QuicPhase<T>>
pub fn with_dns( self, ) -> Result<SwarmBuilder<Tokio, WebsocketPhase<impl AuthenticatedMultiplexedTransport>>, Error>
Available on non-WebAssembly and crate feature
tokio
and crate feature dns
only.source§impl<T: AuthenticatedMultiplexedTransport> SwarmBuilder<Tokio, QuicPhase<T>>
impl<T: AuthenticatedMultiplexedTransport> SwarmBuilder<Tokio, QuicPhase<T>>
sourcepub async fn with_websocket<SecUpgrade, SecStream, SecError, MuxUpgrade, MuxStream, MuxError>(
self,
security_upgrade: SecUpgrade,
multiplexer_upgrade: MuxUpgrade,
) -> Result<SwarmBuilder<Tokio, RelayPhase<impl AuthenticatedMultiplexedTransport>>, WebsocketError<SecUpgrade::Error>>where
SecStream: AsyncRead + AsyncWrite + Unpin + Send + 'static,
SecError: Error + Send + Sync + 'static,
SecUpgrade: IntoSecurityUpgrade<RwStreamSink<BytesConnection<TcpStream>>>,
SecUpgrade::Upgrade: InboundUpgrade<Negotiated<RwStreamSink<BytesConnection<TcpStream>>>, Output = (PeerId, SecStream), Error = SecError> + OutboundUpgrade<Negotiated<RwStreamSink<BytesConnection<TcpStream>>>, Output = (PeerId, SecStream), Error = SecError> + Clone + Send + 'static,
<SecUpgrade::Upgrade as InboundUpgrade<Negotiated<RwStreamSink<BytesConnection<TcpStream>>>>>::Future: Send,
<SecUpgrade::Upgrade as OutboundUpgrade<Negotiated<RwStreamSink<BytesConnection<TcpStream>>>>>::Future: Send,
<<<SecUpgrade as IntoSecurityUpgrade<RwStreamSink<BytesConnection<TcpStream>>>>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send,
<<SecUpgrade as IntoSecurityUpgrade<RwStreamSink<BytesConnection<TcpStream>>>>::Upgrade as UpgradeInfo>::Info: Send,
MuxStream: StreamMuxer + Send + 'static,
MuxStream::Substream: Send + 'static,
MuxStream::Error: Send + Sync + 'static,
MuxUpgrade: IntoMultiplexerUpgrade<SecStream>,
MuxUpgrade::Upgrade: InboundUpgrade<Negotiated<SecStream>, Output = MuxStream, Error = MuxError> + OutboundUpgrade<Negotiated<SecStream>, Output = MuxStream, Error = MuxError> + Clone + Send + 'static,
<MuxUpgrade::Upgrade as InboundUpgrade<Negotiated<SecStream>>>::Future: Send,
<MuxUpgrade::Upgrade as OutboundUpgrade<Negotiated<SecStream>>>::Future: Send,
MuxError: Error + Send + Sync + 'static,
<<<MuxUpgrade as IntoMultiplexerUpgrade<SecStream>>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send,
<<MuxUpgrade as IntoMultiplexerUpgrade<SecStream>>::Upgrade as UpgradeInfo>::Info: Send,
Available on crate feature tokio
and non-WebAssembly and crate feature websocket
only.
pub async fn with_websocket<SecUpgrade, SecStream, SecError, MuxUpgrade, MuxStream, MuxError>(
self,
security_upgrade: SecUpgrade,
multiplexer_upgrade: MuxUpgrade,
) -> Result<SwarmBuilder<Tokio, RelayPhase<impl AuthenticatedMultiplexedTransport>>, WebsocketError<SecUpgrade::Error>>where
SecStream: AsyncRead + AsyncWrite + Unpin + Send + 'static,
SecError: Error + Send + Sync + 'static,
SecUpgrade: IntoSecurityUpgrade<RwStreamSink<BytesConnection<TcpStream>>>,
SecUpgrade::Upgrade: InboundUpgrade<Negotiated<RwStreamSink<BytesConnection<TcpStream>>>, Output = (PeerId, SecStream), Error = SecError> + OutboundUpgrade<Negotiated<RwStreamSink<BytesConnection<TcpStream>>>, Output = (PeerId, SecStream), Error = SecError> + Clone + Send + 'static,
<SecUpgrade::Upgrade as InboundUpgrade<Negotiated<RwStreamSink<BytesConnection<TcpStream>>>>>::Future: Send,
<SecUpgrade::Upgrade as OutboundUpgrade<Negotiated<RwStreamSink<BytesConnection<TcpStream>>>>>::Future: Send,
<<<SecUpgrade as IntoSecurityUpgrade<RwStreamSink<BytesConnection<TcpStream>>>>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send,
<<SecUpgrade as IntoSecurityUpgrade<RwStreamSink<BytesConnection<TcpStream>>>>::Upgrade as UpgradeInfo>::Info: Send,
MuxStream: StreamMuxer + Send + 'static,
MuxStream::Substream: Send + 'static,
MuxStream::Error: Send + Sync + 'static,
MuxUpgrade: IntoMultiplexerUpgrade<SecStream>,
MuxUpgrade::Upgrade: InboundUpgrade<Negotiated<SecStream>, Output = MuxStream, Error = MuxError> + OutboundUpgrade<Negotiated<SecStream>, Output = MuxStream, Error = MuxError> + Clone + Send + 'static,
<MuxUpgrade::Upgrade as InboundUpgrade<Negotiated<SecStream>>>::Future: Send,
<MuxUpgrade::Upgrade as OutboundUpgrade<Negotiated<SecStream>>>::Future: Send,
MuxError: Error + Send + Sync + 'static,
<<<MuxUpgrade as IntoMultiplexerUpgrade<SecStream>>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send,
<<MuxUpgrade as IntoMultiplexerUpgrade<SecStream>>::Upgrade as UpgradeInfo>::Info: Send,
tokio
and non-WebAssembly and crate feature websocket
only.source§impl<Provider, T: AuthenticatedMultiplexedTransport> SwarmBuilder<Provider, QuicPhase<T>>
impl<Provider, T: AuthenticatedMultiplexedTransport> SwarmBuilder<Provider, QuicPhase<T>>
pub fn with_bandwidth_logging( self, ) -> (SwarmBuilder<Provider, BehaviourPhase<impl AuthenticatedMultiplexedTransport, NoRelayBehaviour>>, Arc<BandwidthSinks>)
source§impl<Provider, T: AuthenticatedMultiplexedTransport> SwarmBuilder<Provider, RelayPhase<T>>
impl<Provider, T: AuthenticatedMultiplexedTransport> SwarmBuilder<Provider, RelayPhase<T>>
pub fn with_behaviour<B, R: TryIntoBehaviour<B>>( self, constructor: impl FnOnce(&Keypair) -> R, ) -> Result<SwarmBuilder<Provider, SwarmPhase<T, B>>, R::Error>
source§impl<T, B> SwarmBuilder<Tokio, SwarmPhase<T, B>>
impl<T, B> SwarmBuilder<Tokio, SwarmPhase<T, B>>
pub fn with_swarm_config( self, constructor: impl FnOnce(Config) -> Config, ) -> SwarmBuilder<Tokio, BuildPhase<T, B>>
Available on crate feature
tokio
only.pub fn build(self) -> Swarm<B>where
B: NetworkBehaviour,
T: AuthenticatedMultiplexedTransport,
Available on crate feature
tokio
only.source§impl SwarmBuilder<Tokio, TcpPhase>
impl SwarmBuilder<Tokio, TcpPhase>
sourcepub fn with_tcp<SecUpgrade, SecStream, SecError, MuxUpgrade, MuxStream, MuxError>(
self,
tcp_config: Config,
security_upgrade: SecUpgrade,
multiplexer_upgrade: MuxUpgrade,
) -> Result<SwarmBuilder<Tokio, QuicPhase<impl AuthenticatedMultiplexedTransport>>, SecUpgrade::Error>where
SecStream: AsyncRead + AsyncWrite + Unpin + Send + 'static,
SecError: Error + Send + Sync + 'static,
SecUpgrade: IntoSecurityUpgrade<TcpStream>,
SecUpgrade::Upgrade: InboundUpgrade<Negotiated<TcpStream>, Output = (PeerId, SecStream), Error = SecError> + OutboundUpgrade<Negotiated<TcpStream>, Output = (PeerId, SecStream), Error = SecError> + Clone + Send + 'static,
<SecUpgrade::Upgrade as InboundUpgrade<Negotiated<TcpStream>>>::Future: Send,
<SecUpgrade::Upgrade as OutboundUpgrade<Negotiated<TcpStream>>>::Future: Send,
<<<SecUpgrade as IntoSecurityUpgrade<TcpStream>>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send,
<<SecUpgrade as IntoSecurityUpgrade<TcpStream>>::Upgrade as UpgradeInfo>::Info: Send,
MuxStream: StreamMuxer + Send + 'static,
MuxStream::Substream: Send + 'static,
MuxStream::Error: Send + Sync + 'static,
MuxUpgrade: IntoMultiplexerUpgrade<SecStream>,
MuxUpgrade::Upgrade: InboundUpgrade<Negotiated<SecStream>, Output = MuxStream, Error = MuxError> + OutboundUpgrade<Negotiated<SecStream>, Output = MuxStream, Error = MuxError> + Clone + Send + 'static,
<MuxUpgrade::Upgrade as InboundUpgrade<Negotiated<SecStream>>>::Future: Send,
<MuxUpgrade::Upgrade as OutboundUpgrade<Negotiated<SecStream>>>::Future: Send,
MuxError: Error + Send + Sync + 'static,
<<<MuxUpgrade as IntoMultiplexerUpgrade<SecStream>>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send,
<<MuxUpgrade as IntoMultiplexerUpgrade<SecStream>>::Upgrade as UpgradeInfo>::Info: Send,
Available on non-WebAssembly and crate feature tcp
and crate feature tokio
only.
pub fn with_tcp<SecUpgrade, SecStream, SecError, MuxUpgrade, MuxStream, MuxError>(
self,
tcp_config: Config,
security_upgrade: SecUpgrade,
multiplexer_upgrade: MuxUpgrade,
) -> Result<SwarmBuilder<Tokio, QuicPhase<impl AuthenticatedMultiplexedTransport>>, SecUpgrade::Error>where
SecStream: AsyncRead + AsyncWrite + Unpin + Send + 'static,
SecError: Error + Send + Sync + 'static,
SecUpgrade: IntoSecurityUpgrade<TcpStream>,
SecUpgrade::Upgrade: InboundUpgrade<Negotiated<TcpStream>, Output = (PeerId, SecStream), Error = SecError> + OutboundUpgrade<Negotiated<TcpStream>, Output = (PeerId, SecStream), Error = SecError> + Clone + Send + 'static,
<SecUpgrade::Upgrade as InboundUpgrade<Negotiated<TcpStream>>>::Future: Send,
<SecUpgrade::Upgrade as OutboundUpgrade<Negotiated<TcpStream>>>::Future: Send,
<<<SecUpgrade as IntoSecurityUpgrade<TcpStream>>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send,
<<SecUpgrade as IntoSecurityUpgrade<TcpStream>>::Upgrade as UpgradeInfo>::Info: Send,
MuxStream: StreamMuxer + Send + 'static,
MuxStream::Substream: Send + 'static,
MuxStream::Error: Send + Sync + 'static,
MuxUpgrade: IntoMultiplexerUpgrade<SecStream>,
MuxUpgrade::Upgrade: InboundUpgrade<Negotiated<SecStream>, Output = MuxStream, Error = MuxError> + OutboundUpgrade<Negotiated<SecStream>, Output = MuxStream, Error = MuxError> + Clone + Send + 'static,
<MuxUpgrade::Upgrade as InboundUpgrade<Negotiated<SecStream>>>::Future: Send,
<MuxUpgrade::Upgrade as OutboundUpgrade<Negotiated<SecStream>>>::Future: Send,
MuxError: Error + Send + Sync + 'static,
<<<MuxUpgrade as IntoMultiplexerUpgrade<SecStream>>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send,
<<MuxUpgrade as IntoMultiplexerUpgrade<SecStream>>::Upgrade as UpgradeInfo>::Info: Send,
tcp
and crate feature tokio
only.Adds a TCP based transport.
Note that both security_upgrade
and multiplexer_upgrade
take function pointers,
i.e. they take the function themselves (without the invocation via ()
), not the
result of the function invocation. See example below.
let swarm = SwarmBuilder::with_new_identity()
.with_tokio()
.with_tcp(
Default::default(),
(libp2p_tls::Config::new, libp2p_noise::Config::new),
libp2p_yamux::Config::default,
)?
source§impl<Provider> SwarmBuilder<Provider, TcpPhase>
impl<Provider> SwarmBuilder<Provider, TcpPhase>
pub fn with_other_transport<Muxer: StreamMuxer + Send + 'static, OtherTransport: Transport<Output = (PeerId, Muxer)> + Send + Unpin + 'static, R: TryIntoTransport<OtherTransport>>( self, constructor: impl FnOnce(&Keypair) -> R, ) -> Result<SwarmBuilder<Provider, OtherTransportPhase<impl AuthenticatedMultiplexedTransport>>, R::Error>
source§impl SwarmBuilder<Tokio, TcpPhase>
impl SwarmBuilder<Tokio, TcpPhase>
sourcepub async fn with_websocket<SecUpgrade, SecStream, SecError, MuxUpgrade, MuxStream, MuxError>(
self,
security_upgrade: SecUpgrade,
multiplexer_upgrade: MuxUpgrade,
) -> Result<SwarmBuilder<Tokio, RelayPhase<impl AuthenticatedMultiplexedTransport>>, WebsocketError<SecUpgrade::Error>>where
SecStream: AsyncRead + AsyncWrite + Unpin + Send + 'static,
SecError: Error + Send + Sync + 'static,
SecUpgrade: IntoSecurityUpgrade<RwStreamSink<BytesConnection<TcpStream>>>,
SecUpgrade::Upgrade: InboundUpgrade<Negotiated<RwStreamSink<BytesConnection<TcpStream>>>, Output = (PeerId, SecStream), Error = SecError> + OutboundUpgrade<Negotiated<RwStreamSink<BytesConnection<TcpStream>>>, Output = (PeerId, SecStream), Error = SecError> + Clone + Send + 'static,
<SecUpgrade::Upgrade as InboundUpgrade<Negotiated<RwStreamSink<BytesConnection<TcpStream>>>>>::Future: Send,
<SecUpgrade::Upgrade as OutboundUpgrade<Negotiated<RwStreamSink<BytesConnection<TcpStream>>>>>::Future: Send,
<<<SecUpgrade as IntoSecurityUpgrade<RwStreamSink<BytesConnection<TcpStream>>>>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send,
<<SecUpgrade as IntoSecurityUpgrade<RwStreamSink<BytesConnection<TcpStream>>>>::Upgrade as UpgradeInfo>::Info: Send,
MuxStream: StreamMuxer + Send + 'static,
MuxStream::Substream: Send + 'static,
MuxStream::Error: Send + Sync + 'static,
MuxUpgrade: IntoMultiplexerUpgrade<SecStream>,
MuxUpgrade::Upgrade: InboundUpgrade<Negotiated<SecStream>, Output = MuxStream, Error = MuxError> + OutboundUpgrade<Negotiated<SecStream>, Output = MuxStream, Error = MuxError> + Clone + Send + 'static,
<MuxUpgrade::Upgrade as InboundUpgrade<Negotiated<SecStream>>>::Future: Send,
<MuxUpgrade::Upgrade as OutboundUpgrade<Negotiated<SecStream>>>::Future: Send,
MuxError: Error + Send + Sync + 'static,
<<<MuxUpgrade as IntoMultiplexerUpgrade<SecStream>>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send,
<<MuxUpgrade as IntoMultiplexerUpgrade<SecStream>>::Upgrade as UpgradeInfo>::Info: Send,
Available on crate feature tokio
and non-WebAssembly and crate feature websocket
only.
pub async fn with_websocket<SecUpgrade, SecStream, SecError, MuxUpgrade, MuxStream, MuxError>(
self,
security_upgrade: SecUpgrade,
multiplexer_upgrade: MuxUpgrade,
) -> Result<SwarmBuilder<Tokio, RelayPhase<impl AuthenticatedMultiplexedTransport>>, WebsocketError<SecUpgrade::Error>>where
SecStream: AsyncRead + AsyncWrite + Unpin + Send + 'static,
SecError: Error + Send + Sync + 'static,
SecUpgrade: IntoSecurityUpgrade<RwStreamSink<BytesConnection<TcpStream>>>,
SecUpgrade::Upgrade: InboundUpgrade<Negotiated<RwStreamSink<BytesConnection<TcpStream>>>, Output = (PeerId, SecStream), Error = SecError> + OutboundUpgrade<Negotiated<RwStreamSink<BytesConnection<TcpStream>>>, Output = (PeerId, SecStream), Error = SecError> + Clone + Send + 'static,
<SecUpgrade::Upgrade as InboundUpgrade<Negotiated<RwStreamSink<BytesConnection<TcpStream>>>>>::Future: Send,
<SecUpgrade::Upgrade as OutboundUpgrade<Negotiated<RwStreamSink<BytesConnection<TcpStream>>>>>::Future: Send,
<<<SecUpgrade as IntoSecurityUpgrade<RwStreamSink<BytesConnection<TcpStream>>>>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send,
<<SecUpgrade as IntoSecurityUpgrade<RwStreamSink<BytesConnection<TcpStream>>>>::Upgrade as UpgradeInfo>::Info: Send,
MuxStream: StreamMuxer + Send + 'static,
MuxStream::Substream: Send + 'static,
MuxStream::Error: Send + Sync + 'static,
MuxUpgrade: IntoMultiplexerUpgrade<SecStream>,
MuxUpgrade::Upgrade: InboundUpgrade<Negotiated<SecStream>, Output = MuxStream, Error = MuxError> + OutboundUpgrade<Negotiated<SecStream>, Output = MuxStream, Error = MuxError> + Clone + Send + 'static,
<MuxUpgrade::Upgrade as InboundUpgrade<Negotiated<SecStream>>>::Future: Send,
<MuxUpgrade::Upgrade as OutboundUpgrade<Negotiated<SecStream>>>::Future: Send,
MuxError: Error + Send + Sync + 'static,
<<<MuxUpgrade as IntoMultiplexerUpgrade<SecStream>>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send,
<<MuxUpgrade as IntoMultiplexerUpgrade<SecStream>>::Upgrade as UpgradeInfo>::Info: Send,
tokio
and non-WebAssembly and crate feature websocket
only.source§impl<T> SwarmBuilder<Tokio, WebsocketPhase<T>>
impl<T> SwarmBuilder<Tokio, WebsocketPhase<T>>
Adds a websocket client transport.
Note that both security_upgrade
and multiplexer_upgrade
take function pointers,
i.e. they take the function themselves (without the invocation via ()
), not the
result of the function invocation. See example below.
let swarm = SwarmBuilder::with_new_identity()
.with_tokio()
.with_websocket(
(libp2p_tls::Config::new, libp2p_noise::Config::new),
libp2p_yamux::Config::default,
)
.await?
pub async fn with_websocket<SecUpgrade, SecStream, SecError, MuxUpgrade, MuxStream, MuxError>(
self,
security_upgrade: SecUpgrade,
multiplexer_upgrade: MuxUpgrade,
) -> Result<SwarmBuilder<Tokio, RelayPhase<impl AuthenticatedMultiplexedTransport>>, WebsocketError<SecUpgrade::Error>>where
T: AuthenticatedMultiplexedTransport,
SecStream: AsyncRead + AsyncWrite + Unpin + Send + 'static,
SecError: Error + Send + Sync + 'static,
SecUpgrade: IntoSecurityUpgrade<RwStreamSink<BytesConnection<TcpStream>>>,
SecUpgrade::Upgrade: InboundUpgrade<Negotiated<RwStreamSink<BytesConnection<TcpStream>>>, Output = (PeerId, SecStream), Error = SecError> + OutboundUpgrade<Negotiated<RwStreamSink<BytesConnection<TcpStream>>>, Output = (PeerId, SecStream), Error = SecError> + Clone + Send + 'static,
<SecUpgrade::Upgrade as InboundUpgrade<Negotiated<RwStreamSink<BytesConnection<TcpStream>>>>>::Future: Send,
<SecUpgrade::Upgrade as OutboundUpgrade<Negotiated<RwStreamSink<BytesConnection<TcpStream>>>>>::Future: Send,
<<<SecUpgrade as IntoSecurityUpgrade<RwStreamSink<BytesConnection<TcpStream>>>>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send,
<<SecUpgrade as IntoSecurityUpgrade<RwStreamSink<BytesConnection<TcpStream>>>>::Upgrade as UpgradeInfo>::Info: Send,
MuxStream: StreamMuxer + Send + 'static,
MuxStream::Substream: Send + 'static,
MuxStream::Error: Send + Sync + 'static,
MuxUpgrade: IntoMultiplexerUpgrade<SecStream>,
MuxUpgrade::Upgrade: InboundUpgrade<Negotiated<SecStream>, Output = MuxStream, Error = MuxError> + OutboundUpgrade<Negotiated<SecStream>, Output = MuxStream, Error = MuxError> + Clone + Send + 'static,
<MuxUpgrade::Upgrade as InboundUpgrade<Negotiated<SecStream>>>::Future: Send,
<MuxUpgrade::Upgrade as OutboundUpgrade<Negotiated<SecStream>>>::Future: Send,
MuxError: Error + Send + Sync + 'static,
<<<MuxUpgrade as IntoMultiplexerUpgrade<SecStream>>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send,
<<MuxUpgrade as IntoMultiplexerUpgrade<SecStream>>::Upgrade as UpgradeInfo>::Info: Send,
Available on non-WebAssembly and crate feature
tokio
and crate feature websocket
only.source§impl<Provider, T: AuthenticatedMultiplexedTransport> SwarmBuilder<Provider, WebsocketPhase<T>>
impl<Provider, T: AuthenticatedMultiplexedTransport> SwarmBuilder<Provider, WebsocketPhase<T>>
pub fn with_behaviour<B, R: TryIntoBehaviour<B>>( self, constructor: impl FnOnce(&Keypair) -> R, ) -> Result<SwarmBuilder<Provider, SwarmPhase<T, B>>, R::Error>
Auto Trait Implementations§
impl<Provider, Phase> Freeze for SwarmBuilder<Provider, Phase>where
Phase: Freeze,
impl<Provider, Phase> RefUnwindSafe for SwarmBuilder<Provider, Phase>where
Phase: RefUnwindSafe,
Provider: RefUnwindSafe,
impl<Provider, Phase> Send for SwarmBuilder<Provider, Phase>
impl<Provider, Phase> Sync for SwarmBuilder<Provider, Phase>
impl<Provider, Phase> Unpin for SwarmBuilder<Provider, Phase>
impl<Provider, Phase> UnwindSafe for SwarmBuilder<Provider, Phase>where
Phase: UnwindSafe,
Provider: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> FmtForward for T
impl<T> FmtForward for T
source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
Causes
self
to use its Binary
implementation when Debug
-formatted.source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
Causes
self
to use its Display
implementation when
Debug
-formatted.source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
Causes
self
to use its LowerExp
implementation when
Debug
-formatted.source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
Causes
self
to use its LowerHex
implementation when
Debug
-formatted.source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
Causes
self
to use its Octal
implementation when Debug
-formatted.source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
Causes
self
to use its Pointer
implementation when
Debug
-formatted.source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
Causes
self
to use its UpperExp
implementation when
Debug
-formatted.source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
Causes
self
to use its UpperHex
implementation when
Debug
-formatted.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Pipes by value. This is generally the method you want to use. Read more
source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
Borrows
self
and passes that borrow into the pipe function. Read moresource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
Mutably borrows
self
and passes that borrow into the pipe function. Read moresource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
Borrows
self
, then passes self.as_ref()
into the pipe function.source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
Mutably borrows
self
, then passes self.as_mut()
into the pipe
function.source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
Borrows
self
, then passes self.deref()
into the pipe function.source§impl<T> Tap for T
impl<T> Tap for T
source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Immutable access to the
Borrow<B>
of a value. Read moresource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
Mutable access to the
BorrowMut<B>
of a value. Read moresource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
Immutable access to the
AsRef<R>
view of a value. Read moresource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
Mutable access to the
AsMut<R>
view of a value. Read moresource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Immutable access to the
Deref::Target
of a value. Read moresource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Mutable access to the
Deref::Target
of a value. Read moresource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
Calls
.tap()
only in debug builds, and is erased in release builds.source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
Calls
.tap_mut()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
Calls
.tap_borrow()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
Calls
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
Calls
.tap_ref()
only in debug builds, and is erased in release
builds.source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
Calls
.tap_ref_mut()
only in debug builds, and is erased in release
builds.source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
Calls
.tap_deref()
only in debug builds, and is erased in release
builds.