Skip to content
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

RID order guaranteed by avoiding iteration over a map #2840

Merged
merged 1 commit into from
Aug 1, 2024
Merged

RID order guaranteed by avoiding iteration over a map #2840

merged 1 commit into from
Aug 1, 2024

Conversation

j1elo
Copy link
Contributor

@j1elo j1elo commented Aug 1, 2024

Map iteration order is not guaranteed by Go, so it's an error to iterate over a map in places where maintaining the same ordering is important.

This change replaces the map of simulcastRid{} with an array of the same type. The simulcastRid{} type is extended to hold the rid-id which previously was used as the key in the map.

Accesses to the map are replaced with range loops to find the desired rid-id for each case.

Default code format applied.
Unit tests passed.

Fixes #2838

@j1elo
Copy link
Contributor Author

j1elo commented Aug 1, 2024

A comment to the side: I'm thinking that what the original code did (and it's still done by the changed code) is to present the RIDs in the same order as the a=rid lines are found, not strictly speaking in the order of the a=simulcast attribute.

However, I'm not sure if that'd be an actual problem. I know that theoretically RIDs should be treated or given in the order found in a=simulcast... but in practice, does this matter? I've yet to see an instance where the a=rid lines come in a different order than the order of a=simulcast.

Practical SDP Offer example for readers who might be confused:

m=video 9 UDP/TLS/RTP/SAVPF ...
a=rid:layer0 send
a=rid:layer1 send
a=rid:layer2 send
a=simulcast:send layer0;layer1;layer2

Copy link

codecov bot commented Aug 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.92%. Comparing base (35b3ae1) to head (db89908).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2840   +/-   ##
=======================================
  Coverage   78.91%   78.92%           
=======================================
  Files          89       89           
  Lines        8314     8317    +3     
=======================================
+ Hits         6561     6564    +3     
  Misses       1276     1276           
  Partials      477      477           
Flag Coverage Δ
go 80.51% <100.00%> (+<0.01%) ⬆️
wasm 64.88% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Map iteration order is not guaranteed by Go, so it's an error to iterate
over a map in places where maintaining the same ordering is important.

This change replaces the map of simulcastRid{} with an array of the same
type. The simulcastRid{} type is extended to hold the rid-id which
previously was used as the key in the map.

Accesses to the map are replaced with range loops to find the desired
rid-id for each case.

Fixes #2838
@Sean-Der Sean-Der merged commit cbbb1c2 into pion:master Aug 1, 2024
17 checks passed
@j1elo j1elo deleted the fix-rid-order branch August 1, 2024 15:04
@j1elo
Copy link
Contributor Author

j1elo commented Aug 1, 2024

Great! thanks for the lint fixes, and for the work merging this.
A couple questions:

  • Is the linter a default Go tool? I'd love to read more about it and see how to run it locally to avoid those naming mistakes in the future.
  • Will this change be backported to v3? EDIT: I just saw it cherry-picked on v3 so that answers this question :)

@Sean-Der
Copy link
Member

Sean-Der commented Aug 1, 2024

https://github.com/golangci/golangci-lint isn't a default Go tool, but is pretty popular! I don't know how I ended up on it.

I also added you to the org. Feel free to push tags and make branches w/e you need :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Undefined iteration order when parsing SDP RID ids
2 participants