|
19 | 19 | // DEALINGS IN THE SOFTWARE. |
20 | 20 |
|
21 | 21 | use crate::{ |
22 | | - error::{Error, ParseError, SubstreamError}, |
| 22 | + error::{Error, SubstreamError}, |
23 | 23 | multistream_select::{ |
24 | 24 | webrtc_listener_negotiate, HandshakeResult, ListenerSelectResult, NegotiationError, |
25 | 25 | WebRtcDialerState, |
@@ -581,7 +581,21 @@ impl WebRtcConnection { |
581 | 581 | ); |
582 | 582 |
|
583 | 583 | // Decode errors are not recoverable. |
584 | | - let payload = WebRtcMessage::decode(&data)?.payload.ok_or(Error::InvalidData)?; |
| 584 | + let WebRtcMessage { |
| 585 | + payload: Some(payload), |
| 586 | + flag: None, |
| 587 | + } = WebRtcMessage::decode(&data) |
| 588 | + .map_err(|err| SubstreamError::NegotiationError(err.into()))? |
| 589 | + else { |
| 590 | + tracing::debug!( |
| 591 | + target: LOG_TARGET, |
| 592 | + peer = ?self.peer, |
| 593 | + ?channel_id, |
| 594 | + "non-payload frame during inbound opening, closing channel" |
| 595 | + ); |
| 596 | + return Err(Error::ConnectionClosed); |
| 597 | + }; |
| 598 | + |
585 | 599 | let protocols = self.protocol_set.protocols_with_keep_alives(); |
586 | 600 | let protocol_names = protocols.keys().cloned().collect(); |
587 | 601 | let (response, negotiated) = |
@@ -666,11 +680,21 @@ impl WebRtcConnection { |
666 | 680 | "handle opening outbound substream", |
667 | 681 | ); |
668 | 682 |
|
669 | | - let rtc_message = WebRtcMessage::decode(&data) |
670 | | - .map_err(|err| SubstreamError::NegotiationError(err.into()))?; |
671 | | - let message = rtc_message.payload.ok_or(SubstreamError::NegotiationError( |
672 | | - ParseError::InvalidData.into(), |
673 | | - ))?; |
| 683 | + // Decode errors are not recoverable. |
| 684 | + let WebRtcMessage { |
| 685 | + payload: Some(message), |
| 686 | + flag: None, |
| 687 | + } = WebRtcMessage::decode(&data) |
| 688 | + .map_err(|err| SubstreamError::NegotiationError(err.into()))? |
| 689 | + else { |
| 690 | + tracing::debug!( |
| 691 | + target: LOG_TARGET, |
| 692 | + peer = ?self.peer, |
| 693 | + ?channel_id, |
| 694 | + "non-payload frame during outbound opening, closing channel" |
| 695 | + ); |
| 696 | + return Err(SubstreamError::ConnectionClosed); |
| 697 | + }; |
674 | 698 |
|
675 | 699 | let protocol = match dialer_state.register_response(message)? { |
676 | 700 | HandshakeResult::Succeeded(protocol) => protocol, |
|
0 commit comments