mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-21 22:01:34 +00:00
feat(yamux): rename symbols to follow module-based naming convention
Implements our naming convention for the `libp2p-yamux` crate. Related: #2217. Pull-Request: #3852.
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -3078,7 +3078,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libp2p-yamux"
|
||||
version = "0.43.0"
|
||||
version = "0.43.1"
|
||||
dependencies = [
|
||||
"async-std",
|
||||
"futures",
|
||||
|
@ -65,7 +65,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
let transport = tcp::async_io::Transport::default()
|
||||
.upgrade(Version::V1Lazy)
|
||||
.authenticate(noise::Config::new(&local_key)?)
|
||||
.multiplex(yamux::YamuxConfig::default())
|
||||
.multiplex(yamux::Config::default())
|
||||
.boxed();
|
||||
|
||||
let behaviour = Behaviour::new(local_key.public());
|
||||
|
@ -54,7 +54,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
let transport = tcp::async_io::Transport::default()
|
||||
.upgrade(Version::V1Lazy)
|
||||
.authenticate(noise::Config::new(&local_key)?)
|
||||
.multiplex(yamux::YamuxConfig::default())
|
||||
.multiplex(yamux::Config::default())
|
||||
.boxed();
|
||||
|
||||
let behaviour = Behaviour::new(local_key.public());
|
||||
|
@ -78,7 +78,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
let tcp_transport = tcp::async_io::Transport::new(tcp::Config::default().nodelay(true))
|
||||
.upgrade(upgrade::Version::V1Lazy)
|
||||
.authenticate(noise::Config::new(&id_keys).expect("signing libp2p-noise static keypair"))
|
||||
.multiplex(yamux::YamuxConfig::default())
|
||||
.multiplex(yamux::Config::default())
|
||||
.timeout(std::time::Duration::from_secs(20))
|
||||
.boxed();
|
||||
let quic_transport = quic::async_std::Transport::new(quic::Config::new(&id_keys));
|
||||
|
@ -100,7 +100,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
.authenticate(
|
||||
noise::Config::new(&local_key).expect("Signing libp2p-noise static DH keypair failed."),
|
||||
)
|
||||
.multiplex(yamux::YamuxConfig::default())
|
||||
.multiplex(yamux::Config::default())
|
||||
.boxed();
|
||||
|
||||
#[derive(NetworkBehaviour)]
|
||||
|
@ -66,7 +66,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
let transport = tcp::async_io::Transport::default()
|
||||
.upgrade(Version::V1Lazy)
|
||||
.authenticate(noise::Config::new(&local_key)?)
|
||||
.multiplex(yamux::YamuxConfig::default())
|
||||
.multiplex(yamux::Config::default())
|
||||
.boxed();
|
||||
|
||||
// We create a custom network behaviour that combines Kademlia and mDNS.
|
||||
|
@ -50,7 +50,7 @@ pub(crate) async fn new(
|
||||
let transport = tcp::async_io::Transport::default()
|
||||
.upgrade(Version::V1Lazy)
|
||||
.authenticate(noise::Config::new(&id_keys)?)
|
||||
.multiplex(yamux::YamuxConfig::default())
|
||||
.multiplex(yamux::Config::default())
|
||||
.boxed();
|
||||
|
||||
// Build the Swarm, connecting the lower layer transport logic with the
|
||||
|
@ -54,7 +54,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
let transport = tcp::async_io::Transport::default()
|
||||
.upgrade(Version::V1Lazy)
|
||||
.authenticate(noise::Config::new(&local_key).unwrap())
|
||||
.multiplex(yamux::YamuxConfig::default())
|
||||
.multiplex(yamux::Config::default())
|
||||
.boxed();
|
||||
|
||||
// Create a identify network behaviour.
|
||||
|
@ -41,9 +41,7 @@ use libp2p::{
|
||||
noise, ping,
|
||||
pnet::{PnetConfig, PreSharedKey},
|
||||
swarm::{NetworkBehaviour, SwarmBuilder, SwarmEvent},
|
||||
tcp,
|
||||
yamux::YamuxConfig,
|
||||
Multiaddr, PeerId, Transport,
|
||||
tcp, yamux, Multiaddr, PeerId, Transport,
|
||||
};
|
||||
use std::{env, error::Error, fs, path::Path, str::FromStr, time::Duration};
|
||||
|
||||
@ -53,7 +51,7 @@ pub fn build_transport(
|
||||
psk: Option<PreSharedKey>,
|
||||
) -> transport::Boxed<(PeerId, StreamMuxerBox)> {
|
||||
let noise_config = noise::Config::new(&key_pair).unwrap();
|
||||
let yamux_config = YamuxConfig::default();
|
||||
let yamux_config = yamux::Config::default();
|
||||
|
||||
let base_transport = tcp::async_io::Transport::new(tcp::Config::default().nodelay(true));
|
||||
let maybe_encrypted = match psk {
|
||||
|
@ -75,7 +75,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
tcp::async_io::Transport::default()
|
||||
.upgrade(Version::V1Lazy)
|
||||
.authenticate(noise::Config::new(&local_key)?)
|
||||
.multiplex(yamux::YamuxConfig::default())
|
||||
.multiplex(yamux::Config::default())
|
||||
.boxed(),
|
||||
Behaviour::new(local_pub_key),
|
||||
local_peer_id,
|
||||
|
@ -58,7 +58,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
let transport = tcp::async_io::Transport::default()
|
||||
.upgrade(Version::V1Lazy)
|
||||
.authenticate(noise::Config::new(&local_key)?)
|
||||
.multiplex(yamux::YamuxConfig::default())
|
||||
.multiplex(yamux::Config::default())
|
||||
.boxed();
|
||||
|
||||
let mut swarm =
|
||||
|
@ -53,7 +53,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
.authenticate(
|
||||
noise::Config::new(&local_key).expect("Signing libp2p-noise static DH keypair failed."),
|
||||
)
|
||||
.multiplex(libp2p::yamux::YamuxConfig::default())
|
||||
.multiplex(libp2p::yamux::Config::default())
|
||||
.boxed();
|
||||
|
||||
let behaviour = Behaviour {
|
||||
|
@ -45,7 +45,7 @@ async fn main() {
|
||||
tcp::tokio::Transport::default()
|
||||
.upgrade(Version::V1Lazy)
|
||||
.authenticate(noise::Config::new(&key_pair).unwrap())
|
||||
.multiplex(yamux::YamuxConfig::default())
|
||||
.multiplex(yamux::Config::default())
|
||||
.boxed(),
|
||||
MyBehaviour {
|
||||
rendezvous: rendezvous::client::Behaviour::new(key_pair.clone()),
|
||||
|
@ -41,7 +41,7 @@ async fn main() {
|
||||
tcp::tokio::Transport::default()
|
||||
.upgrade(Version::V1Lazy)
|
||||
.authenticate(noise::Config::new(&key_pair).unwrap())
|
||||
.multiplex(yamux::YamuxConfig::default())
|
||||
.multiplex(yamux::Config::default())
|
||||
.boxed(),
|
||||
MyBehaviour {
|
||||
identify: identify::Behaviour::new(identify::Config::new(
|
||||
|
@ -41,7 +41,7 @@ async fn main() {
|
||||
tcp::tokio::Transport::default()
|
||||
.upgrade(Version::V1Lazy)
|
||||
.authenticate(noise::Config::new(&key_pair).unwrap())
|
||||
.multiplex(yamux::YamuxConfig::default())
|
||||
.multiplex(yamux::Config::default())
|
||||
.boxed(),
|
||||
MyBehaviour {
|
||||
rendezvous: rendezvous::client::Behaviour::new(key_pair.clone()),
|
||||
|
@ -55,7 +55,7 @@ async fn main() {
|
||||
tcp::tokio::Transport::default()
|
||||
.upgrade(Version::V1Lazy)
|
||||
.authenticate(noise::Config::new(&key_pair).unwrap())
|
||||
.multiplex(yamux::YamuxConfig::default())
|
||||
.multiplex(yamux::Config::default())
|
||||
.boxed(),
|
||||
MyBehaviour {
|
||||
identify: identify::Behaviour::new(identify::Config::new(
|
||||
|
@ -181,9 +181,9 @@ async fn main() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn muxer_protocol_from_env() -> Result<Either<yamux::YamuxConfig, mplex::MplexConfig>> {
|
||||
fn muxer_protocol_from_env() -> Result<Either<yamux::Config, mplex::MplexConfig>> {
|
||||
Ok(match from_env("muxer")? {
|
||||
Muxer::Yamux => Either::Left(yamux::YamuxConfig::default()),
|
||||
Muxer::Yamux => Either::Left(yamux::Config::default()),
|
||||
Muxer::Mplex => Either::Right(mplex::MplexConfig::new()),
|
||||
})
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ libp2p-rendezvous = { version = "0.12.0", path = "../protocols/rendezvous", opti
|
||||
libp2p-request-response = { version = "0.24.0", path = "../protocols/request-response", optional = true }
|
||||
libp2p-swarm = { version = "0.42.0", path = "../swarm" }
|
||||
libp2p-wasm-ext = { version = "0.39.0", path = "../transports/wasm-ext", optional = true }
|
||||
libp2p-yamux = { version = "0.43.0", path = "../muxers/yamux", optional = true }
|
||||
libp2p-yamux = { version = "0.43.1", path = "../muxers/yamux", optional = true }
|
||||
multiaddr = { version = "0.17.0" }
|
||||
pin-project = "1.0.0"
|
||||
|
||||
|
@ -233,7 +233,7 @@ pub async fn development_transport(
|
||||
.upgrade(core::upgrade::Version::V1)
|
||||
.authenticate(noise::Config::new(&keypair).unwrap())
|
||||
.multiplex(core::upgrade::SelectUpgrade::new(
|
||||
yamux::YamuxConfig::default(),
|
||||
yamux::Config::default(),
|
||||
#[allow(deprecated)]
|
||||
mplex::MplexConfig::default(),
|
||||
))
|
||||
@ -290,7 +290,7 @@ pub fn tokio_development_transport(
|
||||
.upgrade(core::upgrade::Version::V1)
|
||||
.authenticate(noise::Config::new(&keypair).unwrap())
|
||||
.multiplex(core::upgrade::SelectUpgrade::new(
|
||||
yamux::YamuxConfig::default(),
|
||||
yamux::Config::default(),
|
||||
#[allow(deprecated)]
|
||||
mplex::MplexConfig::default(),
|
||||
))
|
||||
|
@ -1,3 +1,11 @@
|
||||
## 0.43.1 - unreleased
|
||||
|
||||
- Drop `Yamux` prefix from all types.
|
||||
Users are encouraged to import the `yamux` module and refer to types via `yamux::Muxer`, `yamux::Config` etc.
|
||||
See [PR XXXX].
|
||||
|
||||
[PR XXXX]: https://github.com/libp2p/rust-libp2p/pull/XXXX
|
||||
|
||||
## 0.43.0
|
||||
|
||||
- Update to `libp2p-core` `v0.39.0`.
|
||||
|
@ -3,7 +3,7 @@ name = "libp2p-yamux"
|
||||
edition = "2021"
|
||||
rust-version = "1.60.0"
|
||||
description = "Yamux multiplexing protocol for libp2p"
|
||||
version = "0.43.0"
|
||||
version = "0.43.1"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/libp2p/rust-libp2p"
|
||||
|
@ -40,8 +40,11 @@ use std::{
|
||||
use thiserror::Error;
|
||||
use yamux::ConnectionError;
|
||||
|
||||
#[deprecated(note = "Import the `yamux` module instead and refer to this type as `yamux::Muxer`.")]
|
||||
pub type Yamux<S> = Muxer<S>;
|
||||
|
||||
/// A Yamux connection.
|
||||
pub struct Yamux<S> {
|
||||
pub struct Muxer<S> {
|
||||
/// The [`futures::stream::Stream`] of incoming substreams.
|
||||
incoming: S,
|
||||
/// Handle to control the connection.
|
||||
@ -62,13 +65,13 @@ pub struct Yamux<S> {
|
||||
|
||||
const MAX_BUFFERED_INBOUND_STREAMS: usize = 25;
|
||||
|
||||
impl<S> fmt::Debug for Yamux<S> {
|
||||
impl<S> fmt::Debug for Muxer<S> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.write_str("Yamux")
|
||||
}
|
||||
}
|
||||
|
||||
impl<C> Yamux<Incoming<C>>
|
||||
impl<C> Muxer<Incoming<C>>
|
||||
where
|
||||
C: AsyncRead + AsyncWrite + Send + Unpin + 'static,
|
||||
{
|
||||
@ -77,7 +80,7 @@ where
|
||||
let conn = yamux::Connection::new(io, cfg, mode);
|
||||
let ctrl = conn.control();
|
||||
|
||||
Yamux {
|
||||
Self {
|
||||
incoming: Incoming {
|
||||
stream: yamux::into_stream(conn).err_into().boxed(),
|
||||
_marker: std::marker::PhantomData,
|
||||
@ -89,7 +92,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<C> Yamux<LocalIncoming<C>>
|
||||
impl<C> Muxer<LocalIncoming<C>>
|
||||
where
|
||||
C: AsyncRead + AsyncWrite + Unpin + 'static,
|
||||
{
|
||||
@ -98,7 +101,7 @@ where
|
||||
let conn = yamux::Connection::new(io, cfg, mode);
|
||||
let ctrl = conn.control();
|
||||
|
||||
Yamux {
|
||||
Self {
|
||||
incoming: LocalIncoming {
|
||||
stream: yamux::into_stream(conn).err_into().boxed_local(),
|
||||
_marker: std::marker::PhantomData,
|
||||
@ -110,14 +113,15 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub type YamuxResult<T> = Result<T, YamuxError>;
|
||||
#[deprecated(note = "Use `Result<T, yamux::Error>` instead.")]
|
||||
pub type YamuxResult<T> = Result<T, Error>;
|
||||
|
||||
impl<S> StreamMuxer for Yamux<S>
|
||||
impl<S> StreamMuxer for Muxer<S>
|
||||
where
|
||||
S: Stream<Item = Result<yamux::Stream, YamuxError>> + Unpin,
|
||||
S: Stream<Item = Result<yamux::Stream, Error>> + Unpin,
|
||||
{
|
||||
type Substream = yamux::Stream;
|
||||
type Error = YamuxError;
|
||||
type Error = Error;
|
||||
|
||||
fn poll_inbound(
|
||||
mut self: Pin<&mut Self>,
|
||||
@ -138,7 +142,7 @@ where
|
||||
) -> Poll<Result<Self::Substream, Self::Error>> {
|
||||
Pin::new(&mut self.control)
|
||||
.poll_open_stream(cx)
|
||||
.map_err(YamuxError)
|
||||
.map_err(Error)
|
||||
}
|
||||
|
||||
fn poll(
|
||||
@ -165,11 +169,8 @@ where
|
||||
Poll::Pending
|
||||
}
|
||||
|
||||
fn poll_close(mut self: Pin<&mut Self>, c: &mut Context<'_>) -> Poll<YamuxResult<()>> {
|
||||
if let Poll::Ready(()) = Pin::new(&mut self.control)
|
||||
.poll_close(c)
|
||||
.map_err(YamuxError)?
|
||||
{
|
||||
fn poll_close(mut self: Pin<&mut Self>, c: &mut Context<'_>) -> Poll<Result<(), Error>> {
|
||||
if let Poll::Ready(()) = Pin::new(&mut self.control).poll_close(c).map_err(Error)? {
|
||||
return Poll::Ready(Ok(()));
|
||||
}
|
||||
|
||||
@ -184,24 +185,27 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> Yamux<S>
|
||||
impl<S> Muxer<S>
|
||||
where
|
||||
S: Stream<Item = Result<yamux::Stream, YamuxError>> + Unpin,
|
||||
S: Stream<Item = Result<yamux::Stream, Error>> + Unpin,
|
||||
{
|
||||
fn poll_inner(&mut self, cx: &mut Context<'_>) -> Poll<Result<yamux::Stream, YamuxError>> {
|
||||
fn poll_inner(&mut self, cx: &mut Context<'_>) -> Poll<Result<yamux::Stream, Error>> {
|
||||
self.incoming.poll_next_unpin(cx).map(|maybe_stream| {
|
||||
let stream = maybe_stream
|
||||
.transpose()?
|
||||
.ok_or(YamuxError(ConnectionError::Closed))?;
|
||||
.ok_or(Error(ConnectionError::Closed))?;
|
||||
|
||||
Ok(stream)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[deprecated(note = "Import the `yamux` module and refer to this type as `yamux::Config` instead.")]
|
||||
pub type YamuxConfig = Config;
|
||||
|
||||
/// The yamux configuration.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct YamuxConfig {
|
||||
pub struct Config {
|
||||
inner: yamux::Config,
|
||||
mode: Option<yamux::Mode>,
|
||||
}
|
||||
@ -246,11 +250,16 @@ impl WindowUpdateMode {
|
||||
}
|
||||
}
|
||||
|
||||
#[deprecated(
|
||||
note = "Import the `yamux` module and refer to this type as `yamux::LocalConfig` instead."
|
||||
)]
|
||||
pub type YamuxLocalConfig = LocalConfig;
|
||||
|
||||
/// The yamux configuration for upgrading I/O resources which are ![`Send`].
|
||||
#[derive(Clone)]
|
||||
pub struct YamuxLocalConfig(YamuxConfig);
|
||||
pub struct LocalConfig(Config);
|
||||
|
||||
impl YamuxConfig {
|
||||
impl Config {
|
||||
/// Creates a new `YamuxConfig` in client mode, regardless of whether
|
||||
/// it will be used for an inbound or outbound upgrade.
|
||||
pub fn client() -> Self {
|
||||
@ -294,24 +303,24 @@ impl YamuxConfig {
|
||||
self
|
||||
}
|
||||
|
||||
/// Converts the config into a [`YamuxLocalConfig`] for use with upgrades
|
||||
/// Converts the config into a [`LocalConfig`] for use with upgrades
|
||||
/// of I/O streams that are ![`Send`].
|
||||
pub fn into_local(self) -> YamuxLocalConfig {
|
||||
YamuxLocalConfig(self)
|
||||
pub fn into_local(self) -> LocalConfig {
|
||||
LocalConfig(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for YamuxConfig {
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
let mut inner = yamux::Config::default();
|
||||
// For conformity with mplex, read-after-close on a multiplexed
|
||||
// connection is never permitted and not configurable.
|
||||
inner.set_read_after_close(false);
|
||||
YamuxConfig { inner, mode: None }
|
||||
Config { inner, mode: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl UpgradeInfo for YamuxConfig {
|
||||
impl UpgradeInfo for Config {
|
||||
type Info = &'static [u8];
|
||||
type InfoIter = iter::Once<Self::Info>;
|
||||
|
||||
@ -320,7 +329,7 @@ impl UpgradeInfo for YamuxConfig {
|
||||
}
|
||||
}
|
||||
|
||||
impl UpgradeInfo for YamuxLocalConfig {
|
||||
impl UpgradeInfo for LocalConfig {
|
||||
type Info = &'static [u8];
|
||||
type InfoIter = iter::Once<Self::Info>;
|
||||
|
||||
@ -329,71 +338,74 @@ impl UpgradeInfo for YamuxLocalConfig {
|
||||
}
|
||||
}
|
||||
|
||||
impl<C> InboundUpgrade<C> for YamuxConfig
|
||||
impl<C> InboundUpgrade<C> for Config
|
||||
where
|
||||
C: AsyncRead + AsyncWrite + Send + Unpin + 'static,
|
||||
{
|
||||
type Output = Yamux<Incoming<C>>;
|
||||
type Output = Muxer<Incoming<C>>;
|
||||
type Error = io::Error;
|
||||
type Future = future::Ready<Result<Self::Output, Self::Error>>;
|
||||
|
||||
fn upgrade_inbound(self, io: C, _: Self::Info) -> Self::Future {
|
||||
let mode = self.mode.unwrap_or(yamux::Mode::Server);
|
||||
future::ready(Ok(Yamux::new(io, self.inner, mode)))
|
||||
future::ready(Ok(Muxer::new(io, self.inner, mode)))
|
||||
}
|
||||
}
|
||||
|
||||
impl<C> InboundUpgrade<C> for YamuxLocalConfig
|
||||
impl<C> InboundUpgrade<C> for LocalConfig
|
||||
where
|
||||
C: AsyncRead + AsyncWrite + Unpin + 'static,
|
||||
{
|
||||
type Output = Yamux<LocalIncoming<C>>;
|
||||
type Output = Muxer<LocalIncoming<C>>;
|
||||
type Error = io::Error;
|
||||
type Future = future::Ready<Result<Self::Output, Self::Error>>;
|
||||
|
||||
fn upgrade_inbound(self, io: C, _: Self::Info) -> Self::Future {
|
||||
let cfg = self.0;
|
||||
let mode = cfg.mode.unwrap_or(yamux::Mode::Server);
|
||||
future::ready(Ok(Yamux::local(io, cfg.inner, mode)))
|
||||
future::ready(Ok(Muxer::local(io, cfg.inner, mode)))
|
||||
}
|
||||
}
|
||||
|
||||
impl<C> OutboundUpgrade<C> for YamuxConfig
|
||||
impl<C> OutboundUpgrade<C> for Config
|
||||
where
|
||||
C: AsyncRead + AsyncWrite + Send + Unpin + 'static,
|
||||
{
|
||||
type Output = Yamux<Incoming<C>>;
|
||||
type Output = Muxer<Incoming<C>>;
|
||||
type Error = io::Error;
|
||||
type Future = future::Ready<Result<Self::Output, Self::Error>>;
|
||||
|
||||
fn upgrade_outbound(self, io: C, _: Self::Info) -> Self::Future {
|
||||
let mode = self.mode.unwrap_or(yamux::Mode::Client);
|
||||
future::ready(Ok(Yamux::new(io, self.inner, mode)))
|
||||
future::ready(Ok(Muxer::new(io, self.inner, mode)))
|
||||
}
|
||||
}
|
||||
|
||||
impl<C> OutboundUpgrade<C> for YamuxLocalConfig
|
||||
impl<C> OutboundUpgrade<C> for LocalConfig
|
||||
where
|
||||
C: AsyncRead + AsyncWrite + Unpin + 'static,
|
||||
{
|
||||
type Output = Yamux<LocalIncoming<C>>;
|
||||
type Output = Muxer<LocalIncoming<C>>;
|
||||
type Error = io::Error;
|
||||
type Future = future::Ready<Result<Self::Output, Self::Error>>;
|
||||
|
||||
fn upgrade_outbound(self, io: C, _: Self::Info) -> Self::Future {
|
||||
let cfg = self.0;
|
||||
let mode = cfg.mode.unwrap_or(yamux::Mode::Client);
|
||||
future::ready(Ok(Yamux::local(io, cfg.inner, mode)))
|
||||
future::ready(Ok(Muxer::local(io, cfg.inner, mode)))
|
||||
}
|
||||
}
|
||||
|
||||
#[deprecated(note = "Import the `yamux` module and refer to this type as `yamux::Error` instead.")]
|
||||
pub type YamuxError = Error;
|
||||
|
||||
/// The Yamux [`StreamMuxer`] error type.
|
||||
#[derive(Debug, Error)]
|
||||
#[error("yamux error: {0}")]
|
||||
pub struct YamuxError(#[from] yamux::ConnectionError);
|
||||
pub struct Error(#[from] yamux::ConnectionError);
|
||||
|
||||
impl From<YamuxError> for io::Error {
|
||||
fn from(err: YamuxError) -> Self {
|
||||
impl From<Error> for io::Error {
|
||||
fn from(err: Error) -> Self {
|
||||
match err.0 {
|
||||
yamux::ConnectionError::Io(e) => e,
|
||||
e => io::Error::new(io::ErrorKind::Other, e),
|
||||
@ -403,7 +415,7 @@ impl From<YamuxError> for io::Error {
|
||||
|
||||
/// The [`futures::stream::Stream`] of incoming substreams.
|
||||
pub struct Incoming<T> {
|
||||
stream: BoxStream<'static, Result<yamux::Stream, YamuxError>>,
|
||||
stream: BoxStream<'static, Result<yamux::Stream, Error>>,
|
||||
_marker: std::marker::PhantomData<T>,
|
||||
}
|
||||
|
||||
@ -415,7 +427,7 @@ impl<T> fmt::Debug for Incoming<T> {
|
||||
|
||||
/// The [`futures::stream::Stream`] of incoming substreams (`!Send`).
|
||||
pub struct LocalIncoming<T> {
|
||||
stream: LocalBoxStream<'static, Result<yamux::Stream, YamuxError>>,
|
||||
stream: LocalBoxStream<'static, Result<yamux::Stream, Error>>,
|
||||
_marker: std::marker::PhantomData<T>,
|
||||
}
|
||||
|
||||
@ -426,7 +438,7 @@ impl<T> fmt::Debug for LocalIncoming<T> {
|
||||
}
|
||||
|
||||
impl<T> Stream for Incoming<T> {
|
||||
type Item = Result<yamux::Stream, YamuxError>;
|
||||
type Item = Result<yamux::Stream, Error>;
|
||||
|
||||
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||
self.stream.as_mut().poll_next_unpin(cx)
|
||||
@ -440,7 +452,7 @@ impl<T> Stream for Incoming<T> {
|
||||
impl<T> Unpin for Incoming<T> {}
|
||||
|
||||
impl<T> Stream for LocalIncoming<T> {
|
||||
type Item = Result<yamux::Stream, YamuxError>;
|
||||
type Item = Result<yamux::Stream, Error>;
|
||||
|
||||
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||
self.stream.as_mut().poll_next_unpin(cx)
|
||||
|
@ -1,10 +1,9 @@
|
||||
use libp2p_yamux::YamuxConfig;
|
||||
use libp2p_yamux::Config;
|
||||
|
||||
#[async_std::test]
|
||||
async fn close_implies_flush() {
|
||||
let (alice, bob) =
|
||||
libp2p_muxer_test_harness::connected_muxers_on_memory_ring_buffer::<YamuxConfig, _, _>()
|
||||
.await;
|
||||
libp2p_muxer_test_harness::connected_muxers_on_memory_ring_buffer::<Config, _, _>().await;
|
||||
|
||||
libp2p_muxer_test_harness::close_implies_flush(alice, bob).await;
|
||||
}
|
||||
@ -12,8 +11,7 @@ async fn close_implies_flush() {
|
||||
#[async_std::test]
|
||||
async fn read_after_close() {
|
||||
let (alice, bob) =
|
||||
libp2p_muxer_test_harness::connected_muxers_on_memory_ring_buffer::<YamuxConfig, _, _>()
|
||||
.await;
|
||||
libp2p_muxer_test_harness::connected_muxers_on_memory_ring_buffer::<Config, _, _>().await;
|
||||
|
||||
libp2p_muxer_test_harness::read_after_close(alice, bob).await;
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ fn build_client() -> Swarm<Client> {
|
||||
.or_transport(libp2p_tcp::async_io::Transport::default())
|
||||
.upgrade(Version::V1)
|
||||
.authenticate(PlainText2Config { local_public_key })
|
||||
.multiplex(libp2p_yamux::YamuxConfig::default())
|
||||
.multiplex(libp2p_yamux::Config::default())
|
||||
.boxed();
|
||||
|
||||
SwarmBuilder::without_executor(
|
||||
|
@ -60,7 +60,7 @@ fn build_node_with_config(cfg: KademliaConfig) -> (Multiaddr, TestSwarm) {
|
||||
let transport = MemoryTransport::default()
|
||||
.upgrade(upgrade::Version::V1)
|
||||
.authenticate(noise::Config::new(&local_key).unwrap())
|
||||
.multiplex(yamux::YamuxConfig::default())
|
||||
.multiplex(yamux::Config::default())
|
||||
.boxed();
|
||||
|
||||
let local_id = local_public_key.to_peer_id();
|
||||
|
@ -24,7 +24,7 @@ libp2p-noise = { version = "0.42.2", path = "../../transports/noise" }
|
||||
libp2p-quic = { version = "0.7.0-alpha.2", path = "../../transports/quic", features = ["async-std"] }
|
||||
libp2p-swarm = { version = "0.42.1", path = "../../swarm", features = ["macros", "async-std"] }
|
||||
libp2p-tcp = { version = "0.39.0", path = "../../transports/tcp", features = ["async-io"] }
|
||||
libp2p-yamux = { version = "0.43.0", path = "../../muxers/yamux" }
|
||||
libp2p-yamux = { version = "0.43.1", path = "../../muxers/yamux" }
|
||||
log = "0.4"
|
||||
thiserror = "1.0"
|
||||
void = "1"
|
||||
|
@ -55,7 +55,7 @@ async fn main() -> Result<()> {
|
||||
libp2p_noise::Config::new(&local_key)
|
||||
.expect("Signing libp2p-noise static DH keypair failed."),
|
||||
)
|
||||
.multiplex(libp2p_yamux::YamuxConfig::default());
|
||||
.multiplex(libp2p_yamux::Config::default());
|
||||
|
||||
let quic = {
|
||||
let mut config = libp2p_quic::Config::new(&local_key);
|
||||
|
@ -49,7 +49,7 @@ async fn main() {
|
||||
libp2p_noise::Config::new(&local_key)
|
||||
.expect("Signing libp2p-noise static DH keypair failed."),
|
||||
)
|
||||
.multiplex(libp2p_yamux::YamuxConfig::default());
|
||||
.multiplex(libp2p_yamux::Config::default());
|
||||
|
||||
let quic = {
|
||||
let mut config = libp2p_quic::Config::new(&local_key);
|
||||
|
@ -357,7 +357,7 @@ where
|
||||
transport
|
||||
.upgrade(upgrade::Version::V1)
|
||||
.authenticate(PlainText2Config { local_public_key })
|
||||
.multiplex(libp2p_yamux::YamuxConfig::default())
|
||||
.multiplex(libp2p_yamux::Config::default())
|
||||
.boxed()
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ libp2p-identity = { version = "0.1.1", path = "../identity" }
|
||||
libp2p-plaintext = { version = "0.39.1", path = "../transports/plaintext" }
|
||||
libp2p-swarm = { version = "0.42.0", path = "../swarm" }
|
||||
libp2p-tcp = { version = "0.39.0", path = "../transports/tcp", features = ["async-io"] }
|
||||
libp2p-yamux = { version = "0.43.0", path = "../muxers/yamux" }
|
||||
libp2p-yamux = { version = "0.43.1", path = "../muxers/yamux" }
|
||||
futures = "0.3.28"
|
||||
log = "0.4.17"
|
||||
rand = "0.8.5"
|
||||
|
@ -32,7 +32,7 @@ use libp2p_swarm::{
|
||||
dial_opts::DialOpts, AddressScore, NetworkBehaviour, Swarm, SwarmBuilder, SwarmEvent,
|
||||
THandlerErr,
|
||||
};
|
||||
use libp2p_yamux::YamuxConfig;
|
||||
use libp2p_yamux as yamux;
|
||||
use std::fmt::Debug;
|
||||
use std::time::Duration;
|
||||
|
||||
@ -216,7 +216,7 @@ where
|
||||
.authenticate(PlainText2Config {
|
||||
local_public_key: identity.public(),
|
||||
})
|
||||
.multiplex(YamuxConfig::default())
|
||||
.multiplex(yamux::Config::default())
|
||||
.timeout(Duration::from_secs(20))
|
||||
.boxed();
|
||||
|
||||
|
@ -2067,7 +2067,7 @@ mod tests {
|
||||
.authenticate(plaintext::PlainText2Config {
|
||||
local_public_key: local_public_key.clone(),
|
||||
})
|
||||
.multiplex(yamux::YamuxConfig::default())
|
||||
.multiplex(yamux::Config::default())
|
||||
.boxed();
|
||||
let behaviour = CallTraceBehaviour::new(MockBehaviour::new(handler_proto));
|
||||
match ThreadPool::new().ok() {
|
||||
|
@ -111,7 +111,7 @@ where
|
||||
.and_then(move |socket, _| pnet.handshake(socket))
|
||||
.upgrade(Version::V1)
|
||||
.authenticate(libp2p_noise::Config::new(&identity).unwrap())
|
||||
.multiplex(libp2p_yamux::YamuxConfig::default())
|
||||
.multiplex(libp2p_yamux::Config::default())
|
||||
.boxed();
|
||||
SwarmBuilder::with_tokio_executor(
|
||||
transport,
|
||||
|
@ -234,7 +234,7 @@ fn new_tcp_quic_transport() -> (PeerId, Boxed<(PeerId, StreamMuxerBox)>) {
|
||||
let tcp_transport = tcp::async_io::Transport::new(tcp::Config::default())
|
||||
.upgrade(upgrade::Version::V1)
|
||||
.authenticate(noise::Config::new(&keypair).unwrap())
|
||||
.multiplex(yamux::YamuxConfig::default());
|
||||
.multiplex(yamux::Config::default());
|
||||
|
||||
let transport = OrTransport::new(quic_transport, tcp_transport)
|
||||
.map(|either_output, _| match either_output {
|
||||
|
@ -61,7 +61,7 @@ fn make_swarm() -> Swarm<keep_alive::Behaviour> {
|
||||
let transport = MemoryTransport::default()
|
||||
.upgrade(Version::V1)
|
||||
.authenticate(libp2p_tls::Config::new(&identity).unwrap())
|
||||
.multiplex(libp2p_yamux::YamuxConfig::default())
|
||||
.multiplex(libp2p_yamux::Config::default())
|
||||
.boxed();
|
||||
|
||||
SwarmBuilder::without_executor(
|
||||
|
Reference in New Issue
Block a user