refactor(webrtc): deduplicate _varint.py β use libp2p.utils.varint#1379
Open
yashksaini-coder wants to merge 2 commits into
Open
refactor(webrtc): deduplicate _varint.py β use libp2p.utils.varint#1379yashksaini-coder wants to merge 2 commits into
yashksaini-coder wants to merge 2 commits into
Conversation
Deletes libp2p/transport/webrtc/_varint.py and migrates stream.py and signaling.py to import from the shared libp2p.utils.varint utilities: - encode_uvarint (identical algorithm, both files) - decode_varint_with_size (same (value, consumed) tuple, replaces decode_uvarint in stream.py) - decode_uvarint_from_stream (byte-by-byte async reader, replaces the private _read_uvarint in signaling.py; error wrapping in read_signaling_message preserves WebRTCSignalingError at call sites) Updates three test files to import the canonical utilities directly. No wire-format or protocol change. Closes libp2p#1355.
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.
Summary
Closes #1355.
PR #1309 added
libp2p/transport/webrtc/_varint.pywithencode_uvarintanddecode_uvarintfor WebRTC data-channel and signaling framing. The same unsigned LEB128 logic already exists inlibp2p/utils/varint.py, used by mplex, msgio, identify, and others.This PR:
libp2p/transport/webrtc/_varint.pystream.py: importsencode_uvarint+decode_varint_with_sizefromlibp2p.utils.varintβ the latter returns the same(value, consumed)tuple shape, making it a 1:1 replacementsignaling.py: importsencode_uvarint+decode_uvarint_from_streamfromlibp2p.utils.varintβ replaces the private_read_uvarinthelper (functionally identical byte-by-byte reader); error wrapping inread_signaling_messagepreservesWebRTCSignalingErrorat call siteslibp2p.utils.varintdirectlyNo wire-format or protocol change. Pure refactor.
Why it's safe
_varint.pylibp2p.utils.varintencode_uvarint(v)encode_uvarint(v)β identical algorithm (>0x7Fβ‘>=0x80)decode_uvarint(data) β (value, consumed)decode_varint_with_size(data) β (value, consumed)β same tuple_read_uvarint(stream)decode_uvarint_from_stream(reader)β same byte-by-byte loop;INetStreamis aReaderTest plan
tests/core/transport/webrtc/)1355.internal.rstadded