fix(onvif): discovery correctness and reliability issues#61
Merged
Conversation
85190f8 to
f323757
Compare
**High:** - _discover_cameras_probe() is now wrapped in try/except OSError inside discover_cameras(). UDP multicast failures (getaddrinfo, socket creation, sendto, recvfrom) no longer abort the entire discovery pipeline; the subnet scan fallback now runs as documented. - _camera_info_from_probe_response() defaults HTTPS XAddr to port 443 and HTTP to port 80. Previously, https://host/path fell back to port 80, which caused RTSP resolution to probe the wrong ONVIF service. **Medium:** - _probe_rtsp_paths() no longer sends a fake Digest auth header. The malformed Authorization: Digest realm="", nonce="" string could trigger 400 Bad Request from strict RTSP servers, giving false negatives. We now do the first probe without auth and treat 401 as "path exists" per existing logic. - _get_local_ip() now prefers hostname resolution before falling back to UDP connect to 8.8.8.8. Isolated LANs and air-gapped networks without a default route can now discover cameras via subnet scan. **Smaller:** - WS-Discovery MessageID is now unique per probe (uuid.uuid4()) instead of a static string, reducing response caching issues on some cameras. - _name_from_scopes() uses urllib.parse.unquote() instead of only replacing %20, properly decoding all percent-encoded characters. - get_rtsp_uri() now logs exceptions via logging.getLogger(__name__).exception() instead of silently swallowing them. - Add 9 characterization tests covering probe fallback, HTTPS default port, RTSP request shape, exception logging, unique MessageID, unquote decoding, and hostname-based local IP discovery.
f323757 to
ebafc82
Compare
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
This PR fixes 6 correctness and reliability bugs in ONVIF discovery and RTSP resolution.
Fixes
discover_cameras()now wraps_discover_cameras_probe()intry/except OSError. Subnet scan runs on any UDP multicast failure._camera_info_from_probe_response()now inspectsurlparse(...).schemeand defaults HTTPS → 443, HTTP → 80.Digest realm="", nonce=""header, causing strict cameras to return 400 Bad Request (false negative)._probe_rtsp_paths()no longer sends auth on the first probe. 401 responses are still treated as "path exists"._get_local_ip()now prefers hostname resolution first, then falls back to the public DNS trick.uuid:trio-edge-discover.uuid.uuid4()MessageID.%20, not other percent-encoded characters._name_from_scopes()now usesurllib.parse.unquote().get_rtsp_uri()silently swallows all exceptions, making debugging impossible.logging.getLogger(__name__).exception().Tests
Added 9 characterization tests covering:
unquotescope decodingAll 15 tests pass. Lint and format checks pass.