Repository navigation
feat(session): per-call max_payload_bytes and max_blocks on get() - #131
Conversation
get() always reassembled under the accumulator's default 64 KiB cap, and BLOCK2 and SIZE2 are managed options, so a caller had no way to read a larger representation at any timeout. A file listed under /file/list/vs/0 and served by /file/transfer/vs/0 is one such read, reported through localthings. Block2Accumulator already takes max_payload_bytes. get() now does too, keyword-only, and passes it through _blockwise_get to both attempts of _blockwise_get_once, so an ETag restart keeps the caller's cap. None, the default, leaves the accumulator's own default in place. Nothing else calls _blockwise_get with it, so the Observe refetch is unchanged. A bool, a non-int, or a value <= 0 raises before anything is sent: TypeError for the type, ValueError for the range, the same split get() already uses for extra_options. On its own this does not carry a transfer past 64 KiB. MAX_BLOCKS is the default byte cap in 1024-byte blocks, so the block count stops the transfer at the same point unless a subclass raises it. The tests pin that as well as the subclass route.
The block count is the second cap, and with small blocks it is the one that ends a transfer. MAX_BLOCKS is 64, derived from 1024-byte blocks. A server that answers block 0 at 1024 bytes and then advertises SZX 2 delivers 64-byte blocks after it, and the 64th block arrives at about 5 KB, far inside any byte cap. The device log in the localthings report is consistent with that shape; it was not measured here. get() now takes max_blocks beside max_payload_bytes, keyword-only and validated the same way. None keeps self.MAX_BLOCKS, so a subclass override still applies. The two stay independent: neither is derived from the other or from the negotiated SZX, and raising one leaves the other at its default. Both are threaded to the ETag restart. This is separate from the previous commit so it can be dropped on its own.
|
@QuiteYellow This is what we talked about in mbillow/localthings#659. Let me know if you have any feedback! |
|
Thanks @mbillow, I'll run an automated review then take a look properly over the next few days. |
QuiteYellow-reviewer
left a comment
There was a problem hiding this comment.
Automated review at 07a1e97.
Not run: no local build or test run. CI passes on all 8 checks.
One documentation point, inline. No code defects found. The validation, the None defaults, the ETag restart path and the unchanged Observe refetch path all match the PR description.
|
Thanks for this. Merging as it stands. On the question in the description: keep the split. It matches what I'll follow up with a small docs-only PR: the docstring will say that |
Follows up on mbillow/localthings#659 (comment).
An appliance lists files on
/file/list/vs/0and serves them as a Block2 transfer from/file/transfer/vs/0. The fixed reassembly caps stop that transfer.BLOCK2/SIZE2are managed options, so the caller can't fetch the blocks itself, at any timeout.What this does
DtlsCoapSession.get()gets two keyword-only arguments, both defaulting toNone:max_payload_bytes: the assembled-byte cap.Nonekeeps the accumulator's default (MAX_BLOCK2_PAYLOAD_BYTES).max_blocks: the block-count cap.Nonekeepsself.MAX_BLOCKS, so a subclass override still applies.Both are passed through
_blockwise_getto both_blockwise_get_onceattempts, so an ETag restart keeps the caller's caps, and intoBlock2Accumulator. No other caller passes them, so the Observe refetch path is unchanged. Defaults,BLOCK_SZX,_BLOCK_MAX_ATTEMPTS,_BLOCK_ACK_TIMEOUTand the timeout semantics are unchanged too.A
bool, a non-int, or a value ≤ 0 raises inget()before a token is minted or a datagram sent. Type problems raiseTypeErrorand range problems raiseValueError, the same splitget()already uses forextra_options. The accumulator itself raisesValueErrorfor both. I followedget()'s convention; say if you'd rather match the accumulator.Two changes
max_payload_bytes: what you agreed to in the thread.max_blocks: an addition you haven't agreed to, but I think may be needed.MAX_BLOCKSis 64, which is the 64 KiB byte cap in 1024-byte blocks. So at 1 KiB blocks the two caps are the same limit, and raisingmax_payload_bytesalone doesn't carry a transfer past 64 KiB. The block count stops it at the same point (test_max_payload_bytes_alone_stops_at_the_default_block_cap). With commit 1 alone, a caller also needs a subclass that raisesMAX_BLOCKS. That works and is tested, but it's per-session and not per-call.With small blocks it's worse. If a server answers block 0 at 1024 bytes and then advertises SZX 2, the 64th block arrives at about 5 KB, whatever the byte cap is. The device log in the localthings report looks like that pattern (32–64 B blocks after the first one), but I haven't measured it here. The tests use a fake device with that pattern and don't describe any appliance.
Tests
New file
tests/test_get_block2_limits.py(30 tests). It uses the synchronous fake device fromtest_block2_get_cap.py, extended to downshift after block 0 and to change ETag on the first transfer. It covers:MAX_BLOCKSapplies whenmax_blocksisNone.True,0,-1,"1024"and1.5for each argument raise before any datagram is sent or token is minted.get().I checked that the tests catch mistakes. Dropping the caps from the ETag-restart call fails
test_etag_restart_uses_the_callers_block_cap. UsingMAX_BLOCK2_BLOCKSin place ofself.MAX_BLOCKSfails the two subclass tests.maingives the same 49 warnings.docs/api.mdwas regenerated withtools/generate_api_docs.py.