Files
NODEDC_MISSION_CORE/src/k1link/fleet/heartbeat_encoding.py
T
DCCONSTRUCTIONS e06ff9a214 feat(fleet): add shared WireGuard profiles and bounded rover transport
Add portable shared WireGuard profiles while retaining Tailscale and Worker boundaries. Bound rover command/telemetry delivery, recovery and diagnostic capture across Core and Node.
2026-10-29 09:10:01 +03:00

22 lines
797 B
Python

"""Bounded, negotiated compression for the existing full Node heartbeat."""
import zlib
MAX_HEARTBEAT_BYTES = 8 * 1024 * 1024
def decode_heartbeat(body: bytes, encoding: str, path: str) -> bytes:
if not encoding:
return body
if encoding != "gzip" or path != "/v1/node/heartbeat":
raise ValueError("Unsupported encoding")
try:
stream = zlib.decompressobj(16 + zlib.MAX_WBITS)
decoded = stream.decompress(body, MAX_HEARTBEAT_BYTES + 1)
if (len(decoded) > MAX_HEARTBEAT_BYTES or not stream.eof
or stream.unused_data or stream.unconsumed_tail):
raise ValueError("Invalid compressed heartbeat")
return decoded
except zlib.error as error:
raise ValueError("Invalid compressed heartbeat") from error