Federation-Node / node_record.py
Kode-Animator's picture
Phase 1A: Modular Node Conformance
e61e751
Raw
History Blame Contribute Delete
3.17 kB
"""
Federation Node β€” NodeRecord Builder
======================================
Contract: C-FED-NODE-001 v0.1.1
Generates the NodeRecord (Β§4), capability advertisement (Β§6),
conformance declaration (Β§12.3), and trust posture (Β§7).
"""
from __future__ import annotations
from datetime import datetime, timezone
# ─── Constants ───
NODE_VERSION = "0.2.0"
CONTRACT_VERSION = "C-FED-NODE-001 v0.1.1"
PROTOCOL_VERSION = "1.0.0"
# Accepted message classes (Phase 1A)
ACCEPTED_MESSAGE_CLASSES = [
"HANDSHAKE_REQUEST",
"HANDSHAKE_RESPONSE",
"THOUGHT",
"PROPOSAL",
"ARTIFACT_TRANSFER",
"HEARTBEAT",
"REFUSAL",
"STATUS_UPDATE",
]
MAX_PAYLOAD_BYTES = 5_242_880 # 5 MB
INBOX_QUOTA = 1000
# ─── Builders ───
def build_capabilities() -> dict:
"""Build the capabilities advertisement per C-FED-NODE-001 Β§6."""
return {
"protocol_versions": [PROTOCOL_VERSION],
"accepted_message_classes": ACCEPTED_MESSAGE_CLASSES,
"accepted_content_types": ["text/markdown", "application/json"],
"max_payload_bytes": MAX_PAYLOAD_BYTES,
"supports_witnessing": True,
"supports_delegation": False, # Phase 3
"supports_registry": False, # Phase 2
"rate_limits": {
"envelopes_per_minute": 30,
"envelopes_per_hour": 500,
},
"inbox_quota": INBOX_QUOTA,
}
def build_conformance() -> dict:
"""Build conformance declaration per C-FED-NODE-001 Β§12.3."""
return {
"contract": "C-FED-NODE-001",
"version": "0.1.1",
"level": "minimum",
"extensions": ["witnessing"],
}
def build_trust_posture(default_action: str, blocked_behavior: str) -> dict:
"""Build the public trust posture per C-FED-NODE-001 Β§4."""
return {
"default_action": default_action,
"accepts_registry_known": True,
"accepts_delegation": False, # Phase 3
"blocked_behavior": blocked_behavior,
"trust_graph_public": False,
}
def build_node_record(
*,
node_identity,
alias: str,
owner: str,
relay_url: str,
roles: list[str],
default_action: str,
blocked_behavior: str,
boot_time: str,
) -> dict:
"""Build the full NodeRecord per C-FED-NODE-001 Β§4."""
return {
"identity": {
"glyph_seal": str(node_identity),
"public_key": None, # Phase 3: Ed25519
"alias": alias,
"owner_display_name": owner or None,
},
"endpoints": {
"relay_url": relay_url or None,
"registry_url": None, # Phase 2
"capabilities_url": f"{relay_url}/capabilities" if relay_url else None,
},
"capabilities": build_capabilities(),
"roles": roles,
"trust_posture": build_trust_posture(default_action, blocked_behavior),
"metadata": {
"node_version": NODE_VERSION,
"contract_version": CONTRACT_VERSION,
"protocol_version": PROTOCOL_VERSION,
"registered_at": boot_time,
"last_seen": datetime.now(timezone.utc).isoformat(),
},
}