Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
webrtc: Support multistream-select header and protocol in separate pr…
…otobuf messages
  • Loading branch information
haikoschol committed Mar 3, 2026
commit 7473d5fe77afbf0d98522f28dd887ffef8d47cad
32 changes: 20 additions & 12 deletions src/multistream_select/dialer_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,12 @@ impl WebRtcDialerState {
protocol: ProtocolName,
fallback_names: Vec<ProtocolName>,
) -> crate::Result<(Self, Vec<u8>)> {
let message = webrtc_encode_multistream_message(Message::Protocol(
Protocol::try_from(protocol.as_ref()).map_err(|_| Error::InvalidData)?,
))?
let message = webrtc_encode_multistream_message(
Message::Protocol(
Protocol::try_from(protocol.as_ref()).map_err(|_| Error::InvalidData)?,
),
true,
)?
.freeze()
.to_vec();

Expand All @@ -368,9 +371,12 @@ impl WebRtcDialerState {
self.protocol = next;
self.state = HandshakeState::WaitingResponse;

let message = webrtc_encode_multistream_message(Message::Protocol(
Protocol::try_from(self.protocol.as_ref()).map_err(|_| Error::InvalidData)?,
))?
let message = webrtc_encode_multistream_message(
Message::Protocol(
Protocol::try_from(self.protocol.as_ref()).map_err(|_| Error::InvalidData)?,
),
true,
)?
.freeze()
.to_vec();

Expand Down Expand Up @@ -931,9 +937,10 @@ mod tests {

#[test]
fn negotiate_main_protocol() {
let message = webrtc_encode_multistream_message(Message::Protocol(
Protocol::try_from(&b"/13371338/proto/1"[..]).unwrap(),
))
let message = webrtc_encode_multistream_message(
Message::Protocol(Protocol::try_from(&b"/13371338/proto/1"[..]).unwrap()),
true,
)
.unwrap()
.freeze();

Expand All @@ -953,9 +960,10 @@ mod tests {

#[test]
fn negotiate_fallback_protocol() {
let message = webrtc_encode_multistream_message(Message::Protocol(
Protocol::try_from(&b"/sup/proto/1"[..]).unwrap(),
))
let message = webrtc_encode_multistream_message(
Message::Protocol(Protocol::try_from(&b"/sup/proto/1"[..]).unwrap()),
true,
)
.unwrap()
.freeze();

Expand Down
2 changes: 1 addition & 1 deletion src/multistream_select/length_delimited.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use std::{
};

const MAX_LEN_BYTES: u16 = 2;
const MAX_FRAME_SIZE: u16 = (1 << (MAX_LEN_BYTES * 8 - MAX_LEN_BYTES)) - 1;
pub(super) const MAX_FRAME_SIZE: u16 = (1 << (MAX_LEN_BYTES * 8 - MAX_LEN_BYTES)) - 1;
const DEFAULT_BUFFER_SIZE: usize = 64;
const LOG_TARGET: &str = "litep2p::multistream-select";

Expand Down
Loading
Loading