Asked directly by the owner, about his own cameras, from his phone's connection. The answer is physics and the product was not giving it. A camera lives on the shop's LAN behind a router. 192.168.1.121 means "something on the network I am attached to" and nothing more - from mobile data, a hotel or head office it resolves to nobody, or to a completely different device holding that number. There is no route in from the internet and there must not be: an RTSP camera reachable from outside is how a shop's cameras end up being watched by strangers. That is why the product is split the way it is - the shop PC is the only machine on the camera's LAN, and every other surface reaches it outbound, which is what makes Watch live work from anywhere while nothing connects in. What was wrong is the message. "cannot reach 192.168.1.121:554 - Operation timed out" reads as a broken camera and sends somebody to re-type an address and a password that were always correct. _wrong_network_hint names the cause and separates two states that need opposite actions: on that network -> check the camera is powered on and the address is right somewhere else -> the COMPUTER is in the wrong place; no setting fixes it - The local address comes from a connected UDP socket that sends nothing. It only fixes a route so the kernel will name the source address. - The LAN ranges are spelled out, not is_private. That property also covers carrier-grade NAT and the documentation networks, and telling somebody who typed 203.0.113.9 that it is "on the shop's own network" is a confident wrong answer in the place people look first. Found by a test using that address as its example of a PUBLIC one. - A DNS name gets no hint: nothing can be concluded about camera.local from the string, and guessing is the failure mode this message exists to fix. - With no network at all it still names the cause and drops the comparison, rather than claiming to know which network this machine is on. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KGcjxF1cNLcuwc3DAPcnfj
82 lines
3.1 KiB
Python
82 lines
3.1 KiB
Python
"""Why a camera "will not connect", when the real answer is that the computer
|
|
asking is in the wrong building.
|
|
|
|
Asked directly by the owner, about his own cameras, from his phone's
|
|
connection: *"when i connect from my mobile internet the cameras wont connect,
|
|
why is that"*. The answer was `cannot reach 192.168.1.121:554 - Operation
|
|
timed out`, which reads as a broken camera and sends somebody to re-type an
|
|
address and a password that were always correct.
|
|
"""
|
|
import pytest
|
|
|
|
from behavision import capture
|
|
|
|
|
|
@pytest.fixture
|
|
def on(monkeypatch):
|
|
def _set(ip):
|
|
monkeypatch.setattr(capture, "_local_ipv4", lambda: ip)
|
|
return _set
|
|
|
|
|
|
def test_a_different_network_says_so_and_says_what_to_do(on):
|
|
on("10.11.12.13") # a phone's tethered network
|
|
hint = capture._wrong_network_hint("192.168.1.121")
|
|
assert "not the camera's network" in hint
|
|
# The action, not just the diagnosis: no setting on this screen fixes it.
|
|
assert "computer in the shop" in hint
|
|
|
|
|
|
def test_the_same_network_sends_you_to_the_camera_instead(on):
|
|
on("192.168.1.120")
|
|
hint = capture._wrong_network_hint("192.168.1.121")
|
|
assert "on that network" in hint
|
|
assert "powered on" in hint
|
|
# Two states that need opposite actions must not share a sentence.
|
|
assert "not the camera's network" not in hint
|
|
|
|
|
|
@pytest.mark.parametrize("host", [
|
|
"8.8.8.8", # plainly routable
|
|
"203.0.113.9", # TEST-NET-3: `is_private` calls this private, and it is
|
|
# not a LAN address - which is why the check spells out
|
|
# the RFC1918 blocks instead of asking is_private
|
|
"100.64.0.5", # carrier-grade NAT, what a mobile network hands out
|
|
])
|
|
def test_an_address_that_is_not_a_lan_address_gets_no_hint(on, host):
|
|
"""A routable address unreachable from here is an ordinary network fault,
|
|
and inventing a story about private networks would be wrong."""
|
|
on("192.168.1.120")
|
|
assert capture._wrong_network_hint(host) == ""
|
|
|
|
|
|
def test_a_name_gets_no_hint(on):
|
|
"""Nothing can be concluded about `camera.local` from the string, and a
|
|
guess here is a confident wrong answer in the place people look first."""
|
|
on("192.168.1.120")
|
|
assert capture._wrong_network_hint("camera.local") == ""
|
|
|
|
|
|
def test_loopback_gets_no_hint(on):
|
|
on("192.168.1.120")
|
|
assert capture._wrong_network_hint("127.0.0.1") == ""
|
|
|
|
|
|
def test_with_no_network_at_all_it_still_names_the_cause(on):
|
|
"""A machine with no route cannot say which network it is on, and must not
|
|
pretend: the private-address fact is still true and still the reason."""
|
|
on("")
|
|
hint = capture._wrong_network_hint("192.168.1.121")
|
|
assert "private address" in hint
|
|
assert "this computer is on" not in hint
|
|
|
|
|
|
def test_the_hint_reaches_the_message_a_person_reads():
|
|
"""The whole point is the sentence on the screen, not a helper nobody
|
|
calls. Port 1 on a private address refuses or times out immediately."""
|
|
ok, msg = capture._tcp_reachable("rtsp://192.168.1.121:1/ch0", 1.0)
|
|
assert not ok
|
|
assert "192.168.1.121" in msg
|
|
# Whichever branch the OS takes, the explanation travels with it.
|
|
assert "network" in msg
|