Skip to content

ICE: Avoid heap allocation per TURN Data Indication - #480

Open
smhussa22 wants to merge 1 commit into
ValveSoftware:masterfrom
smhussa22:ice-turn-data-indication-no-alloc
Open

smhussa22 wants to merge 1 commit into
ValveSoftware:masterfrom
smhussa22:ice-turn-data-indication-no-alloc

Conversation

@smhussa22

Copy link
Copy Markdown

There was a TODO in the TURN Data Indication handler in the steamnetworkingsockets_ice_client.cpp file about avoiding a heap allocation per packet.

It was building a CUtlVector of every STUN attribute just to find XOR-PEER-ADDRESS and DATA.
The change I applied to fix this heap allocation per packet was to walk the attributes in place and keep the first match of each, stopping early once both are found.
It also stops at the same points ParseSTUNAttributes does when called with no key, so the same packets get accepted or dropped as before.

To avoid duplicating the fingerprint check, I moved it into a small helper. It is called BCheckFingerprint, that both paths use. I also added the fingerprint XOR value as a constant k_nSTUN_FingerprintXOR in the header, similar to how k_nSTUN_CookieValue is already defined there. I didn't see any rules prohibiting this in code style, and thus I made this change as other constants were already doing so, please let me know if this is incorrect.

test_crypto and test_p2p.py pass, including the TURN relay cases. I also ran the full test_p2p.py suite under heaptrack on master and on this branch. On master there were 1,692 allocations from the Data Indication handler, all from the CUtlVector behind the ParseSTUNAttributes call. With this change there are none.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant