Skip to content

Commit

Permalink
chore(mplex): Changing naming convention
Browse files Browse the repository at this point in the history
- related to #2217, including
- Changing naming from `MplexConfig` to `Config` in crates and usage

Pull-Request: #5870.
  • Loading branch information
badgooooor authored Feb 20, 2025
1 parent 0d01a42 commit b1afe88
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ libp2p-kad = { version = "0.47.0", path = "protocols/kad" }
libp2p-mdns = { version = "0.47.0", path = "protocols/mdns" }
libp2p-memory-connection-limits = { version = "0.4.0", path = "misc/memory-connection-limits" }
libp2p-metrics = { version = "0.16.0", path = "misc/metrics" }
libp2p-mplex = { version = "0.43.0", path = "muxers/mplex" }
libp2p-mplex = { version = "0.43.1", path = "muxers/mplex" }
libp2p-noise = { version = "0.46.0", path = "transports/noise" }
libp2p-perf = { version = "0.4.0", path = "protocols/perf" }
libp2p-ping = { version = "0.46.0", path = "protocols/ping" }
Expand Down
6 changes: 3 additions & 3 deletions core/tests/transport_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use libp2p_core::{
Endpoint,
};
use libp2p_identity as identity;
use libp2p_mplex::MplexConfig;
use libp2p_mplex::Config;
use libp2p_noise as noise;
use multiaddr::{Multiaddr, Protocol};
use rand::random;
Expand Down Expand Up @@ -89,7 +89,7 @@ async fn upgrade_pipeline() {
.apply(HelloUpgrade {})
.apply(HelloUpgrade {})
.apply(HelloUpgrade {})
.multiplex(MplexConfig::default())
.multiplex(Config::default())
.boxed();

let dialer_keys = identity::Keypair::generate_ed25519();
Expand All @@ -100,7 +100,7 @@ async fn upgrade_pipeline() {
.apply(HelloUpgrade {})
.apply(HelloUpgrade {})
.apply(HelloUpgrade {})
.multiplex(MplexConfig::default())
.multiplex(Config::default())
.boxed();

let listen_addr1 = Multiaddr::from(Protocol::Memory(random::<u64>()));
Expand Down
10 changes: 5 additions & 5 deletions interop-tests/src/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub(crate) mod native {
.with_tcp(
tcp::Config::default(),
tls::Config::new,
mplex::MplexConfig::default,
mplex::Config::default,
)?
.with_behaviour(behaviour_constructor)?
.build(),
Expand All @@ -82,7 +82,7 @@ pub(crate) mod native {
.with_tcp(
tcp::Config::default(),
noise::Config::new,
mplex::MplexConfig::default,
mplex::Config::default,
)?
.with_behaviour(behaviour_constructor)?
.build(),
Expand All @@ -103,7 +103,7 @@ pub(crate) mod native {
(Transport::Ws, Some(SecProtocol::Tls), Some(Muxer::Mplex)) => (
libp2p::SwarmBuilder::with_new_identity()
.with_tokio()
.with_websocket(tls::Config::new, mplex::MplexConfig::default)
.with_websocket(tls::Config::new, mplex::Config::default)
.await?
.with_behaviour(behaviour_constructor)?
.build(),
Expand All @@ -121,7 +121,7 @@ pub(crate) mod native {
(Transport::Ws, Some(SecProtocol::Noise), Some(Muxer::Mplex)) => (
libp2p::SwarmBuilder::with_new_identity()
.with_tokio()
.with_websocket(noise::Config::new, mplex::MplexConfig::default)
.with_websocket(noise::Config::new, mplex::Config::default)
.await?
.with_behaviour(behaviour_constructor)?
.build(),
Expand Down Expand Up @@ -235,7 +235,7 @@ pub(crate) mod wasm {
noise::Config::new(&local_key)
.context("failed to initialise noise")?,
)
.multiplex(mplex::MplexConfig::new()))
.multiplex(mplex::Config::new()))
})?
.with_behaviour(behaviour_constructor)?
.with_swarm_config(|c| c.with_idle_connection_timeout(Duration::from_secs(5)))
Expand Down
10 changes: 2 additions & 8 deletions libp2p/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,7 @@ mod tests {
.with_tcp(
Default::default(),
libp2p_tls::Config::new,
(
libp2p_yamux::Config::default,
libp2p_mplex::MplexConfig::default,
),
(libp2p_yamux::Config::default, libp2p_mplex::Config::default),
)
.unwrap()
.with_behaviour(|_| libp2p_swarm::dummy::Behaviour)
Expand All @@ -201,10 +198,7 @@ mod tests {
.with_tcp(
Default::default(),
(libp2p_tls::Config::new, libp2p_noise::Config::new),
(
libp2p_yamux::Config::default,
libp2p_mplex::MplexConfig::default,
),
(libp2p_yamux::Config::default, libp2p_mplex::Config::default),
)
.unwrap()
.with_behaviour(|_| libp2p_swarm::dummy::Behaviour)
Expand Down
5 changes: 5 additions & 0 deletions muxers/mplex/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.43.1

- Rename `MplexConfig` to `Config` for consistency with other crates (see [discussion 2174](https://github.com/libp2p/rust-libp2p/discussions/2174)).
See [PR 5870](https://github.com/libp2p/rust-libp2p/pull/5870).

## 0.43.0

<!-- Update to libp2p-core v0.43.0 -->
Expand Down
2 changes: 1 addition & 1 deletion muxers/mplex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p-mplex"
edition = "2021"
rust-version = { workspace = true }
description = "Mplex 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"
Expand Down
4 changes: 2 additions & 2 deletions muxers/mplex/benches/split_send_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ fn run(
}

fn tcp_transport(split_send_size: usize) -> BenchTransport {
let mut mplex = mplex::MplexConfig::default();
let mut mplex = mplex::Config::default();
mplex.set_split_send_size(split_send_size);

libp2p_tcp::async_io::Transport::new(libp2p_tcp::Config::default().nodelay(true))
Expand All @@ -198,7 +198,7 @@ fn tcp_transport(split_send_size: usize) -> BenchTransport {
}

fn mem_transport(split_send_size: usize) -> BenchTransport {
let mut mplex = mplex::MplexConfig::default();
let mut mplex = mplex::Config::default();
mplex.set_split_send_size(split_send_size);

transport::MemoryTransport::default()
Expand Down
14 changes: 7 additions & 7 deletions muxers/mplex/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub(crate) const DEFAULT_MPLEX_PROTOCOL_NAME: &str = "/mplex/6.7.0";

/// Configuration for the multiplexer.
#[derive(Debug, Clone)]
pub struct MplexConfig {
pub struct Config {
/// Maximum number of simultaneously used substreams.
pub(crate) max_substreams: usize,
/// Maximum number of frames buffered per substream.
Expand All @@ -40,9 +40,9 @@ pub struct MplexConfig {
pub(crate) protocol_name: &'static str,
}

impl MplexConfig {
impl Config {
/// Builds the default configuration.
pub fn new() -> MplexConfig {
pub fn new() -> Config {
Default::default()
}

Expand Down Expand Up @@ -108,7 +108,7 @@ impl MplexConfig {
pub enum MaxBufferBehaviour {
/// Reset the substream whose frame buffer overflowed.
///
/// > **Note**: If more than [`MplexConfig::set_max_buffer_size()`] frames
/// > **Note**: If more than [`Config::set_max_buffer_size()`] frames
/// > are received in succession for a substream in the context of
/// > trying to read data from a different substream, the former substream
/// > may be reset before application code had a chance to read from the
Expand All @@ -130,9 +130,9 @@ pub enum MaxBufferBehaviour {
Block,
}

impl Default for MplexConfig {
fn default() -> MplexConfig {
MplexConfig {
impl Default for Config {
fn default() -> Config {
Config {
max_substreams: 128,
max_buffer_len: 32,
max_buffer_behaviour: MaxBufferBehaviour::Block,
Expand Down
16 changes: 8 additions & 8 deletions muxers/mplex/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use smallvec::SmallVec;

use crate::{
codec::{Codec, Frame, LocalStreamId, RemoteStreamId},
MaxBufferBehaviour, MplexConfig,
Config, MaxBufferBehaviour,
};
/// A connection identifier.
///
Expand Down Expand Up @@ -70,7 +70,7 @@ pub(crate) struct Multiplexed<C> {
/// The underlying multiplexed I/O stream.
io: Fuse<Framed<C, Codec>>,
/// The configuration.
config: MplexConfig,
config: Config,
/// The buffer of new inbound substreams that have not yet
/// been drained by `poll_next_stream`. This buffer is
/// effectively bounded by `max_substreams - substreams.len()`.
Expand Down Expand Up @@ -122,7 +122,7 @@ where
C: AsyncRead + AsyncWrite + Unpin,
{
/// Creates a new multiplexed I/O stream.
pub(crate) fn new(io: C, config: MplexConfig) -> Self {
pub(crate) fn new(io: C, config: Config) -> Self {
let id = ConnectionId(rand::random());
tracing::debug!(connection=%id, "New multiplexed connection");
Multiplexed {
Expand Down Expand Up @@ -1168,9 +1168,9 @@ mod tests {
}
}

impl Arbitrary for MplexConfig {
fn arbitrary(g: &mut Gen) -> MplexConfig {
MplexConfig {
impl Arbitrary for Config {
fn arbitrary(g: &mut Gen) -> Config {
Config {
max_substreams: g.gen_range(1..100),
max_buffer_len: g.gen_range(1..1000),
max_buffer_behaviour: MaxBufferBehaviour::arbitrary(g),
Expand Down Expand Up @@ -1236,7 +1236,7 @@ mod tests {
.with_env_filter(EnvFilter::from_default_env())
.try_init();

fn prop(cfg: MplexConfig, overflow: NonZeroU8) {
fn prop(cfg: Config, overflow: NonZeroU8) {
let mut r_buf = BytesMut::new();
let mut codec = Codec::new();

Expand Down Expand Up @@ -1374,7 +1374,7 @@ mod tests {
.with_env_filter(EnvFilter::from_default_env())
.try_init();

fn prop(cfg: MplexConfig, num_streams: NonZeroU8) {
fn prop(cfg: Config, num_streams: NonZeroU8) {
let num_streams = cmp::min(cfg.max_substreams, num_streams.get() as usize);

// Setup the multiplexed connection.
Expand Down
11 changes: 7 additions & 4 deletions muxers/mplex/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,18 @@ use std::{

use bytes::Bytes;
use codec::LocalStreamId;
pub use config::{MaxBufferBehaviour, MplexConfig};
pub use config::{Config, MaxBufferBehaviour};
use futures::{prelude::*, ready};
use libp2p_core::{
muxing::{StreamMuxer, StreamMuxerEvent},
upgrade::{InboundConnectionUpgrade, OutboundConnectionUpgrade, UpgradeInfo},
};
use parking_lot::Mutex;

impl UpgradeInfo for MplexConfig {
#[deprecated = "Use `Config` instead"]
pub type MplexConfig = Config;

impl UpgradeInfo for Config {
type Info = &'static str;
type InfoIter = iter::Once<Self::Info>;

Expand All @@ -52,7 +55,7 @@ impl UpgradeInfo for MplexConfig {
}
}

impl<C> InboundConnectionUpgrade<C> for MplexConfig
impl<C> InboundConnectionUpgrade<C> for Config
where
C: AsyncRead + AsyncWrite + Unpin,
{
Expand All @@ -68,7 +71,7 @@ where
}
}

impl<C> OutboundConnectionUpgrade<C> for MplexConfig
impl<C> OutboundConnectionUpgrade<C> for Config
where
C: AsyncRead + AsyncWrite + Unpin,
{
Expand Down
8 changes: 3 additions & 5 deletions muxers/mplex/tests/compliance.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
use libp2p_mplex::MplexConfig;
use libp2p_mplex::Config;

#[async_std::test]
async fn close_implies_flush() {
let (alice, bob) =
libp2p_muxer_test_harness::connected_muxers_on_memory_ring_buffer::<MplexConfig, _, _>()
.await;
libp2p_muxer_test_harness::connected_muxers_on_memory_ring_buffer::<Config, _, _>().await;

libp2p_muxer_test_harness::close_implies_flush(alice, bob).await;
}

#[async_std::test]
async fn read_after_close() {
let (alice, bob) =
libp2p_muxer_test_harness::connected_muxers_on_memory_ring_buffer::<MplexConfig, _, _>()
.await;
libp2p_muxer_test_harness::connected_muxers_on_memory_ring_buffer::<Config, _, _>().await;

libp2p_muxer_test_harness::read_after_close(alice, bob).await;
}

0 comments on commit b1afe88

Please sign in to comment.