diff --git a/src/adn_server/domain/mesh_session.py b/src/adn_server/domain/mesh_session.py index 0a5acd0..b6cca17 100644 --- a/src/adn_server/domain/mesh_session.py +++ b/src/adn_server/domain/mesh_session.py @@ -239,7 +239,10 @@ class MeshSessionStore: return self._sessions.get(system_name) def session(self, system_name: str, sys_cfg: dict[str, Any] | None = None) -> ObpBridgeSession: - """The session for this system, created from its config on first use.""" + """The session for this system, created from its config on first use. + + Runs several times per datagram, so ``dns_host`` is left to ``sync``. + """ session = self._sessions.get(system_name) if session is None: session = ObpBridgeSession( @@ -250,7 +253,6 @@ class MeshSessionStore: self._sessions[system_name] = session elif sys_cfg is not None: session.configured_peer = _peer_from_config(sys_cfg) - session.dns_host = dns_host_from_config(sys_cfg) return session def drop(self, system_name: str) -> None: @@ -274,8 +276,13 @@ class MeshSessionStore: configured = _peer_from_config(sys_cfg) session = self._sessions.get(name) if session is None: - self._sessions[name] = ObpBridgeSession(system_name=name, configured_peer=configured) + self._sessions[name] = ObpBridgeSession( + system_name=name, + configured_peer=configured, + dns_host=dns_host_from_config(sys_cfg), + ) continue + session.dns_host = dns_host_from_config(sys_cfg) if session.configured_peer != configured: session.configured_peer = configured session.forget_learned_peer() diff --git a/tests/domain/test_mesh_session.py b/tests/domain/test_mesh_session.py index 8949c4b..a650d7e 100644 --- a/tests/domain/test_mesh_session.py +++ b/tests/domain/test_mesh_session.py @@ -277,6 +277,25 @@ def test_sync_registers_enabled_openbridges_only() -> None: assert len(store) == 1 +def test_sync_anchors_a_session_it_creates() -> None: + """Missing it here loses DNS anchoring silently: nothing else derives it.""" + config = _config(_TARGET_IP="peer.example.net") + store = MeshSessionStore() + store.sync(config) + assert store.session("OBP-FR").dns_host == "peer.example.net" + + +def test_sync_anchors_a_session_that_already_existed() -> None: + config = _config() + store = MeshSessionStore() + store.sync(config) + assert store.session("OBP-FR").dns_host is None + + config["SYSTEMS"]["OBP-FR"]["_TARGET_IP"] = "peer.example.net" + store.sync(config) + assert store.session("OBP-FR").dns_host == "peer.example.net" + + def test_a_reload_that_moves_the_peer_wins_over_what_was_learned() -> None: """Editing TARGET_IP in the YAML is the way out of a bad learned address.""" config = _config()