Repository navigation
Conversation
The TURN Data Indication handler built a CUtlVector of every STUN attribute just to find the XOR-PEER-ADDRESS and DATA attributes, which allocates on every relayed packet. Walk the attributes directly instead, capturing the first match of each, and stop at the same early-out points ParseSTUNAttributes uses when called without a key (bad fingerprint, or any message-integrity attribute). The result is unchanged; the other vector-based call sites are untouched.
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.
WriteGenericSTUNAttribute's caller on the TURN Data Indication path built aCUtlVector<STUNAttribute>just to find the XOR-PEER-ADDRESS and DATA attributes, heap-allocating on every relayed packet. This walks the attributes directly instead, capturing the first match of each, and stops at the same early-out pointsParseSTUNAttributesuses when called without a key (bad fingerprint, or any message-integrity attribute). The accept/reject behavior is unchanged; other vector-based call sites in this file are untouched.Verification
Correctness —
test_cryptoandtest_p2p.pypass, including the TURN-relay-specific cases (symmetric NAT (requires TURN relay),relay via LAN TURN,TURN allocation refresh), run 3x clean with no flakes under ASan+UBSan.The actual fix — measured directly, not just asserted. I added a scratch benchmark hook that calls the real
OnPacketReceivedin-process with one synthetic TURN Data Indication packet, N times, under a process-wide malloc/calloc/realloc counter, built identically against master and against this branch:Exactly 1 allocation/call on master (the vector growing from empty), exactly 0 on this branch, at both scales.