macula_protocol behaviour (macula v0.20.5)
View SourceBehaviour defining the protocol that Macula mesh applications must implement.
Overview
This behaviour defines the contract that applications must implement to be considered "mesh-worthy" and allowed to participate in the Macula mesh network. The gatekeeper validates that apps implement this protocol before granting mesh access.
Why This Matters
Not every container or process should be allowed to join the mesh. This protocol ensures that: - Apps have proper identity (backed by certificates) - Apps declare their capabilities upfront - Apps can receive mesh events - Apps can be health-checked during sessions
Implementation
BEAM apps implement this as a behaviour. The implementation must export: - mesh_identity/0 - Returns the app's identity binary - mesh_capabilities/0 - Returns list of capabilities - mesh_api/0 - Returns map of topics, procedures, content_types - handle_mesh_event/2 - Handles incoming events - mesh_health/0 - Returns ok or error tuple
Non-BEAM apps implement equivalent gRPC or HTTP endpoints that the gatekeeper can probe.
Security Model
1. Identity must match the certificate's subject 2. Capabilities are validated against licenses at operation time 3. Health checks run periodically during sessions 4. Failed health checks may result in session termination
See also: macula_gatekeeper.
Summary
Functions
Checks if a capability is valid.
Validates that an API spec is well-formed.
Validates that capabilities list is valid.
Validates that an identity is well-formed.
Types
Callbacks
-callback mesh_api() -> api_spec().
-callback mesh_capabilities() -> [capability()].
-callback mesh_health() -> health_status().
-callback mesh_identity() -> identity().
Functions
Checks if a capability is valid.
Validates that an API spec is well-formed.
-spec validate_capabilities([capability()]) -> ok | {error, term()}.
Validates that capabilities list is valid.
Validates that an identity is well-formed.
Valid identities: - Are non-empty binaries - Contain at least 3 dot-separated segments - Each segment contains only alphanumeric characters and hyphens