Add TCP stream buffering to SessionInitiationProtocol - #61
Conversation
…_frame Co-authored-by: codingjoe <1772890+codingjoe@users.noreply.github.com> Agent-Logs-Url: https://github.com/codingjoe/VoIP/sessions/6938e2c0-d1ba-4740-8f03-50b5ed9a8b7b
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## transactions #61 +/- ##
===============================================
Coverage ? 87.66%
===============================================
Files ? 26
Lines ? 1954
Branches ? 0
===============================================
Hits ? 1713
Misses ? 241
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-authored-by: codingjoe <1772890+codingjoe@users.noreply.github.com> Agent-Logs-Url: https://github.com/codingjoe/VoIP/sessions/6d0e224a-c1c2-494c-ad1c-2e90bd633722
Done in 78daf19. Added |
data_received()assumed each TCP chunk was exactly one complete SIP message. TCP is a stream protocol — frames can be split across multiple deliveries or coalesced into one.Changes
recv_buffer: bytearray— accumulates raw bytes from the TCP stream acrossdata_received()callsPING/PONGconstants — module-leveltyping.Final[bytes]constants (b"\r\n\r\n"andb"\r\n") replace all scattered byte literals in the keepalive pathextract_frames()— generator that extracts complete frames from the buffer usingContent-Lengthheader framing (RFC 3261 §18.3); yields amemoryviewinto the buffer for each SIP message (zero-copy untilMessage.parseneedsbytes) and thePING/PONGconstants for keepalive frames; the view is explicitly released before the buffer is compacted; partial messages remain buffered until all bytes arrivedispatch_frame()— routes a single complete frame (memoryview | bytes) to the appropriate handler, converting tobytesonly at parse timedata_received()— appends torecv_bufferand iterates theextract_frames()generatorTests
39 new tests covering: split headers, split body, coalesced messages, all keepalive edge cases (partial PING, PONG-then-message, etc.), invalid
Content-Length, and end-to-enddata_receivedreassembly scenarios.💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.