distribute/handshake/negotiation

Values

pub fn protocol_negotiate(
  local_caps: List(capability.Capability),
  remote_caps: List(capability.Capability),
  protocol: String,
) -> option.Option(Int)

Find the highest compatible version for a protocol given local and remote capabilities. Returns Some(version) if a compatible version exists in the overlapping range, None if the protocol is not supported by both sides or ranges don’t overlap.

Algorithm

  1. Find capability for protocol in local capabilities
  2. Find capability for protocol in remote capabilities
  3. If both exist, compute overlap: max(local.min, remote.min) to min(local.max, remote.max)
  4. If overlap is valid (min <= max), return the max version of the overlap
  5. Otherwise return None
pub fn schema_decode_from_node(
  registry: process.Subject(actor.RegistryCommand),
  timeout_ms: Int,
  node_id: String,
  protocol: String,
  schemas: List(codec.Schema(a)),
  binary: BitArray,
) -> Result(a, String)

Decode a value from a specific node using the negotiated version.

Similar to schema_encode_for_node, but for decoding. Looks up the negotiated version and uses the appropriate schema decoder.

pub fn schema_encode_for_node(
  registry: process.Subject(actor.RegistryCommand),
  timeout_ms: Int,
  node_id: String,
  protocol: String,
  schemas: List(codec.Schema(a)),
  value: a,
) -> Result(BitArray, String)

Encode a value for a specific node using the negotiated version.

This function looks up the negotiated version for the given protocol from the registry, selects the appropriate schema version, and encodes the value.

Parameters

  • registry: The registry actor subject to lookup negotiated versions
  • timeout_ms: Timeout for registry lookup in milliseconds
  • node_id: Target node identifier
  • protocol: Protocol name to use for version lookup
  • schemas: List of available schemas for this protocol, ordered by version
  • value: The value to encode

Returns

  • Ok(binary) with encoded data using the negotiated schema
  • Error(reason) if negotiation info not found or encoding fails
pub fn validate_capabilities(
  caps: List(capability.Capability),
) -> Result(Nil, String)

Validate that a list of capabilities is well-formed. Returns Ok(Nil) if all capabilities have min <= max and non-empty protocol names. Returns Error(reason) if any capability is invalid.

Search Document