forked from dmilstein/channels
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChannelsReliable.tla
28 lines (17 loc) · 1011 Bytes
/
ChannelsReliable.tla
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
---- MODULE ChannelsReliable ----
\* An implementation of the Channels abstraction that models perfectly reliable
\* channels (no dropped messages, no duplicates, order always preserved)
EXTENDS Integers, Sequences, TLC, ChannelsUtils
InitChannels(Clients) == InitChannelsWithInboxes([ c \in Clients |-> <<>> ])
HasMessage(C, client) == C.ClientInboxes[client] /= <<>>
\* Match interface of the other, more complex Channel implementations
Wrap(msg) == [ rawMsg |-> msg ]
AddToInbox(C, msg, receiver) == Append(C.ClientInboxes[receiver], Wrap(msg))
Send(C, sender, receiver, msg, msgLabel, senderState) ==
SendWithAdder(C, sender, receiver, msg, msgLabel, senderState, AddToInbox)
\* Always return the first message, but return a set to fit the overall interface
NextMessages(C, client) == {Head(C.ClientInboxes[client])}
RemoveOneCopy(msg, inbox) == Tail(inbox)
MarkMessageReceived(C, receiver, msg, receiverState) ==
MarkReceivedWithRemover(C, receiver, msg, receiverState, RemoveOneCopy)
=====