Skip to content

Commit

Permalink
[mplex, yamux] Streamline configuration API. (#1822)
Browse files Browse the repository at this point in the history
* Streamline mplex and yamux configurations.

  * For all configuration options that exist for both multiplexers
    and have the same semantics, use the same names for the
    configuration.
  * Rename `Config` to `YamuxConfig` for consistentcy with
    the majority of other protocols, e.g. `MplexConfig`, `PingConfig`,
    `KademliaConfig`, etc.
  * Completely hide `yamux` APIs within `libp2p-yamux`. This allows
    to fully control the libp2p API and streamline it with other
    muxer APIs, consciously choosing e.g. which configuration options
    to make configurable in libp2p and which to fix to certain values.
    It does also not necessarily prescribe new incompatible version bumps of
    yamux for `libp2p-yamux`, as no `yamux` types are exposed. The cost
    is some more duplication of configuration options in the API, as well
    as the need to update `libp2p-yamux` if `yamux` introduces new
    configuration options that `libp2p-yamux` wants to expose as well.

* Update CHANGELOGs.
  • Loading branch information
romanb authored Nov 6, 2020
1 parent 689eeaf commit 2ba78b4
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 73 deletions.
2 changes: 1 addition & 1 deletion examples/ipfs-private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use libp2p::{
noise,
swarm::NetworkBehaviourEventProcess,
tcp::TcpConfig,
yamux::Config as YamuxConfig,
yamux::YamuxConfig,
Multiaddr, NetworkBehaviour, PeerId, Swarm, Transport,
};
use std::{
Expand Down
4 changes: 4 additions & 0 deletions muxers/mplex/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# 0.24.0 [unreleased]

- Tweak the naming in the `MplexConfig` API for better
consistency with `libp2p-yamux`.
[PR 1822](https://github.com/libp2p/rust-libp2p/pull/1822).

- Update dependencies.

# 0.23.1 [2020-10-28]
Expand Down
8 changes: 4 additions & 4 deletions muxers/mplex/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ impl MplexConfig {
/// accumulates too quickly (judged by internal bounds), the
/// connection is closed with an error due to the misbehaved
/// remote.
pub fn max_substreams(&mut self, max: usize) -> &mut Self {
pub fn set_max_num_streams(&mut self, max: usize) -> &mut Self {
self.max_substreams = max;
self
}

/// Sets the maximum number of frames buffered per substream.
///
/// A limit is necessary in order to avoid DoS attacks.
pub fn max_buffer_len(&mut self, max: usize) -> &mut Self {
pub fn set_max_buffer_size(&mut self, max: usize) -> &mut Self {
self.max_buffer_len = max;
self
}
Expand All @@ -72,14 +72,14 @@ impl MplexConfig {
/// for a substream.
///
/// See the documentation of [`MaxBufferBehaviour`].
pub fn max_buffer_len_behaviour(&mut self, behaviour: MaxBufferBehaviour) -> &mut Self {
pub fn set_max_buffer_behaviour(&mut self, behaviour: MaxBufferBehaviour) -> &mut Self {
self.max_buffer_behaviour = behaviour;
self
}

/// Sets the frame size used when sending data. Capped at 1Mbyte as per the
/// Mplex spec.
pub fn split_send_size(&mut self, size: usize) -> &mut Self {
pub fn set_split_send_size(&mut self, size: usize) -> &mut Self {
let size = cmp::min(size, MAX_FRAME_SIZE);
self.split_send_size = size;
self
Expand Down
4 changes: 4 additions & 0 deletions muxers/yamux/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# 0.27.0 [unreleased]

- Tweak the naming in the `MplexConfig` API for better
consistency with `libp2p-mplex`.
[PR 1822](https://github.com/libp2p/rust-libp2p/pull/1822).

- Update dependencies.

# 0.26.0 [2020-10-16]
Expand Down
Loading

0 comments on commit 2ba78b4

Please sign in to comment.