Merge pull request #92 from Amateur-Digital-Network/perf/obp-session-lookup

perf(obp): derive a bridge's dns_host on reload, not on every lookup
pull/93/head
ce5rpy 7 days ago committed by GitHub
commit 27a0a1031c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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()

@ -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()

Loading…
Cancel
Save

Powered by TurnKey Linux.