Skip to content
Juvix imports

module arch.node.types.messages;

import prelude open public;
import arch.node.types.basics open;
import arch.node.types.crypto open;
import arch.node.types.identities open;

Messages and mailboxes

Types

A message is a piece of data dispatched from one engine, termed the sender, to another engine, referred to as the target. When a message is sent, it is enveloped with additional metadata such as the target address and potentially the sender address, in case the sender wants to be identified. Upon arrival at the target engine, the message is stored in the target engine's mailboxes. These mailboxes are indexed by an identifier that are only unique to their engine. If the target engine has only one mailbox, the mailbox identifier is redundant.

The following types are used to represent these messages and mailboxes.

EngineMsg

An engine message is a message between engines. It consists of a sender, a target, an optional mailbox identifier, and the message itself.

type EngineMsg M :=
mkEngineMsg@{
sender : EngineID;
target : EngineID;
mailbox : Option MailboxID;
msg : M;
};

EngineMsgID

An engine message identifier. The cryptographic hash of the corresponding EngineMsg.

syntax alias EngineMsgID := Digest;

Mailbox S

A mailbox is a container for engine messages and optionally a mailbox state. The mailbox state could be used to store additional information about the mailbox, such as the priority of the messages in the mailbox.

Where does mailbox state come from?

The mailbox state is related to the capabilities of mailboxes of the paper 1. In particular, at any given point in time, a mailbox will have a capability for receiving messages (in later versions of the specs). As mailbox state can be useful in general, we already have it now.

type Mailbox S M :=
mkMailbox@{
messages : List (EngineMsg M);
mailboxState : Option S;
};

MailboxID

A mailbox identifier is a natural number used to index mailboxes.

Where do mailbox identifiers come from?

The concept of mailbox identifier is taken from the paper 1 (see also Mailbox Cluster and 2).

syntax alias MailboxID := Nat;

Timer H

type Timer H :=
mkTimer@{
time : Time;
handle : H;
};

Trigger H

type Trigger H M :=
| MessageArrived@{msg : EngineMsg M}
| Elapsed@{timers : List (Timer H)};

TimestampedTrigger H

type TimestampedTrigger H M :=
mkTimestampedTrigger@{
time : Time;
trigger : Trigger H M;
};

  1. Simon Fowler, Duncan Paul Attard, Franciszek Sowul, Simon J. Gay, and Phil Trinder. Special delivery: programming with mailbox types. Proceedings of the ACM on Programming Languages, 7(ICFP):78–107, August 2023. URL: http://dx.doi.org/10.1145/3607832, doi:10.1145/3607832

  2. Shams M. Imam and Vivek Sarkar. Selectors: actors with multiple guarded mailboxes. AGERE! '14: Proceedings of the 4th International Workshop on Programming based on Actors Agents and Decentralized Control, October 2014. URL: http://dx.doi.org/10.1145/2687357.2687360, doi:10.1145/2687357.2687360