Files
hms-mediaengine/packages/domain/hms_domain/ids.py
T
HMS MediaEngine Agent 0922cc1d68 Phase 0: Repository-Initialisierung nach Bauplan v1.2
- Struktur gemäß §8 (Eigentumsgrenzen), PLAN.md als normative Basis
- Pflichtdokumente: STATUS.md, ERRORS.md, TEST_REPORT.md, CHANGELOG.md, ADRs
- ADR-0001 Python 3.13-Pin, ADR-0002 GStreamer 1.28.6-Pin (Windows),
  ADR-0003 IPC TCP+MessagePack v1
- Kernpakete: hms_protocol, hms_domain, hms_parameter, hms_artnet,
  hms_adaptive, hms_capabilities, hms_plugin_sdk
- Renderer-Spike: D3D11-Primärpfad + Dev-GL-Pfad (§36 Nr. 4-5)
- Control Core: FastAPI REST + WebSocket (§36 Nr. 9)
- Beispielplugins: Passthrough + Gaussian Blur (3 Adaptive-Quality-
  Varianten, HLSL/GLSL/GLES)
- Tools: Art-Net-Emulator, Fixture-Generator (Master32/Layer64-CSV),
  Capability-Probe
- JSON-Schemas: IPC, Plugin, Projekt, Cluster
- 121 Unit-/Integrationstests grün, Ruff grün

Gate 0 bleibt offen: Hardwaremessungen nur auf echter Windows-Referenz-
hardware gültig (§29.7, §33).
2026-09-11 00:36:59 +02:00

54 lines
1.6 KiB
Python

"""Stabile IDs (PLAN.md §3.6, §10.1).
- UUIDs für alle Show-Objekte.
- Persistente node_id: einmal erzeugt, dauerhaft gespeichert; unabhängig
von IP-Adresse und Hostname (§6.3).
"""
from __future__ import annotations
import os
import uuid
from pathlib import Path
def new_uuid() -> str:
"""Stabile UUID für Show-Objekte (Layer, Effekte, Outputs, ...)."""
return str(uuid.uuid4())
def _machine_independent_seed() -> bytes:
"""Einstreu ohne IP/Hostname: OS-Urandom hat Priorität (§6.3)."""
return os.urandom(16)
def new_node_id() -> str:
"""Erzeugt eine neue, netzwerkunabhängige node_id (UUIDv4)."""
return str(uuid.UUID(bytes=_machine_independent_seed(), version=4))
def persistent_node_id(identity_file: Path) -> str:
"""Lädt die node_id aus identity_file oder erzeugt sie genau einmal.
IP-Wechsel ändern die node_id nicht; doppelte Vergabe über die Datei
wird durch exklusives Erzeugen (O_EXCL) verhindert.
"""
identity_file = Path(identity_file)
if identity_file.exists():
existing = identity_file.read_text(encoding="utf-8").strip()
if existing:
uuid.UUID(existing) # Validierung: muss UUID sein
return existing
identity_file.parent.mkdir(parents=True, exist_ok=True)
candidate = new_node_id()
try:
fd = os.open(identity_file, os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o600)
with os.fdopen(fd, "w", encoding="utf-8") as fh:
fh.write(candidate)
return candidate
except FileExistsError:
existing = identity_file.read_text(encoding="utf-8").strip()
if not existing:
raise
return existing