Moved PaddingSize field from Packet to Header#307
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #307 +/- ##
==========================================
- Coverage 86.88% 86.85% -0.03%
==========================================
Files 26 26
Lines 3087 3104 +17
==========================================
+ Hits 2682 2696 +14
- Misses 348 350 +2
- Partials 57 58 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
608c7ca to
0b11247
Compare
|
Hello, this change doesn't fix anything inside this specific library (pion/rtp) and makes it more difficult to use since the resulting public interface is less clear and doesn't correspond to a real RTP packet structure anymore, since the padding is moved inside the header while it doesn't belong there (as written inside the code too). Personally i would have fixed things inside pion/webrtc in order to route type headerPaddingSizePair struct {
header rtp.Header
paddingSize int
}instead of making this, that feels like a workaround. Said that, if there are no alternatives for fixing an important issue, this can be merged since it doesn't cause any conflict with existing code. |
Yes this is a workaround because we can't change We can make a list for the stuff we should fix / break for pion 5, This seems like a good fit! |
Yes. Full fix also requires change to pion/srtp, where padding has to be appended to payload before encryption. pion/srtp has to know padding size to do this. Public API has to be backward compatible, so this looked like a best approach.
Size fields usually are in protocol headers. But RTP was designed to be as compact as possible, so designers did not want to waste extra bytes to send packet size and padding size in RTP header. Using one bit to mark presence of padding and sending padding size in last byte of the packet allowed to reduce packet size, even that this approach is a bit hacky.
This would break public API, so this is something to consider for pion v5.0.x. I think that it should be changed to send RTP header and raw (marshaled) RTP packet in one struct. SRTP ciphers works with buffers, so having RTP packet as raw bytes would simplify things there. This is especially important for Cryptex (full header encryption, RFC 9335) support. There is already WebRTC extension defined for it, so after some time it will became part of the standard and browsers will start using it: https://w3c.github.io/webrtc-extensions/#rtp-header-extension-encryption BTW, I am going to implement Cryptex in pion/srtp. |
at-wat
left a comment
There was a problem hiding this comment.
LGTM!
Let's have a full fix in the next major update
| func (p Packet) MarshalSize() int { | ||
| return p.Header.MarshalSize() + len(p.Payload) + int(p.PaddingSize) | ||
| if p.PaddingSize > 0 && p.Header.PaddingSize == 0 { | ||
| p.Header.PaddingSize = p.PaddingSize |
There was a problem hiding this comment.
The function name looks like an immutable method but have a side effect. (Clone() as well)
I think it's reasonable for now but maybe better to note this as a godoc comment.
There was a problem hiding this comment.
Thanks. I have updated code to remove this side effect.
0b11247 to
94f42ec
Compare
Parts of pion code passes RTP header and payload via separate parameters instead of using Packet struct to pass them together. As a result value of padding size field may be lost. This change adds PaddingSize field to the Header struct and marks one in Packet as a deprecated. This is part of fix for pion/webrtc#2403 . Another change is needed for pion/srtp to resolve it fully.
94f42ec to
a8b82f7
Compare
|
@joeturki there are no new issues, are you ok with merging this? |
|
looks good to me, thank you for fixing this <3 |
|
Thanks! To fully fix this, I need to create two more PRs, for srtp and webtc. |
Parts of pion code passes RTP header and payload via separate parameters instead of using Packet struct to pass them together. As a result value of padding size field may be lost. This change adds PaddingSize field to the Header struct and marks one in Packet as a deprecated.
This is part of fix for pion/webrtc#2403 . Another change is needed for pion/srtp to resolve it fully.