Repository navigation
Fragment outbound UCI control packets in Python host - #150
Conversation
Host.send_control previously serialized UCI control packets into a single frame without fragmentation. Control payloads exceeding the 255-byte UCI payload limit, such as multicast list updates containing multiple extended subsession keys, overflowed the single-byte length field and failed transmission. Segment serialized control payloads into 255-byte chunks, set the Packet Boundary Flag on intermediate frames, and add test coverage exercising multicast list updates across packet boundaries.
There was a problem hiding this comment.
Code Review
This pull request implements packet fragmentation for UCI control packets in the send_control method, splitting payloads larger than 255 bytes into multiple fragments with the appropriate Packet Boundary Flag (PBF). It also adds a test case in tests/ranging.py to validate this fragmentation behavior. The review feedback recommends adding defensive checks to ensure the packet is not null and has a minimum length of 4 bytes to prevent potential runtime errors.
| raw = packet.serialize() | ||
| chunks = [raw[i : i + 255] for i in range(4, len(raw), 255)] or [b""] |
There was a problem hiding this comment.
Add defensive checks to ensure that the input packet is not None and that the serialized packet is at least 4 bytes long (the minimum size of a valid UCI control packet header). This prevents potential AttributeError and IndexError crashes during serialization and fragmentation.
| raw = packet.serialize() | |
| chunks = [raw[i : i + 255] for i in range(4, len(raw), 255)] or [b""] | |
| if packet is None: | |
| raise ValueError("Packet cannot be None") | |
| raw = packet.serialize() | |
| if len(raw) < 4: | |
| raise ValueError(f"Control packet must be at least 4 bytes, got {len(raw)}") | |
| chunks = [raw[i : i + 255] for i in range(4, len(raw), 255)] or [b""] |
There was a problem hiding this comment.
The test client methods receive typed PDL packet instances that serialize to valid UCI headers; defensive type checks aren't used elsewhere in Host and would add unreached branches to test code.
Host.send_control previously serialized UCI control packets into a single frame without fragmentation. Control payloads exceeding the 255-byte UCI payload limit, such as multicast list updates containing multiple extended subsession keys, overflowed the single-byte length field and failed transmission.
Segment serialized control payloads into 255-byte chunks, set the Packet Boundary Flag on intermediate frames, and add test coverage exercising multicast list updates across packet boundaries.