Skip to content

Commit

Permalink
Deprecate StreamMuxerExt::next_{inbound,outbound}
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaseizinger committed Sep 29, 2022
1 parent 6ff1b02 commit d087153
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

- Implement `Hash` and `Ord` for `PublicKey`. See [PR 2915].

- Deprecate `StreamMuxerExt::next_{inbound,outbound}`. See [PR XXXX].

[PR 2915]: https://github.com/libp2p/rust-libp2p/pull/2915
[PR XXXX]: https://github.com/libp2p/rust-libp2p/pull/XXXX

# 0.36.0

Expand Down
8 changes: 8 additions & 0 deletions core/src/muxing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,19 @@ pub trait StreamMuxerExt: StreamMuxer + Sized {
}

/// Returns a future that resolves to the next inbound `Substream` opened by the remote.
#[deprecated(
since = "0.36.1",
note = "This future violates the `StreamMuxer` contract because it doesn't call `StreamMuxer::poll`."
)]
fn next_inbound(&mut self) -> NextInbound<'_, Self> {
NextInbound(self)
}

/// Returns a future that opens a new outbound `Substream` with the remote.
#[deprecated(
since = "0.36.1",
note = "This future violates the `StreamMuxer` contract because it doesn't call `StreamMuxer::poll`."
)]
fn next_outbound(&mut self) -> NextOutbound<'_, Self> {
NextOutbound(self)
}
Expand Down
8 changes: 6 additions & 2 deletions muxers/mplex/benches/split_send_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ fn run(
}
transport::TransportEvent::Incoming { upgrade, .. } => {
let (_peer, mut conn) = upgrade.await.unwrap();
let mut s = conn.next_inbound().await.expect("unexpected error");
// Just calling `poll_inbound` without `poll` is fine here because mplex makes progress through all `poll_` functions. It is hacky though.
let mut s = poll_fn(|cx| conn.poll_inbound_unpin(cx))
.await
.expect("unexpected error");

let mut buf = vec![0u8; payload_len];
let mut off = 0;
Expand All @@ -139,7 +142,8 @@ fn run(
let sender = async move {
let addr = addr_receiver.await.unwrap();
let (_peer, mut conn) = sender_trans.dial(addr).unwrap().await.unwrap();
let mut stream = conn.next_outbound().await.unwrap();
// Just calling `poll_outbound` without `poll` is fine here because mplex makes progress through all `poll_` functions. It is hacky though.
let mut stream = poll_fn(|cx| conn.poll_outbound_unpin(cx)).await.unwrap();
let mut off = 0;
loop {
let n = poll_fn(|cx| Pin::new(&mut stream).poll_write(cx, &payload[off..]))
Expand Down

0 comments on commit d087153

Please sign in to comment.