-
Notifications
You must be signed in to change notification settings - Fork 23
fix: multistream-select negotiation on outbound substream over webrtc #465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
196d625
b875bbd
925caa9
4200246
85fae21
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| /target | ||
| .idea | ||
|
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -382,21 +382,32 @@ impl WebRtcConnection { | |
| target: LOG_TARGET, | ||
| peer = ?self.peer, | ||
| ?channel_id, | ||
| data_len = ?data.len(), | ||
| "handle opening outbound substream", | ||
| ); | ||
|
|
||
| let rtc_message = WebRtcMessage::decode(&data) | ||
| .map_err(|err| SubstreamError::NegotiationError(err.into()))?; | ||
| let message = rtc_message.payload.ok_or(SubstreamError::NegotiationError( | ||
| let payload = rtc_message.payload.ok_or(SubstreamError::NegotiationError( | ||
| ParseError::InvalidData.into(), | ||
| ))?; | ||
|
|
||
| let HandshakeResult::Succeeded(protocol) = dialer_state.register_response(message)? else { | ||
| // All multistream-select messages are length-prefixed. Since this code path is not using | ||
| // multistream_select::protocol::MessageIO, we need to decode and remove the length here. | ||
| let remaining: &[u8] = &payload; | ||
| let (len, tail) = unsigned_varint::decode::usize(remaining). | ||
| map_err(|_| SubstreamError::NegotiationError( | ||
| ParseError::InvalidData.into(), | ||
| ))?; | ||
|
|
||
| let message = tail[..len].to_vec(); | ||
|
|
||
| let HandshakeResult::Succeeded(protocol) = dialer_state.register_response(message)? else { | ||
| tracing::trace!( | ||
| target: LOG_TARGET, | ||
| peer = ?self.peer, | ||
| ?channel_id, | ||
| "multisteam-select handshake not ready", | ||
| "multistream-select handshake not ready", | ||
| ); | ||
|
|
||
| self.channels.insert( | ||
|
|
@@ -631,6 +642,8 @@ impl WebRtcConnection { | |
| protocol: protocol.to_string(), | ||
| }); | ||
|
|
||
| // self.rtc.channel(channel_id).unwrap().set_buffered_amount_low_threshold(1024); | ||
|
|
||
| tracing::trace!( | ||
| target: LOG_TARGET, | ||
| peer = ?self.peer, | ||
|
|
@@ -742,6 +755,20 @@ impl WebRtcConnection { | |
|
|
||
| continue; | ||
| } | ||
| Event::ChannelBufferedAmountLow(channel_id) => { | ||
| if let Some(ChannelState::Closing) = self.channels.get(&channel_id) { | ||
| tracing::trace!( | ||
| target: LOG_TARGET, | ||
| peer = ?self.peer, | ||
| ?channel_id, | ||
| "buffer drained, closing channel", | ||
| ); | ||
| self.rtc.direct_api().close_data_channel(channel_id); | ||
| self.handles.remove(&channel_id); | ||
| } | ||
|
|
||
| continue; | ||
| } | ||
| event => { | ||
| tracing::debug!( | ||
| target: LOG_TARGET, | ||
|
|
@@ -787,17 +814,15 @@ impl WebRtcConnection { | |
| }, | ||
| event = self.handles.next() => match event { | ||
| None => unreachable!(), | ||
| Some((channel_id, None | Some(SubstreamEvent::Close))) => { | ||
| Some((_, None)) => {} | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a superficial fix for another unrelated issue which I haven't investigated yet. Without this change, a "channel closed" event is fired repeatedly after a while. I believe this is caused by I've also seen this happen when briefly testing with a rust-libp2p dialer, so this is not related to smoldot interop. |
||
| Some((channel_id, Some(SubstreamEvent::Close))) => { | ||
| tracing::trace!( | ||
| target: LOG_TARGET, | ||
| peer = ?self.peer, | ||
| ?channel_id, | ||
| "channel closed", | ||
| ); | ||
|
|
||
| self.rtc.direct_api().close_data_channel(channel_id); | ||
| self.channels.insert(channel_id, ChannelState::Closing); | ||
| self.handles.remove(&channel_id); | ||
| } | ||
| Some((channel_id, Some(SubstreamEvent::Message(data)))) => { | ||
| if let Err(error) = self.on_outbound_data(channel_id, data) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an unrelated issue.