Section Shared.
Definition Label := [ordType of nat].
(* (Heterogenious) messages are parametrized by  - lab   - protocol Label - ptype - protocol, defining the content type - content  - the contents of the message - from/to  - IDs of the sender.receiver node - active - a bit, indicating whether the message hasn't been consumed yet (i.e., read)  I'm not sure, if we're going to need anything else. *)
Structure msg (mtype : Type) :=
Msg {content  : mtype;
from     : nat;
to       : nat;
active   : bool }.
(* Message IDs: pairs Label * id, where Label comes from the protocol. *)
Definition mid := [ordType of nat].
(* Message soup (for a specific protocol) is just a partial finite map from message IDs (mid) to arbitrary Messages. *)
Definition soup : Type :=
union_map mid (msg (TaggedMessage)).
Variables (s: soup) (V: valid s).
(* Allocating new message in the soup *)
Definition post_msg m : soup * mid :=
let: f := fresh s in (s \+ f \\-> m, f).

Lemma post_valid m :  valid (post_msg m).1.