Skip to content

Commit

Permalink
fix(webrtc-utils): read buffer only if empty message
Browse files Browse the repository at this point in the history
This PR adds a return of `Poll::Ready(Ok(0))` when the `message` vector is empty or not present.

This missing return was causing the stream not to finish, then to be dropped, causing the request response protocol to fail over WebRTC.

Now that empty or non existent message vectors get returned as `Ok(0)` the stream can be read and request response works now over WebRTC.

Pull-Request: #5439.
  • Loading branch information
DougAnderson444 authored Jun 5, 2024
1 parent 9dcc172 commit 3da7d91
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 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 @@ -110,7 +110,7 @@ libp2p-tls = { version = "0.4.0", path = "transports/tls" }
libp2p-uds = { version = "0.40.0", path = "transports/uds" }
libp2p-upnp = { version = "0.2.2", path = "protocols/upnp" }
libp2p-webrtc = { version = "0.7.1-alpha", path = "transports/webrtc" }
libp2p-webrtc-utils = { version = "0.2.0", path = "misc/webrtc-utils" }
libp2p-webrtc-utils = { version = "0.2.1", path = "misc/webrtc-utils" }
libp2p-webrtc-websys = { version = "0.3.0-alpha", path = "transports/webrtc-websys" }
libp2p-websocket = { version = "0.43.0", path = "transports/websocket" }
libp2p-websocket-websys = { version = "0.3.2", path = "transports/websocket-websys" }
Expand Down
5 changes: 5 additions & 0 deletions misc/webrtc-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.2.1

- Fix end of stream handling when buffer is empty or not present.
See [PR 5439](https://github.com/libp2p/rust-libp2p/pull/5439).

## 0.2.0

- Update to latest version of `libp2p-noise`.
Expand Down
2 changes: 1 addition & 1 deletion misc/webrtc-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT"
name = "libp2p-webrtc-utils"
repository = "https://github.com/libp2p/rust-libp2p"
rust-version = { workspace = true }
version = "0.2.0"
version = "0.2.1"
publish = true

[dependencies]
Expand Down
10 changes: 8 additions & 2 deletions misc/webrtc-utils/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,14 @@ where
}

debug_assert!(read_buffer.is_empty());
if let Some(message) = message {
*read_buffer = message.into();
match message {
Some(msg) if !msg.is_empty() => {
*read_buffer = msg.into();
}
_ => {
tracing::debug!("poll_read buffer is empty, received None");
return Poll::Ready(Ok(0));
}
}
}
None => {
Expand Down

0 comments on commit 3da7d91

Please sign in to comment.