Fix: Standardize Stream Ordering to Prevent Swarm Pollution#499
Draft
DimaDemchenko wants to merge 1 commit intomainfrom
Draft
Fix: Standardize Stream Ordering to Prevent Swarm Pollution#499DimaDemchenko wants to merge 1 commit intomainfrom
DimaDemchenko wants to merge 1 commit intomainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a critical issue where P2P peers were unable to share segments due to mismatched stream IDs caused by randomized manifest ordering from the CDN.
The Problem
Our current demo manifest URL returns live stream qualities in a randomized order. This appears to be a load-balancing optimization on the AWS/CDN side (likely to distribute the "default" quality selection across users).
Our P2P core relies on the index of the stream to identify and share segments.
Example Scenario:
If User A tries to share a segment from Stream ID 0 (720p), User B rejects it because their Stream ID 0 expects 360p content. This effectively fragments the P2P swarm, isolating users who received different manifest orders.
The Fix
We now enforce a consistent, standardized order for all streams on the client side, regardless of the random order sent by the server.
Before registering streams with the P2P engine, we sort them using a strict rule:
This guarantees that "Stream 0" always maps to the exact same video quality for every user in the swarm, ensuring they can successfully share segments even if their manifest files looked different initially.