Typo in procedure call for checks on slots
[iotcloud.git] / doc / iotcloud.tex
1 \documentclass[11pt]{article}\r
2 \newcommand{\tuple}[1]{\ensuremath \langle #1 \rangle}\r
3 \usepackage{color}\r
4 \usepackage{amsthm}\r
5 \usepackage{amsmath}\r
6 \usepackage{graphicx}\r
7 \usepackage{mathrsfs}\r
8 \usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx\r
9 \usepackage[all]{xy}\r
10 \newtheorem{theorem}{Theorem}\r
11 \newtheorem{prop}{Proposition}\r
12 \newtheorem{lem}{Lemma}\r
13 \newtheorem{defn}{Definition}\r
14 \newcommand{\note}[1]{{\color{red} \bf [[#1]]}}\r
15 \newcommand{\push}[1][1]{\hskip\dimexpr #1\algorithmicindent\relax}\r
16 \begin{document}\r
17 \section{Approach}\r
18 \r
19 \subsection{Keys}\r
20 \r
21 Each device has: user id + password\r
22 \r
23 Server login is:\r
24 hash1(user id), hash1(password)\r
25 \r
26 Symmetric Crypto keys is:\r
27 hash2(user id | password)\r
28 \r
29 Server has finite length queue of entries + max\_entry\_identifier +\r
30 server login key\r
31 \r
32 \subsection{Entry layout}\r
33 Each entry has:\r
34 \begin{enumerate}\r
35 \item Sequence identifier\r
36 \item Random IV (if needed by crypto algorithm)\r
37 \item Encrypted payload\r
38 \end{enumerate}\r
39 \r
40 Payload has:\r
41 \begin{enumerate}\r
42 \item Sequence identifier\r
43 \item Machine id (most probably something like a 64-bit random number \r
44 that is self-generated by client)\r
45 \item HMAC of previous slot\r
46 \item Data entries\r
47 \item HMAC of current slot\r
48 \end{enumerate}\r
49 \r
50 A data entry can be one of these:\r
51 \begin{enumerate}\r
52 \item All or part of a Key-value entry\r
53 \item Slot sequence entry: Machine id + last message identifier \r
54 \newline {The purpose of this is to keep the record of the last slot \r
55 from a certain client if a client's update has to expunge that other \r
56 client's last entry from the queue. This is kept in the slot until \r
57 the entry owner inserts a newer update into the queue.}\r
58 \item Queue state entry: Includes queue size \newline {The purpose \r
59 of this is for the client to tell if the server lies about the number \r
60 of slots in the queue, e.g. if there are 2 queue state entry in the queue, \r
61 e.g. 50 and 70, the client knows that when it sees 50, it should expect \r
62 at most 50 slots in the queue and after it sees 70, it should expect \r
63 50 slots before that queue state entry slot 50 and at most 70 slots. \r
64 The queue state entry slot 70 is counted as slot number 51 in the queue.}\r
65 \item Collision resolution entry: message identifier + machine id of a\r
66 collision winner\r
67 \newline {The purpose of this is to keep keep track of the winner of \r
68 all the collisions until all clients have seen the particular entry.}\r
69 \end{enumerate}\r
70 \r
71 \subsection{Live status}\r
72 \r
73 Live status of entries:\r
74 \begin{enumerate}\r
75 \item Key-Value Entry is dead if either (a) there is a newer key-value pair or (b) it is incomplete.\r
76         \r
77 \item Slot sequence number (of either a message version data\r
78 or user-level data) is dead if there is a newer slot from the same machine.\r
79 \r
80 \item Queue state entry is dead if there is a newer queue state entry.\r
81 {In the case of queue state entries 50 and 70, this means that queue state \r
82 entry 50 is dead and 70 is live. However, not until the number of slots reaches \r
83 70 that queue state entry 50 will be expunged from the queue.}\r
84 \r
85 \item Collision resolution entry is dead if this entry has been seen\r
86 by all clients after a collision happens.\r
87 \end{enumerate}\r
88 \r
89 When data is at the end of the queue ready to expunge, if:\r
90 \begin{enumerate}\r
91 \item The key-value entry is not dead, it must be reinserted at the\r
92 beginning of the queue.\r
93 \r
94 \item If the slot sequence number is not dead, then a message sequence\r
95 entry must be inserted.\r
96 \r
97 \item If the queue state entry is not dead, it must be reinserted at the\r
98 beginning of the queue.\r
99 \end{enumerate}\r
100 \r
101 \r
102 \paragraph{Reads:}\r
103 Client sends a sequence number.  Server replies with either: all data\r
104 entries or all newer data entries.\r
105 \r
106 \paragraph{Writes:}\r
107 Client sends slot, server verifies that sequence number is valid,\r
108 checks entry hash, and replies with an accept message if all checks\r
109 pass.  On success, client updates its sequence number.  On failure,\r
110 server sends updates slots to client and client validates those slots.\r
111 \r
112 \paragraph{Local state on each client:}\r
113 A list of machines and the corresponding latest sequence numbers.\r
114 \r
115 \paragraph{Validation procedure on client:}\r
116 \begin{enumerate}\r
117 \item Decrypt each new slot in order.\r
118 \item For each slot:\r
119     (a) check its HMAC, and\r
120     (b) check that the previous entry HMAC field matches the previous\r
121     entry.\r
122 \item Check that the last-message entry for our machine matches the stored HMAC of our last message sent.\r
123 \item For all other machines, check that the latest sequence number is\r
124 at least as large (never goes backwards).\r
125 \item That the queue has a current queue state entry.\r
126 \item That the number of entries received is consistent with the size\r
127 specified in the queue state entry.\r
128 \end{enumerate}\r
129 \r
130 Key-value entries can span multiple slots.  They aren't valid until\r
131 they are complete.\r
132 \r
133 \subsection{Resizing Queue}\r
134 Client can make a request to resize the queue. This is done as a write that combines:\r
135   (a) a slot with the message, and (b) a request to the server. The queue can only be expanded, never contracted; attempting to decrease the size of the queue will cause future clients to throw an error.\r
136 \r
137 \subsection{Server Algorithm}\r
138 $s \in SN$ is a sequence number\\\r
139 $sv \in SV$ is a slot's value\\\r
140 $slot_s = \tuple{s, sv} \in SL \subseteq SN \times SV$ \\ \\\r
141 \textbf{State} \\\r
142 \textit{SL = set of live slots on server} \\\r
143 \textit{max = maximum number of slots (input only for resize message)} \\\r
144 \textit{n = number of slots} \\ \\\r
145 \textbf{Helper Function} \\\r
146 $MaxSlot(SL_s)= \tuple{s, sv} \mid \tuple{s, sv}\r
147 \in SL_s \wedge \forall \tuple{s_s, sv_s} \in SL_s, s \geq s_s$ \\\r
148 $MinSlot(SL_s)= \tuple{s, sv} \mid \tuple{s, sv} \r
149 \in SL_s \wedge \forall \tuple{s_s, sv_s} \in SL_s, s \leq s_s$ \\\r
150 $SeqN(slot_s = \tuple{s, sv})=s$ \\\r
151 $SlotVal(slot_s = \tuple{s, sv})=sv$ \\\r
152 \r
153 \begin{algorithmic}[1]\r
154 \Function{GetSlot}{$s_g$}\r
155 \State \Return{$\{\tuple{s, sv} \in SL \mid s \geq s_g\}$}\r
156 \EndFunction\r
157 \end{algorithmic}\r
158 \r
159 \begin{algorithmic}[1]\r
160 \Function{PutSlot}{$s_p,sv_p,max'$}\r
161 \If{$(max' \neq \emptyset)$}  \Comment{Resize}\r
162 \State $max \gets max'$\r
163 \EndIf\r
164 \State $\tuple{s_n,sv_n} \gets MaxSlot(SL)$\Comment{Last sv}\r
165 %\State $s_n \gets SeqN(\tuple{s_n,sv_n})$\r
166 \If{$(s_p = s_n + 1)$}\r
167         \If{$n = max$}\r
168         \State $\tuple{s_m,sv_m} \gets MinSlot(SL)$\Comment{First sv}\r
169                 \State $SL \gets SL - \{\tuple{s_m,sv_m}\}$\r
170         \Else \Comment{$n < max$}\r
171                 \State $n \gets n + 1$\r
172         \EndIf\r
173     \State $SL \gets SL \cup \{\tuple{s_p,sv_p}\}$\r
174         \State \Return{$(true,\emptyset)$}\r
175 \Else\r
176         \State \Return{$(false,\{\tuple{s,sv}\in SL \mid \r
177     s \geq s_p\})$}\r
178 \EndIf\r
179 \EndFunction\r
180 \end{algorithmic}\r
181 \r
182 \subsection{Client Algorithm}\r
183 \subsubsection{Reading Slots}\r
184 \textbf{Data Entry} \\\r
185 $de$ is a data entry \\\r
186 $k$ is key of entry \\\r
187 $v$ is value of entry \\\r
188 $kv$ is a key-value entry $\tuple{k,v}$, $kv \in DE$ \\\r
189 $ss$ is a slot sequence entry $\tuple{id,s_{last}}$, \r
190 id + last s of a machine, $ss \in DE$ \\\r
191 $qs$ is a queue state entry (contains $max$ size of queue), $qs \in DE$ \\\r
192 $cr$ is a collision resolution entry $\tuple{s_{col},id_{col}}$, \r
193 s + id of a machine that wins a collision, $cr \in DE$ \\\r
194 $DE$ is a set of all data entries, possibly of different types, in a single message \\\r
195 $s \in SN$ is a sequence number \\\r
196 $id$ is a machine ID\\\r
197 $hmac_p$ is the HMAC value of the previous slot \\\r
198 $hmac_c$ is the HMAC value of the current slot \\\r
199 $Dat_s = \tuple{s,id,hmac_p,DE,hmac_c}$ \\\r
200 $slot_s = \tuple{s, E(Dat_s)} = \r
201 \tuple{s, E(\tuple{s,id,hmac_p,DE,hmac_c})}$ \\ \\\r
202 \textbf{States} \\\r
203 \textit{$id_{self}$ = machine Id of this client} \\\r
204 \textit{$max_g$ = maximum number of slots (initially $max_g > 0$)} \\\r
205 \textit{m = number of slots stored on client (initially $m = 0$)} \\\r
206 \textit{$sl_{last}$ = info of last slot in queue = \r
207         $\tuple{s_{last},sv_{last},id_{last}}$ (initially $\emptyset$)} \\\r
208 \textit{DT = set of $\tuple{k,v}$ on client} \\\r
209 \textit{MS = associative array of $\tuple{id, s_{last}}$ of all clients on client \r
210 (initially empty)} \\\r
211 \textit{$LV$ = live set of $kv$ entries on client, contains \r
212         $\tuple{kv,s}$ entries} \\\r
213 \textit{$SS_{live}$ = live set of $ss$ entries on client} \\\r
214 \textit{$CR_{live}$ = live set of $cr$ entries on client} \\\r
215 \textit{$MS_g$ = set MS to save all $\tuple{id, s_{last}}$ pairs while\r
216 traversing DT after a request to server (initially empty)} \\\r
217 \textit{SK = Secret Key} \\\r
218 \textit{$SM$ = associative array of $\tuple{s, id}$ of all slots in previous reads\r
219 (initially empty)} \\ \\\r
220 \textbf{Helper Functions} \\\r
221 $MaxSlot(SL_s)= \tuple{s, sv}$ \textit{such that} $\tuple{s, sv}\r
222         \in SL_s \wedge \forall \tuple{s_s, sv_s} \in SL_s, s \geq s_s$ \\\r
223 $MinSlot(SL_s)= \tuple{s, sv}$ \textit{such that} $\tuple{s, sv} \r
224         \in SL_s \wedge \forall \tuple{s_s, sv_s} \in SL_s, s \leq s_s$ \\\r
225 $Slot(SL_s,s_s)= \tuple{s, sv}$ \textit{such that} $\tuple{s, sv} \r
226         \in SL_s \wedge \forall \tuple{s_s, sv_s} \in SL_s, s = s_s$ \\\r
227 $SeqN(\tuple{s, sv})=s$ \\\r
228 $SlotVal(\tuple{s, sv})=sv$ \\\r
229 $CreateLastSL(s,sv,id)=\tuple{s,sv,id}=sl_{last}$ \\\r
230 $CreateEntLV(kv_s,s_s)=\tuple{kv_s,s_s}$ \\\r
231 $Decrypt(SK_s,sv_s)=Dat_s=\tuple{s,id,hmac_p,DE,hmac_c}$ \\\r
232 $GetSeqN(Dat_s = \tuple{s,id,hmac_p,DE,hmac_c})=s$ \\\r
233 $GetMacId(Dat_s = \tuple{s,id,hmac_p,DE,hmac_c})=id$ \\\r
234 $GetPrevHmac(Dat_s = \tuple{s,id,hmac_p,DE,hmac_c})=hmac_p$ \\\r
235 $GetCurrHmac(Dat_s = \tuple{s,id,hmac_p,DE,hmac_c})=hmac_c$ \\\r
236 $GetDatEnt(Dat_s = \tuple{s,id,hmac_p,DE,hmac_c})=DE$ \\\r
237 $GetLiveSS(SS_{live},ss_s)= ss$ \textit{such that} $ss \in SS_{live} \r
238         \wedge \forall ss_s \in SS_{live}, ss = ss_s$ \\\r
239 $GetLiveCR(CR_{live},cr_s)= cr$ \textit{such that} $cr \in CR_{live} \r
240         \wedge \forall cr_s \in CR_{live}, cr = cr_s$ \\\r
241 $GetLivEntLastS(LV_s,kv_s)= s$ \textit{such that} $\tuple{kv, s} \in LV_s \r
242         \wedge \forall \tuple{kv_s, s_s} \in LV_s, kv_s = kv$ \\\r
243 $GetKV($key-value data entry$)=\tuple{k_s,v_s} = kv_s$ \\\r
244 $GetSS($slot-sequence data entry$)=\tuple{id_s,s_{s_{last}}} = ss_s$ \\\r
245 $GetQS($queue-state data entry$)=qs_s$ \\\r
246 $GetCR($collision-resolution data entry$)=\tuple{s_s,id_s} = cr_s$ \\\r
247 $GetKey(kv = \tuple{k, v})=k$ \\\r
248 $GetVal(kv = \tuple{k, v})=v$ \\\r
249 $GetId(ss = \tuple{id, s_{last}})=id$ \\\r
250 $GetSLast(ss = \tuple{id, s_{last}})=s_{last}$ \\\r
251 $GetS(cr = \tuple{s, id})=s$ \\\r
252 $GetId(cr = \tuple{s, id})=id$ \\\r
253 $GetKeyVal(DT_s,k_s)= \tuple{k, v}$ \textit{such that} $\tuple{k, v} \r
254         \in DT_s \wedge \forall \tuple{k_s, v_s} \in DT_s, k = k_s$ \\\r
255 $MaxLastSeqN(MS_s)= s_{last}$ \textit{such that} $\tuple{id, s_{last}} \in MS_s \r
256         \wedge \forall \tuple{id_s, s_{s_{last}}} \in MS_s, s_{last} \geq s_{s_{last}}$ \\\r
257 $MinLastSeqN(MS_s)= s_{last}$ \textit{such that} $\tuple{id, s_{last}} \in MS_s \r
258         \wedge \forall \tuple{id_s, s_{s_{last}}} \in MS_s, s_{last} \leq s_{s_{last}}$ \\\r
259 $MinCRSeqN(CR_s)= s$ \textit{such that} $\tuple{s, id} \in CR_s \r
260         \wedge \forall \tuple{s_s, id_s} \in CR_s, s \leq s_s$ \\\r
261 \r
262 \begin{algorithmic}[1]\r
263 \Procedure{Error}{$msg$}\r
264 \State $Print(msg)$\r
265 \State $Halt()$\r
266 \EndProcedure\r
267 \end{algorithmic}\r
268 \r
269 \begin{algorithmic}[1]\r
270 \Function{ValidHmac}{$DE_s,SK_s,hmac_{stored}$}\r
271 \State $hmac_{computed} \gets Hmac(DE_s,SK_s)$\r
272 \State \Return {$hmac_{stored} = hmac_{computed}$}\r
273 \EndFunction\r
274 \end{algorithmic}\r
275 \r
276 \begin{algorithmic}[1]\r
277 \Function{ValidPrevHmac}{$s_s,DE_s,hmac_{p_s},hmac_{p_{sto}}$}\r
278 \If{$s_s = 0 \land hmac_{p_s} = \emptyset$}\Comment{First slot - no previous HMAC}\r
279         \State \Return $true$\r
280 \Else\r
281         \State \Return {$hmac_{p_{sto}} = hmac_{p_s}$}\r
282 \EndIf\r
283 \EndFunction\r
284 \end{algorithmic}\r
285 \r
286 \begin{algorithmic}[1]\r
287 \Function{GetQueSta}{$DE_s$}\r
288 \State $de_{qs} \gets de_s$ \textit{such that} $de_s \in DE_s, \r
289         de_s \in D \land de_s = qs$\r
290 \If{$de_{qs} \neq \emptyset$}\r
291         \State $qs_{ret} \gets GetQS(de_{qs})$\r
292 \Else\r
293         \State $qs_{ret} \gets \emptyset$\r
294 \EndIf\r
295 \State \Return{$qs_{ret}$}\r
296 \EndFunction\r
297 \end{algorithmic}\r
298 \r
299 \begin{algorithmic}[1]\r
300 \Function{GetSlotSeq}{$DE_s$}\r
301 \State $DE_{ss} \gets \{de_s | de_s \in DE_s, de_s = ss\}$\r
302 \State \Return{$DE_{ss}$}\r
303 \EndFunction\r
304 \end{algorithmic}\r
305 \r
306 \begin{algorithmic}[1]\r
307 \Function{GetColRes}{$DE_s$}\r
308 \State $DE_{cr} \gets \{de_s | de_s \in DE_s, de_s = cr\}$\r
309 \State \Return{$DE_{cr}$}\r
310 \EndFunction\r
311 \end{algorithmic}\r
312 \r
313 \begin{algorithmic}[1]\r
314 \Function{UpdateLastSeqN}{$id_s,s_s,MS_s$}\r
315 \State $s_t \gets MS_s[id_s]$\r
316 \If{$s_t = \emptyset$}\r
317         \State $MS_s[id_s] = s_s$  \Comment{First occurrence}\r
318 \Else\r
319         \State $MS_S[id_s] \gets max(s_t, s_s)$\r
320 \EndIf\r
321 \State \Return{$MS_s$}\r
322 \EndFunction\r
323 \end{algorithmic}\r
324 \r
325 \begin{algorithmic}[1]\r
326 \Function{UpdateKVLivEnt}{$LV_s,kv_s,s_s$}\r
327 \State $s_t \gets GetLivEntLastS(LV_s,kv_s)$\r
328 \If{$s_t = \emptyset$}\r
329         \State $LV_s \gets LV_s \cup \{\tuple{kv_s,s_s}\}$\Comment{First occurrence}\r
330 \Else\r
331         \If{$s_s > s_t$}\Comment{Update entry with a later s}\r
332                 \State $LV_s \gets (LV_s - \{\tuple{kv_s,s_t}\}) \cup \r
333                         \{\tuple{kv_s,s_s}\}$\r
334         \EndIf\r
335 \EndIf\r
336 \State \Return{$LV_s$}\r
337 \EndFunction\r
338 \end{algorithmic}\r
339 \r
340 \begin{algorithmic}[1]\r
341 \Function{AddSSLivEnt}{$SS_{s_{live}},de_s$}\r
342 \State $ss_s \gets GetSS(de_s)$\r
343 \State $ss_t \gets GetLiveSS(SS_{s_{live}},ss_s)$\r
344 \If{$ss_t = \emptyset$}\r
345         \State $SS_{s_{live}} \gets SS_{s_{live}} \cup \{ss_s\}$\Comment{First occurrence}\r
346 \EndIf\r
347 \State \Return{$SS_{s_{live}}$}\r
348 \EndFunction\r
349 \end{algorithmic}\r
350 \r
351 \begin{algorithmic}[1]\r
352 \Function{AddCRLivEnt}{$CR_{s_{live}},cr_s$}\r
353 \State $cr_t \gets GetLiveCR(CR_{s_{live}},cr_s)$\r
354 \If{$cr_t = \emptyset$}\r
355         \State $CR_{s_{live}} \gets CR_{s_{live}} \cup \{cr_s\}$\Comment{First occurrence}\r
356 \EndIf\r
357 \State \Return{$CR_{s_{live}}$}\r
358 \EndFunction\r
359 \end{algorithmic}\r
360 \r
361 \begin{algorithmic}[1]\r
362 \Function{UpdateSSLivEnt}{$SS_{s_{live}},MS_s$}\r
363 \State $s_{s_{min}} \gets MinLastSeqN(MS_s)$\r
364 \ForAll{$ss_s \in SS_{s_{live}}$}\r
365         \State $s_{s_{last}} \gets GetSLast(ss_s)$\r
366         \If{$s_{s_{min}} > s_{s_{last}}$}\Comment{Remove if dead}\r
367                 \State $SS_{s_{live}} \gets SS_{s_{live}} - \{ss_s\}$           \r
368         \EndIf\r
369 \EndFor\r
370 \State \Return{$SS_{s_{live}}$}\r
371 \EndFunction\r
372 \end{algorithmic}\r
373 \r
374 \begin{algorithmic}[1]\r
375 \Function{UpdateCRLivEnt}{$CR_{s_{live}},MS_s$}\r
376 \State $s_{s_{min}} \gets MinLastSeqN(MS_s)$\r
377 \ForAll{$cr_s \in CR_{s_{live}}$}\r
378         \State $s_s \gets GetS(cr_s)$\r
379         \If{$s_{s_{min}} > s_s$}\Comment{Remove if dead}\r
380                 \State $CR_{s_{live}} \gets CR_{s_{live}} - \{cr_s\}$   \r
381         \EndIf\r
382 \EndFor\r
383 \State \Return{$CR_{s_{live}}$}\r
384 \EndFunction\r
385 \end{algorithmic}\r
386 \r
387 \begin{algorithmic}[1]\r
388 \Function{UpdateSM}{$SM_s,CR_s$}\Comment{Remove if dead}\r
389 \State $s_{cr_{min}} \gets MinCRSeqN(CR_s)$\r
390         \State $SM_s \gets SM_s - \{\tuple{s_s,id_s} \mid \tuple{s_s,id_s}\r
391                 \in SM_s \wedge s_s < s_{cr_{min}}\}$\r
392 \State \Return{$CR_{s_{live}}$}\r
393 \EndFunction\r
394 \end{algorithmic}\r
395 \r
396 \begin{algorithmic}[1]\r
397 \Procedure{CheckLastSeqN}{$MS_s,MS_t$}\r
398 \For {$\tuple{id, s_t}$ in $MS_t$}\Comment{Check $MS_t$ based on the newer $MS_s$}\r
399         \State $s_s \gets MS_s[id]$\r
400         \If{$s_s = \emptyset$}\r
401         \Call{Error}{'No $s$ for machine $id$'}\r
402         \ElsIf{$id = id_{self}$ and $s_s \neq s_t$}\r
403                         \State \Call{Error}{'Invalid last $s$ for this machine'}\r
404         \ElsIf{$id \neq id_{self}$ and $s_{s_{last}} < s_{t_{last}}$}\r
405         \State \Call{Error}{'Invalid last $s$ for machine $id$'}\r
406     \Else\r
407                 \State $MS_t[id] \gets s_s$\r
408         \EndIf\r
409 \EndFor\r
410 \EndProcedure\r
411 \end{algorithmic}\r
412 \r
413 \begin{algorithmic}[1]\r
414 \Procedure{CheckCollision}{$MS_s,SM_s,cr_s$}\r
415 \If{$cr_s \neq \emptyset$}\r
416         \State $s_s \gets GetS(cr_s)$\r
417         \State $id_s \gets GetId(cr_s)$\r
418         \State $s_{s_{last}} \gets GetLastSeqN(MS_s,id_s)$\r
419         \If{$s_{s_{last}} < s_s$}\r
420                 \State $id_t \gets SM_s[s_s]$\r
421                 \If{$id_s \neq id_t$}\r
422                         \State \Call{Error}{'Invalid $id$ for this slot update'}\r
423                 \EndIf\r
424         \EndIf\r
425 \EndIf\r
426 \EndProcedure\r
427 \end{algorithmic}\r
428 \r
429 \begin{algorithmic}[1]\r
430 \Procedure{CheckSlotsRange}{$|SL_s|,s_{s_{min}},s_{s_{max}}$}\r
431 \State $sz_{SL} \gets s_{s_{max}} - s_{s_{min}} + 1$\r
432 \If{$sz_{SL} \neq |SL_s|$}\r
433         \State \Call{Error}{'Sequence numbers range does not match slots set'}\r
434 \EndIf\r
435 \State $s_{min} \gets MinLastSeqN(MS)$\r
436 \State $s_{max} \gets MaxLastSeqN(MS)$\r
437 \If{$s_{s_{min}} \leq s_{min}$}\r
438         \State \Call{Error}{'Server sent old slot'}\r
439 \EndIf\r
440 \If{$s_{s_{max}} > s_{max}$}\r
441         \State \Call{Error}{'Server sent out-of-range slot'}\r
442 \EndIf\r
443 \State $s_{self} \gets MS_s[id_{self}]$\r
444 \State $sz_{expected} \gets s_{max} - s_{self} + 1$\r
445 \If{$sz_{SL} \neq sz_{expected}$}\r
446         \State \Call{Error}{'Actual number of slots does not match expected'}\r
447 \EndIf\r
448 \EndProcedure\r
449 \end{algorithmic}\r
450 \r
451 \begin{algorithmic}[1]\r
452 \Function{StoreLastSlot}{$MS_s,sl_l,s_s,sv_s,id_s$}\r
453 \State $s_{min} \gets MinLastSeqN(MS_s)$\r
454 \If{$s_{min} \neq \emptyset \land s_{min} = s_s$}\Comment{$MS$ initially empty}\r
455         \State $sl_l \gets CreateLastSL(s_s,sv_s,id_s)$\r
456 \EndIf\r
457 \State \Return{$sl_l$}\r
458 \EndFunction\r
459 \end{algorithmic}\r
460 \r
461 \begin{algorithmic}[1]\r
462 \Function{UpdateDT}{$DT_s,DE_s,LV_s,s_s$}\r
463 \State $DE_{s_{kv}} \gets \{de_s | de_s \in DE_s, de_s = kv\}$\r
464 \ForAll{$de_s \in DE_s$}\r
465         \State $kv_s \gets GetKV(de_s)$\r
466         \State $LV_s \gets \Call{UpdateKVLivEnt}{LV_s,kv_s,s_s}$\r
467         \State $k_s \gets GetKey(kv_s)$\r
468         \State $\tuple{k_s,v_t} \gets GetKeyVal(DT_s,k_s)$\r
469         \If{$\tuple{k_s,v_t} = \emptyset$}\r
470                 \State $DT_s \gets DT_s \cup \{\tuple{k_s,v_s}\}$\r
471         \Else\r
472                 \State $DT_s \gets (DT_s - \{\tuple{k_s,v_t}\}) \cup \r
473                         \{\tuple{k_s,v_s}\}$\r
474         \EndIf\r
475 \EndFor\r
476 \State \Return{$DT_s$}\r
477 \EndFunction\r
478 \end{algorithmic}\r
479 \r
480 \begin{algorithmic}[1]\r
481 \Procedure{ProcessSL}{$SL_g$}\r
482 \State $MS_g \gets \emptyset$\r
483 \State $\tuple{s_{g_{min}},sv_{g_{min}}} \gets MinSlot(SL_g)$\r
484 \State $\tuple{s_{g_{max}},sv_{g_{max}}} \gets MaxSlot(SL_g)$\r
485 \For{$s_g \gets s_{g_{min}}$ \textbf{to} $s_{g_{max}}$}\Comment{Process slots \r
486         in $SL_g$ in order}\r
487         \State $\tuple{s_g,sv_g} \gets Slot(SL_g,s_g)$\r
488         \State $Dat_g \gets Decrypt(SK,sv_g)$\r
489         \State $id_g \gets GetMacId(Dat_g)$\r
490         \State $SM \gets SM \cup \{\tuple{s_g,id_g}\}$\r
491         \State $s_{g_{in}} \gets GetSeqN(Dat_g)$\r
492     \If{$s_g \neq s_{g_{in}}$}\r
493                 \State \Call{Error}{'Invalid sequence number'}\r
494         \EndIf\r
495         \State $DE_g \gets GetDatEnt(Dat_g)$\r
496         \State $hmac_{p_{stored}} \gets GetPrevHmac(Dat_g)$\r
497         \If{$\neg \Call{ValidPrevHmac}{s_g,DE_g,hmac_{p_g},hmac_{p_{stored}}}$}\r
498                 \State \Call{Error}{'Invalid previous HMAC value'}\r
499         \EndIf\r
500         \State $hmac_{c_g} \gets GetCurrHmac(Dat_g)$\r
501         \If{$\neg \Call{ValidHmac}{DE_g,SK,hmac_{c_g}}$}\r
502                 \State \Call{Error}{'Invalid current HMAC value'}\r
503         \EndIf\r
504         \State $hmac_{p_g} \gets Hmac(DE_g,SK)$\Comment{Update $hmac_{p_g}$ for next check}\r
505         \State $qs_g \gets \Call{GetQueSta}{DE_g}$\Comment{Handle qs}\r
506         \If{$qs_g \neq \emptyset \land qs_g > max_g$}\r
507                 \State $max_g \gets qs_g$\r
508         \EndIf\r
509     %Check for last s in Dat\r
510         \State $id_g \gets GetMacId(Dat_g)$\Comment{Handle last s}\r
511         \State $MS_g \gets \Call{UpdateLastSeqN}{id_g,s_g,MS_g}$\r
512     %Check for last s in DE in Dat\r
513         \State $DE_{g_{ss}} \gets \Call{GetSlotSeq}{DE_g}$\Comment{Handle ss}\r
514         \If{$DE_{g_{ss}} \neq \emptyset$}\r
515                 \ForAll{$de_{g_{ss}} \in DE_{g_{ss}}$}\r
516                         \State $\tuple{id_d,s_{d_{last}}} \gets GetSS(de_{g_{ss}})$\r
517                         \State $MS_g \gets \Call{UpdateLastSeqN}{id_d,s_{d_{last}},MS_g}$\r
518                         \State $SS_{live} \gets \Call{AddSSLivEnt}{SS_{live},de_{g_{ss}}}$\r
519                 \EndFor\r
520         \EndIf\r
521         \State $DE_{g_{cr}} \gets \Call{GetColRes}{DE_g}$\Comment{Handle cr}\r
522         \If{$DE_{g_{cr}} \neq \emptyset$}\r
523                 \ForAll{$de_{g_{cr}} \in DE_{g_{cr}}$}\r
524                         \State $cr_g \gets GetCR(de_{g_{cr}})$\r
525                         \State $\Call{CheckCollision}{MS,SM,cr_g}$\r
526                         \State $CR_{live} \gets \Call{AddCRLivEnt}{CR_{live},cr_g}$\r
527                 \EndFor\r
528         \EndIf\r
529         \State $sl_{last} \gets \Call{StoreLastSlot}{MS,sl_{last},s_g,sv_g,id_g}$\r
530         \State $DT \gets \Call{UpdateDT}{DT,DE_g,LV,s_g}$\r
531 \EndFor\r
532 \If{$m + |SL_g| \leq max_g$}\Comment{Check actual size against $max_g$}\r
533         \State $m \gets m + |SL_g|$\r
534 \Else\r
535         \State \Call{Error}{'Actual $SL$ size on server exceeds $max_g$'}\r
536 \EndIf\r
537 \State $\Call{CheckSlotsRange}{|SL_g|,s_{g_{min}},s_{g_{max}}}$\r
538 \State $\Call{CheckLastSeqN}{MS_g,MS}$\r
539 \State $\Call{UpdateSSLivEnt}{SS_{live},MS}$\r
540 \State $\Call{UpdateCRLivEnt}{CR_{live},MS}$\r
541 \State $\Call{UpdateSM}{SM,CR_{live}}$\r
542 \EndProcedure\r
543 \end{algorithmic}\r
544 \r
545 \begin{algorithmic}[1]\r
546 \Procedure{GetKVPairs}{}\r
547 \State $s_g \gets GetLastSeqN(MS,id_{self}) + 1$\r
548 \State $SL_c \gets \Call{GetSlot}{s_g}$\r
549 \State $\Call{ProcessSL}{SL_c}$\Comment{Process slots and update DT}\r
550 \EndProcedure\r
551 \end{algorithmic}\r
552 \r
553 \begin{algorithmic}[1]\r
554 \Function{GetValFromKey}{$k_g$}\r
555 \State $\tuple{k_s,v_s} \gets \tuple{k,v}$ \textit{such that} $\tuple{k,v} \r
556         \in DT \land k = k_g$\r
557 \State \Return{$v_s$}\r
558 \EndFunction\r
559 \end{algorithmic}\r
560 \r
561 \subsubsection{Writing Slots}\r
562 \textbf{States} \\\r
563 \textit{$cp$ = data entry $DE$ maximum size/capacity} \\\r
564 \textit{$ck_p$ = counter of $kv \in KV$ for putting pairs (initially 0)} \\\r
565 \textit{$ck_g$ = counter of $kv \in KV$ for getting pairs (initially 0)} \\\r
566 \textit{$cs_p$ = counter of $ss \in SS$ for putting pairs (initially 0)} \\\r
567 \textit{$cs_g$ = counter of $ss \in SS$ for getting pairs (initially 0)} \\\r
568 \textit{$cc_p$ = counter of $cr \in CR$ for putting pairs (initially 0)} \\\r
569 \textit{$cc_g$ = counter of $cr \in CR$ for getting pairs (initially 0)} \\\r
570 \textit{$hmac_{c_p}$ = the HMAC value of the current slot} \\\r
571 \textit{$hmac_{p_p}$ = the HMAC value of the previous slot \r
572 ($hmac_{p_p} = \emptyset$ for the first slot)} \\\r
573 \textit{$id_{self}$ = machine Id of this client} \\\r
574 \textit{$sl_{last}$ = info of last slot in queue = \r
575         $\tuple{s_{last},sv_{last},id_{last}}$ (initially $\emptyset$)} \\\r
576 \textit{$th_p$ = threshold number of dead slots for a resize to happen} \\\r
577 \textit{$m'_p$ = offset added to $max$ for resize} \\\r
578 \textit{$reinsert_{qs}$ = boolean to decide $qs$($max_g$) reinsertion} \\\r
579 \textit{$KV$ = set of $\tuple{ck, \tuple{k,v}}$ of kv entries on client} \\\r
580 \textit{$SS$ = set of $\tuple{cs, \tuple{id,s_{last}}}$ of ss entries on client} \\\r
581 \textit{$CR$ = set of $\tuple{cc, \tuple{s_{col},id_{col}}}$ of cr entries on client} \\\r
582 \textit{$SL_p$ = set of returned slots on client} \\\r
583 \textit{SK = Secret Key} \\ \\\r
584 \textbf{Helper Functions} \\\r
585 $CreateDat(s,id,hmac_p,DE,hmac_c)=Dat_s=\tuple{s,id,hmac_p,DE,hmac_c}$ \\\r
586 $CreateSS(id_s,s_{s_{last}})=\tuple{id_s,s_{s_{last}}} = ss_s$ \\\r
587 $CreateQS(max'_s)=qs_s$ \\\r
588 $CreateCR(s_s,id_s)=\tuple{s_s,id_s} = cr_s$ \\\r
589 $Encrypt(Dat_s,SK_s)=sv_s$ \\\r
590 $GetLastS(sl = \tuple{s,sv,id})=s$ \\\r
591 $GetSV(sl = \tuple{s,sv,id})=sv$ \\\r
592 $GetID(sl = \tuple{s,sv,id})=id$ \\\r
593 $GetColSeqN(SL_s,s_s)= \tuple{s, sv}$ \textit{such that} $\tuple{s, sv}\r
594 \in SL_s \wedge \forall \tuple{s_s, sv_s} \in SL_s, s = s_s$ \\\r
595 $GetKVPair(KV_s,k_s)= \tuple{ck,\tuple{k, v}}$ \textit{such that} \r
596 $\tuple{ck,\tuple{k, v}} \in KV_s \wedge\r
597 \forall \tuple{ck_s,\tuple{k_s, v_s}} \in KV_s, k = k_s$ \\\r
598 \r
599 \begin{algorithmic}[1]\r
600 \Function{PutKVPair}{$KV_s,\tuple{k_s,v_s}$}\r
601 \State $\tuple{ck_s,\tuple{k_s,v_t}} \gets GetKVPair(KV,k_s)$\r
602 \If{$\tuple{ck_s,\tuple{k_s,v_t}} = \emptyset$}\r
603         \State $KV_s \gets KV_s \cup \{\tuple{ck_p, \tuple{k_s,v_s}}\}$\r
604         \State $ck_p \gets ck_p + 1$\r
605 \Else\r
606         \State $KV_s \gets (KV_s - \{\tuple{ck_s, \tuple{k_s,v_t}}\}) \cup \r
607         \{\tuple{ck_s, \tuple{k_s,v_s}}\}$\r
608 \EndIf\r
609 \State \Return{$KV_s$}\r
610 \EndFunction\r
611 \end{algorithmic}\r
612 \r
613 \begin{algorithmic}[1]\r
614 \Function{PutSSPair}{$SS_s,\tuple{id_s,s_{s_{last}}}$}\Comment{Insert a set of $ss$ entries}\r
615 \State $SS_s \gets SS_s \cup \{\tuple{cs_p, \tuple{id_s,s_{s_{last}}}}\}$\r
616 \State $cs_p \gets cs_p + 1$\r
617 \State \Return{$SS_s$}\r
618 \EndFunction\r
619 \end{algorithmic}\r
620 \r
621 \begin{algorithmic}[1]\r
622 \Function{PutCRPair}{$CR_s,\tuple{s_s,id_s}$}\Comment{Insert a set of $cr$ entries}\r
623 \State $CR_s \gets CR_s \cup \{\tuple{cc_p, \tuple{s_s,id_s}}\}$\r
624 \State $cc_p \gets cc_p + 1$\r
625 \State \Return{$CR_s$}\r
626 \EndFunction\r
627 \end{algorithmic}\r
628 \r
629 \begin{algorithmic}[1]\r
630 \Function{CheckResize}{$MS_s,th_s,max_t,m'_s$}\r
631 \State $s_{last_{min}} \gets MinLastSeqN(MS_s)$\r
632 \State $s_{last_{max}} \gets MaxLastSeqN(MS_s)$\r
633 \State $n_{live} \gets s_{last_{max}} - s_{last_{min}} + 1$\Comment{Number of live slots}\r
634 \State $n_{dead} \gets max_t - n_{live}$\r
635 \If{$n_{dead} \leq th_s$}\r
636         \State $max'_s \gets max_t + m'_s$\r
637 \Else\r
638         \State $max'_s \gets \emptyset$\r
639 \EndIf\r
640 \State \Return{$max'_s$}\r
641 \EndFunction\r
642 \end{algorithmic}\r
643 \r
644 \begin{algorithmic}[1]\r
645 \Function{CheckSLFull}{$MS_s,max_t$}\Comment{Check if $ss$ is needed}\r
646 \State $s_{last_{min}} \gets MinLastSeqN(MS_s)$\r
647 \State $s_{last_{max}} \gets MaxLastSeqN(MS_s)$\r
648 \State $n_{live} \gets s_{last_{max}} - s_{last_{min}}$\Comment{Number of live slots}\r
649 \State $n_{dead} \gets max_t - n_{live}$\r
650 \State \Return {$n_{dead} = 0$}\r
651 \EndFunction\r
652 \end{algorithmic}\r
653 \r
654 \begin{algorithmic}[1]\r
655 \Function{HandleCollision}{$SL_s,s_s$}\r
656 \If{$SL_s = \emptyset$}\r
657         \State \Call{Error}{'No slots received from server'}\r
658 \EndIf\r
659 \State $\tuple{s_{col},sv_{col}} \gets GetColSeqN(SL_s,s_s)$\r
660 \State $Dat_{col} \gets Decrypt(SK,sv_{col})$\r
661 \State $id_{col} \gets GetMacId(Dat_{col})$\r
662 \State $cr_s \gets CreateCR(s_{col},id_{col})$\r
663 \State $\Call{ProcessSL}{SL_s}$\r
664 \State \Return{$cr_s$}\r
665 \EndFunction\r
666 \end{algorithmic}\r
667 \r
668 \begin{algorithmic}[1]\r
669 \Procedure{CheckLastSlot}{$sl_{s_{last}}$}\r
670 \State $s_s \gets GetLastS(sl_{s_{last}})$\r
671 \State $sv_s \gets GetSV(sl_{s_{last}})$\r
672 \State $Dat_s \gets Decrypt(SK,sv_s)$\r
673 \State $DE_s \gets GetDatEnt(Dat_s)$\r
674 \ForAll{$de_s \in DE_s$}\r
675         \State $live \gets \Call{CheckLiveness}{s_s,de_s}$\r
676         \If{$live$}\r
677                 \If{$de_s = kv$}\r
678                         \State $\tuple{k_s,v_s} \gets GetKV(de_s)$\r
679                         \State $KV \gets \Call{PutKVPair}{KV,\tuple{k_s,v_s}}$\r
680                 \ElsIf{$de_s = ss$}\r
681                         \State $\tuple{id_s,s_{s_{last}}} \gets GetSS(de_s)$\r
682                         \State $SS \gets \Call{PutSSPair}{SS,\tuple{id_s,s_{s_{last}}}}$\r
683                 \ElsIf{$de_s = cr$}\r
684                         \State $\tuple{s_s,id_s} \gets GetCR(de_s)$\r
685                         \State $CR \gets \Call{PutCRPair}{CR,\tuple{s_s,id_s}}$\r
686                 \ElsIf{$de_s = qs$}\r
687                         \State $reinsert_{qs} \gets true$\r
688                 \EndIf\r
689         \EndIf\r
690 \EndFor\r
691 \EndProcedure\r
692 \end{algorithmic}\r
693 \r
694 \begin{algorithmic}[1]\r
695 \Function{CheckLiveness}{$s_s,de_s$}\r
696 \State $live \gets true$\r
697 \If{$de_s = kv$}\r
698         \State $s_l \gets GetLivEntLastS(LV,de_s)$\r
699         \If{$s_l = \emptyset \lor s_s < s_l$}\r
700                 \State $live \gets false$\r
701         \EndIf\r
702 \ElsIf{$de_s = ss$}\r
703         \State $ss_s \gets GetSS(de_s)$\r
704         \State $ss_l \gets GetLiveSS(SS_{live},ss_s)$\r
705         \If{$ss_l = \emptyset$}\r
706                 \State $live \gets false$\r
707         \EndIf\r
708 \ElsIf{$de_s = cr$}\r
709         \State $cr_s \gets GetCR(de_s)$\r
710         \State $cr_l \gets GetLiveCR(CR_{live},cr_s)$\r
711         \If{$cr_l = \emptyset$}\r
712                 \State $live \gets false$\r
713         \EndIf\r
714 \ElsIf{$de_s = qs$}\r
715         \State $qs_s \gets GetQS(de_s)$\r
716         \If{$qs_s \neq max_g$}\r
717                 \State $live \gets false$\r
718         \EndIf\r
719 \Else\r
720         \State \Call{Error}{'Unrecognized $de$ type'}\r
721 \EndIf\r
722 \State \Return{$live$}\r
723 \EndFunction\r
724 \end{algorithmic}\r
725 \r
726 \begin{algorithmic}[1]\r
727 \Function{CreateSlotSeq}{$sl_s$}\r
728 \State $id_s \gets GetID(sl_s)$\r
729 \State $s_{s_{last}} \gets GetLastS(sl_s)$\r
730 \State $ss_s \gets CreateSS(id_s,s_{s_{last}})$\r
731 \State \Return{$\tuple{ss_s}$}\r
732 \EndFunction\r
733 \end{algorithmic}\r
734 \r
735 \begin{algorithmic}[1]\r
736 \Function{AddQueSta}{$DE_s,max'_s,cp_s$}\Comment{Insert a $qs$}\r
737 \State $DE_{ret} \gets \emptyset$\r
738 \State $qs_s \gets max'_s$\r
739 \State $DE_{ret} \gets DE_s \cup \{qs_s\}$\r
740 \State $cp_s \gets cp_s - 1$\r
741 \State \Return{$\tuple{DE_{ret},cp_s}$}\r
742 \EndFunction\r
743 \end{algorithmic}\r
744 \r
745 \begin{algorithmic}[1]\r
746 \Function{GetKVPairs}{$DE_s,KV_s,cp_s$}\r
747 \State $DE_{ret} \gets \emptyset$\r
748 \If{$|KV_s| \leq cp_s$}\Comment{$KV$ set can span multiple slots}\r
749         \State $DE_{ret} \gets DE_s \cup\r
750         \{\tuple{k_s,v_s} \mid \tuple{ck_s,\tuple{k_s,v_s}} \in KV_s\}$\r
751 \Else\r
752         \State $DE_{ret} \gets DE_s \cup\r
753         \{\tuple{k_s,v_s} \mid \tuple{ck_s,\tuple{k_s,v_s}} \in KV_s,\r
754                 ck_g \leq ck_s < ck_g + cp_s\}$\r
755 \EndIf\r
756 \State \Return{$\tuple{DE_{ret}}$}\r
757 \EndFunction\r
758 \end{algorithmic}\r
759 \r
760 \begin{algorithmic}[1]\r
761 \Function{GetSSPairs}{$DE_s,SS_s,cp_s$}\r
762 \State $DE_{ret} \gets \emptyset$\r
763 \If{$|SS_s| \leq cp_s$}\Comment{$SS$ set can span multiple slots}\r
764         \State $DE_{ret} \gets DE_s \cup\r
765         \{\tuple{id_s,s_{s_{last}}} \mid \tuple{cs_s,\tuple{id_s,s_{s_{last}}}} \in SS_s\}$\r
766         \State $cp_s \gets cp_s - |SS_s|$\r
767 \Else\r
768         \State $DE_{ret} \gets DE_s \cup\r
769         \{\tuple{id_s,s_{s_{last}}} \mid \tuple{cs_s,\tuple{id_s,s_{s_{last}}}} \in SS_s,\r
770                 cs_g \leq cs_s < cs_g + cp_s\}$\r
771         \State $cp_s \gets 0$\r
772 \EndIf\r
773 \State \Return{$\tuple{DE_{ret},cp_s}$}\r
774 \EndFunction\r
775 \end{algorithmic}\r
776 \r
777 \begin{algorithmic}[1]\r
778 \Function{GetCRPairs}{$DE_s,CR_s,cp_s$}\r
779 \State $DE_{ret} \gets \emptyset$\r
780 \If{$|CR_s| \leq cp_s$}\Comment{$CR$ set can span multiple slots}\r
781         \State $DE_{ret} \gets DE_s \cup\r
782         \{\tuple{s_s,id_s} \mid \tuple{cc_s,\tuple{s_s,id_s}} \in CR_s\}$\r
783         \State $cp_s \gets cp_s - |CR_s|$\r
784 \Else\r
785         \State $DE_{ret} \gets DE_s \cup\r
786         \{\tuple{s_s,id_s} \mid \tuple{cc_s,\tuple{s_s,id_s}} \in CR_s,\r
787                 cc_g \leq cc_s < cc_g + cp_s\}$\r
788         \State $cp_s \gets 0$\r
789 \EndIf\r
790 \State \Return{$\tuple{DE_{ret},cp_s}$}\r
791 \EndFunction\r
792 \end{algorithmic}\r
793 \r
794 \begin{algorithmic}[1]\r
795 \Procedure{PutDataEntries}{$th_p,m'_p$}\r
796 \State $success_p \gets false$\r
797 \State $CR_p \gets \emptyset$\r
798 \While{$\neg success_p$}\r
799         \State $DE_p \gets \emptyset$\r
800         \State $s_p \gets MaxLastSeqN(MS)$\r
801         \State $cp_p \gets cp$\r
802         \State $max'_p \gets \Call{CheckResize}{MS,th_p,max_g,m'_p}$\r
803         \If{$max'_p \neq \emptyset$}\Comment{Add a qs entry}\r
804                 \State $\tuple{DE_p,cp_p} \gets \Call{AddQueSta}{DE_p,max'_p,cp_p}$\r
805                 \State $reinsert_{qs} \gets false$\r
806         \Else\Comment{Check if there is $qs$ reinsertion}\r
807                 \If{$reinsert_{qs}$}\r
808                         \State $\tuple{DE_p,cp_p} \gets \Call{AddQueSta}{DE_p,max_g,cp_p}$\r
809                         \State $reinsert_{qs} \gets false$\r
810                 \EndIf\r
811         \EndIf\r
812         \If{$SS \neq \emptyset$}\Comment{Add $ss$ entries}\r
813                 \State $\tuple{DE_p,cp_p} \gets \Call{GetSSPairs}{DE_p,SS,cp_p}$\r
814         \EndIf\r
815         \If{$CR \neq \emptyset$}\Comment{Add $cr$ entries}\r
816                 \State $\tuple{DE_p,cp_p} \gets \Call{GetCRPairs}{DE_p,CR,cp_p}$\r
817         \EndIf\r
818         \State $\tuple{DE_p,cp_p} \gets \Call{GetKVPairs}{DE_p,KV,cp_p}$\Comment{Add $kv$ entries}\r
819         \State $hmac_{c_p} \gets Hmac(DE_p,SK)$\r
820         \State $Dat_p \gets CreateDat(s_p,id_{self},hmac_{p_p},DE_p,hmac_{c_p})$\r
821         \State $hmac_{p_p} \gets hmac_{c_p}$\r
822         \State $sv_p \gets Encrypt(Dat_p,SK)$\r
823         \State $\tuple{success_p,SL_p} \gets \Call{PutSlot}{s_p,sv_p,max'_p}$\r
824         \If{$\neg success_p$}\r
825                 \State $cr_p \gets \Call{HandleCollision}{SL_p,s_p}$\r
826                 \State $\tuple{s_{p_{col}},id_{p_{col}}} \gets GetCR(cr_p)$\r
827                 \State $CR \gets \Call{PutCRPair}{CR,\tuple{s_{p_{col}},id_{p_{col}}}}$\r
828         \EndIf\r
829 \EndWhile\r
830 \State $MS \gets \Call{UpdateLastSeqN}{id_{self},s_p,MS}$\r
831 \If{$|DE_p| = cp$}\Comment{Update set counters}\r
832         \State $ck_g \gets ck_g + cp_p$\Comment{Middle of set}\r
833         \State $cs_g \gets cs_g + |SS|$\r
834         \State $cc_g \gets cc_g + |CR|$\r
835 \Else\Comment{End of set}\r
836         \State $ck_g \gets 0$\r
837         \State $cs_g \gets 0$\r
838         \State $cc_g \gets 0$\r
839 \EndIf\r
840 \State $need_p \gets \Call{CheckSLFull}{MS,max_g}$\r
841 \If{$need_p$}\Comment{SL on server is full}\r
842         \State $\Call{CheckLastSlot}{sl_{last}}$\Comment{Salvage entries from expunged slot}\r
843         \State $ss_p \gets \Call{CreateSlotSeq}{sl_{last}}$\r
844         \State $\tuple{id_p,s_{p_{last}}} \gets GetSS(ss_p)$\r
845         \State $SS \gets \Call{PutSSPair}{SS,\tuple{id_p,s_{p_{last}}}}$\Comment{Add ss}\r
846 \EndIf\r
847 \EndProcedure\r
848 \end{algorithmic}\r
849 \r
850 %\note{Lots of problems with PutDataEntries: (1) What happens if lose network connectivity after adding the key value pair, but before reinserting the last slot?  You probably need to create space first and then insert your data entry...  (2) What if reinsertlastslot kicks something else important out?  What if the server rejects our update because it is out of date?  At the very least, any putdataentries function w/o a loop is wrong!}\r
851 \r
852 %\note{General comments...  Work on structuring things to improve readability...  This include names of functions/variables, how things are partitioned into functions, adding useful comments,...}\r
853   \r
854 %\note{Also Missing liveness state definition in algorithm...}\r
855 \r
856 \r
857 \subsection{Formal Guarantees}\r
858 \subsubsection{Definitions}\r
859 \r
860 \begin{defn}[Message]\r
861 A message $\mathsf{t}$, is the tuple \r
862 \begin{center}\r
863 $\mathsf{t = \tuple{s, E(Dat_s)}}$ \\\r
864 $\mathsf{Dat_t = \tuple{s,id,hmac_p, DE,hmac_c}}$\r
865 \end{center}\r
866 containing $\mathsf{s}$ as sequence number and $\mathsf{Dat_t}$ as its \r
867 encrypted contents. $\mathsf{Dat_t}$ consists of $\mathsf{s}$, \r
868 $\mathsf{id}$ as machine ID of the sender, $\mathsf{hmac_p}$ as HMAC \r
869 from a previous message, $\mathsf{DE}$ as set of data entries, and \r
870 $\mathsf{hmac_c}$ as HMAC from message $\mathsf{t}$ respectively.\r
871 \end{defn}\r
872 \r
873 \begin{defn}[Equality]\r
874 Two messages $\mathsf{t}$ and $\mathsf{u}$ are equal if their $\mathsf{s}$, \r
875 and $\mathsf{Dat_t}$ are exactly the same.\r
876 \end{defn}\r
877 \r
878 \begin{defn}[Parent]\r
879 A parent of a message $\mathsf{t}$ is the message $\mathsf{\mathscr{P}_t}$, \r
880 unique by the correctness of HMACs in $\mathsf{Dat_t}$, such that \r
881 $\mathsf{hmac_p(t) = hmac_c(\mathscr{P}_t)}$.\r
882 \end{defn}\r
883 \r
884 \begin{defn}[Chain]\r
885 A chain of messages with length $\mathsf{n \ge 1}$ is a message sequence \r
886 $\mathsf{R = (r_s, r_{s+1}, ..., r_{s+n-1})}$ such that for every sequence \r
887 number $\mathsf{s < k \le s+n-1}$, $\mathsf{r_k}$ has sequence number \r
888 $\mathsf{k}$ and is the parent of $\mathsf{r_{k-1}}$.\r
889 \end{defn}\r
890 \r
891 \begin{defn}[Partial sequence]\r
892 A partial sequence $\mathsf{P}$ is a sequence of messages, no two \r
893 with the same sequence number, that can be divided into disjoint chains.\r
894 \end{defn}\r
895 \r
896 \begin{defn}[Total sequence]\r
897 A total sequence $\mathsf{T =}$ $\mathsf{(t_1, t_2, ..., t_n)}$ with \r
898 length $\mathsf{n}$ is a chain of messages that starts at $\mathsf{s = 1}$.\r
899 \end{defn}\r
900 \r
901 \begin{defn}[Path]\r
902 The path of a message $\mathsf{t}$ is the chain that starts at $\mathsf{s = 1}$ \r
903 and whose last message is $\mathsf{t}$. The uniqueness of a path follows \r
904 from the uniqueness of a parent.\r
905 \end{defn}\r
906 \r
907 \begin{defn}[Consistency]\r
908 A partial sequence $\mathsf{P}$ is consistent with a total sequence \r
909 $\mathsf{T}$ of length $\mathsf{n}$ if for every message $\mathsf{p \in P}$ \r
910 with $\mathsf{s_p \leq n}$, $\mathsf{t_{s_p} = p}$. This implies that \r
911 $\mathsf{\{p \in P | s_p \le n\}}$ is a partial sequence of $\mathsf{T}$.\r
912 \end{defn}\r
913 \r
914 \begin{defn}[Transitive closure]\r
915 Transitive closure set at sequence number $\mathsf{s_n}$ is a set \r
916 $\mathsf{\mathscr{S}}$ of clients comprising a connected component of an \r
917 undirected graph, where two clients are connected by an edge if they both \r
918 received the same message $\mathsf{t}$ with sequence number $\mathsf{s_t < s_n}$.\r
919 %TODO: Check with Thomas whether this is $\mathsf{s_t > s_n}$ or it should be\r
920 %$\mathsf{s_t < s_n}$\r
921 \end{defn}\r
922 \r
923 \subsubsection{Lemmas and Proofs}\r
924 \r
925 \begin{prop} \r
926 Every client $\mathsf{J}$ who sends a message $\mathsf{t}$ \r
927 has $\mathsf{\mathscr{P}_t}$ as its latest stored message, and \r
928 $\mathsf{s_t = s_{\mathscr{P}_t} + 1}$. \r
929 \end{prop}\r
930 \begin{proof} True by definition, because $J$ sets \r
931 $\mathsf{hmac_p(t) = hmac_c(\mathscr{P}_t)}$ and \r
932 $\mathsf{s_t = }$ $\mathsf{s_{\mathscr{P}_t + 1}}$ when a message \r
933 is sent. \r
934 \end{proof}\r
935 \r
936 \begin{prop} If a rejected message entry is added to the set $\mathsf{CR}$ \r
937 at sequence number $\mathsf{s}$, the message will remain in $\mathsf{CR}$ \r
938 until every client has seen it. \r
939 \end{prop}\r
940 \begin{proof} Every $\mathsf{CR}$ entry $\mathsf{cr}$ remains in the queue until it \r
941 reaches the tail, and is refreshed by the next sender $\mathsf{J}$ at that time if \r
942 $\mathsf{min(MS) > s_{cr}}$; that is, until every client has sent a message with \r
943 sequence number greater than $\mathsf{s_{cr}}$. Because every client who sends a \r
944 message with sequence number $\mathsf{s}$ has the state of the set $\mathsf{SL}$ at \r
945 $\mathsf{s - 1}$, this client will have seen the message at $\mathsf{s_{cr}}$. \r
946 \end{proof}\r
947 \r
948 \begin{figure}[h]\r
949   \centering\r
950       \xymatrix{ & & L \\\r
951 \dots \ar[r] & q \ar[dr]_{J} \ar[r]^{K} & l_1 \ar[r] & l_2 \ar[r] & \dots \ar[r] & p \ar[r] & \dots \ar[r] & l_n = u \\\r
952 & & r_1 \ar[r] & r_2 \ar[r] & \dots \ar[r] & r_m = t \\\r
953 & & R\r
954 \save "2,3"."2,8"*+\frm{^\}}\r
955 \save "3,3"."3,6"*+\frm{_\}}\r
956 \restore\r
957 \restore\r
958 }\r
959 \caption{By Lemma 1, receiving $t$ after $u$ is impossible.}\r
960 \end{figure}\r
961 \r
962 \begin{lem} Two messages are received without errors by a client $\mathsf{C}$; \r
963 call them $\mathsf{t}$ and $\mathsf{u}$ such that $\mathsf{s_t \le s_u}$. \r
964 Then $\mathsf{t}$ is in the path of $\mathsf{u}$. \r
965 \end{lem}\r
966 \begin{proof}\r
967 Clearly $\mathsf{C}$ will throw an error if $\mathsf{s_t = s_u}$. So \r
968 $\mathsf{s_t < s_u}$. Additionally, if $\mathsf{C}$ receives $\mathsf{u}$ before \r
969 $\mathsf{t}$, this will cause it to throw an error, so $\mathsf{t}$ is received \r
970 before $\mathsf{u}$.\r
971 \r
972 Assume that $\mathsf{t}$ is not in the path of $\mathsf{u}$. Take $\mathsf{u}$ \r
973 to be the packet of smallest sequence number for which this occurs, and \r
974 $\mathsf{t}$ be the packet with greatest sequence number for this $\mathsf{u}$. \r
975 We will prove that an error occurs upon receipt of $\mathsf{u}$.\r
976 \r
977 Let $\mathsf{r_1}$ be the earliest member of the path of $\mathsf{t}$ that is \r
978 not in the path of $\mathsf{u}$, and $\mathsf{q}$ be its parent. Message \r
979 $\mathsf{q}$, the last common ancestor of $\mathsf{t}$ and $\mathsf{u}$, must exist, \r
980 since all clients and the server were initialized with the same state. Let \r
981 $\mathsf{l_1}$ be the successor of $\mathsf{q}$ that is in the path of $\mathsf{u}$; \r
982 we know $\mathsf{l_1 \neq r_1}$. Let $\mathsf{R = (r_1, r_2, \dots, r_m = t)}$ be \r
983 the distinct portion of the path of $\mathsf{t}$, and similarly let $\mathsf{L}$ \r
984 be the distinct portion of the path of $\mathsf{l_n = u}$.\r
985 \r
986 Let $\mathsf{J}$ be the client who sent $\mathsf{r_1}$; that is, such that \r
987 $\mathsf{{id_{self}}_J = GetMacID(r_1)}$, and $\mathsf{K}$ be the client who \r
988 sent $\mathsf{l_1}$.\r
989 \r
990 We know the following three facts: \r
991 \r
992 \begin{enumerate}\r
993 \r
994 \item Because no client can send two messages with the same sequence number, and \r
995 $\mathsf{s_{r_1} = s_{l_1} = s_q + 1}$, $\mathsf{J \neq K}$.\r
996 \r
997 \item To send a message $\mathsf{p}$ that is the parent of some other \r
998 message, one must have received the parent of $\mathsf{p}$. Since \r
999 $\mathsf{u}$ is the message with smallest sequence number received by any \r
1000 client that violates this lemma, no client receives both a message in $\mathsf{r}$ \r
1001 and a message in $\mathsf{l}$; therefore, no client sends both a message in \r
1002 $\mathsf{(r_2,...,t)}$ and a message in $\mathsf{(l_2,...,u)}$.\r
1003 \r
1004 \item Since $\mathsf{u}$ is the message with the greatest- and least- sequence \r
1005 number that violates this lemma, $\mathsf{C}$ does not receive any message with \r
1006 sequence number strictly between $\mathsf{s_t}$ and $\mathsf{s_u}$. Because the \r
1007 $\mathsf{s_{last}}$ that $\mathsf{C}$ stores increases at every message receipt \r
1008 event, $\mathsf{C}$ also does not receive any message after $\mathsf{t}$ and before \r
1009 $\mathsf{u}$ in real time.\r
1010 \r
1011 \end{enumerate}\r
1012 There are two cases:\r
1013 \begin{itemize}\r
1014 \item Case 1: $\mathsf{J}$ did not send a message in $\mathsf{L}$. Then \r
1015 %$\mathsf{v_J(t) > v_J(q) = v_J(u)}$.\r
1016 $\mathsf{s_{t_J} > s_{q_J} = s_{u_J}}$.\r
1017 \begin{itemize}\r
1018 \item Case 1.1: $\mathsf{C}$ never updates its slot sequence list $\mathsf{SS}$ \r
1019 between receiving $\mathsf{t}$ and receiving $\mathsf{u}$; this can only happen if \r
1020 $\mathsf{s_t = s_u - 1}$. Since $\mathsf{t}$ is not the parent of $\mathsf{u}$, \r
1021 $\mathsf{hmac_p(u) \neq hmac_c(t)}$, causing $\mathsf{C}$ to error.\r
1022 \item Case 1.2: Case 1.1 does not occur; therefore, $\mathsf{C}$ must update \r
1023 its slot sequence list $\mathsf{SS}$ at some point between receiving $\mathsf{t}$ \r
1024 and $\mathsf{u}$. \r
1025 The latest sequence number of $\mathsf{J}$ decreases during this time, which \r
1026 means it must decrease when some message is received, which means $\mathsf{C}$ \r
1027 throws an error in the $\mathsf{CheckLastSeqN}$ subroutine.\r
1028 \end{itemize}\r
1029 \r
1030 \item Case 2: $\mathsf{J}$ sent at least one message in $\mathsf{L}$. Call the \r
1031 first one $\mathsf{p}$. We know that $\mathsf{s_p > s_{r_1}}$, since \r
1032 $\mathsf{J \neq K}$ and $\mathsf{p \neq l_1}$. Message $\mathsf{r_1}$ must be sent \r
1033 either before or after $\mathsf{p}$.\r
1034 \begin{itemize}\r
1035 \item Case 2.1: Client $\mathsf{J}$ sends $\mathsf{p}$, and then $\mathsf{r_1}$. \r
1036 Before sending $\mathsf{p}$, the greatest sequence number of a message that \r
1037 $\mathsf{J}$ has received, $\mathsf{{s_{last}}_J}$, must be equal to \r
1038 $\mathsf{s_p - 1 \ge s_{r_1}}$. Since $\mathsf{{s_{last}}_J}$ never decreases, \r
1039 client $\mathsf{J}$ cannot then send a message with sequence number \r
1040 $\mathsf{s_{r_1}}$, a contradiction.\r
1041 \item Case 2.2: Client $\mathsf{J}$ sends $\mathsf{r_1}$, and then $\mathsf{p}$. \r
1042 Let $\mathsf{X = (r_1, \dots )}$ be the list of messages $\mathsf{J}$ sends \r
1043 starting before $\mathsf{r_1}$ and ending before $p$.\r
1044 \begin{itemize}\r
1045 \item Case 2.2.1: Some message in $\mathsf{X}$ was accepted. Let $\mathsf{s_{w_J}}$ \r
1046 be the greatest sequence number of the messages that client $\mathsf{J}$ sent in \r
1047 the path of message $\mathsf{w}$. In this case, before sending $\mathsf{p}$, \r
1048 $\mathsf{J}$'s value in $\mathsf{MS_J}$ for its own latest sequence number would \r
1049 be strictly greater than $\mathsf{s_{q_J}}$. If there is a sequence of messages with \r
1050 contiguous sequence numbers that $\mathsf{J}$ receives between $\mathsf{r_1}$ and \r
1051 $\mathsf{p}$, $\mathsf{J}$ throws an error for a similar reason as Case 1.1. Otherwise, \r
1052 when preparing to send $\mathsf{p}$, $\mathsf{J}$ would have received an update of its \r
1053 own latest sequence number as at most $\mathsf{s_{q_J}}$. $J$ throws an error before \r
1054 sending $\mathsf{p}$, because its own latest sequence number decreases.\r
1055 \item Case 2.2.2: All messages in $\mathsf{X}$ were rejected, making $\mathsf{p}$ \r
1056 the first message of $\mathsf{J}$ that is accepted after $\mathsf{r_1}$. Note that \r
1057 $\mathsf{u}$ is the message with least sequence number that violates this lemma, and \r
1058 therefore the first one that $\mathsf{C}$ receives after $\mathsf{t}$. Therefore, \r
1059 $\mathsf{C}$ could not have seen a message after $\mathsf{t}$ with sequence number less \r
1060 than $\mathsf{s_p}$. In the $\mathsf{PutDataEntries}$ subroutine, $\mathsf{J}$ adds every \r
1061 %TODO: Check with Thomas about this part\r
1062 %rejected message to $\mathsf{CR(p)}$; so for every $\mathsf{s}$, $\mathsf{1 \leq s < |X|}$, \r
1063 %the $\mathsf{s}$-th element of $\mathsf{X}$ will be recorded in the rejected message list\r
1064 %$\mathsf{CR}$ of all further elements of $\mathsf{X}$; and every element of \r
1065 %$\mathsf{X}$ will be recorded in $\mathsf{CR_C(p)}$. Since every rejected message in \r
1066 %$\mathsf{CR(p)}$ will be in $\mathsf{CR_C(u)}$, ${r_1}$ will be recorded in \r
1067 %$\mathsf{CR_C(p)}$. When $\mathsf{C}$ receives $\mathsf{u}$, $\mathsf{C}$ will throw \r
1068 %an error from the match $\mathsf{\tuple{s_q+1, id_J}}$ in $\mathsf{CR_C(p)}$.\r
1069 $\mathsf{cr}$ entry that contains sequence number $\mathsf{s}$ and machine ID \r
1070 $\mathsf{id}$ of the messsages that win in the collisions before $\mathsf{p}$ into \r
1071 $\mathsf{CR}$; $\mathsf{CR}$ keeps the collection of live $\mathsf{cr}$ entries, namely\r
1072 those which not all clients have seen. Hence, for every $\mathsf{s}$, $\mathsf{1 \leq s < |X|}$, \r
1073 the collision winner that has collided with $\mathsf{s}$-th element of $\mathsf{X}$ \r
1074 will be recorded appropriately. Since all the $\mathsf{cr}$ entries that record \r
1075 the results of the collisions before $\mathsf{p}$ will also be seen when $\mathsf{u}$ \r
1076 is received, ${l_1}$ will be recorded in a $\mathsf{cr}$ entry as the winner in the \r
1077 collision against ${r_1}$. When $\mathsf{C}$ receives $\mathsf{u}$, if $\mathsf{C}$ \r
1078 has seen the $\mathsf{cr}$ entry that records the collision, it will already throw \r
1079 an error from the mismatch of $\mathsf{\tuple{s_q+1, id_J}}$ with \r
1080 $\mathsf{\tuple{s_q+1, id_K}}$ in the corresponding $\mathsf{cr}$ entry.\r
1081 \item Case 2.2.2.1: \r
1082 \end{itemize}\r
1083 \end{itemize}\r
1084 \r
1085 \end{itemize}\r
1086 \end{proof}\r
1087 \r
1088 \begin{lem} If there are two packets $\mathsf{t}$ and $\mathsf{u}$, with \r
1089 $\mathsf{s_t \leq s_u}$, such that $\mathsf{t}$ is in the path of $\mathsf{u}$, \r
1090 then for any message $\mathsf{p}$ with $\mathsf{s_p \leq s_t}$, iff $\mathsf{p}$ is in \r
1091 the path of $\mathsf{t}$, it is in the path of $\mathsf{u}$. \r
1092 \end{lem}\r
1093 \r
1094 \begin{proof}\r
1095 If $\mathsf{s_t = s_u}$ or $\mathsf{s_p = s_t}$, then we are done, because the two \r
1096 relevant messages are the same. If they are different messages, then:\r
1097 \begin{itemize}\r
1098 \item Reverse direction: The definition of $\mathsf{t}$ being in the path of \r
1099 $\mathsf{u}$ is the existence of a message sequence $\mathsf{(\dots, t, \dots, u)}$ \r
1100 such that each message except $\mathsf{u}$ is the parent of the succeeding message. \r
1101 The path of $\mathsf{u}$ must contain some message with sequence number $\mathsf{s_p}$; \r
1102 because $\mathsf{p}$ is in the path of $\mathsf{u}$, this message is $\mathsf{p}$ \r
1103 itself. The path of $\mathsf{t}$ is then the prefix of this path ending at $\mathsf{t}$, \r
1104 which clearly contains $\mathsf{p}$.\r
1105 \r
1106 \item Forward direction: The path of $\mathsf{t}$ is a substring of the path of \r
1107 $\mathsf{u}$, so if the path of $\mathsf{t}$ contains $\mathsf{p}$, so does the path \r
1108 of $\mathsf{u}$.\r
1109 \end{itemize}\r
1110 \end{proof}\r
1111 \r
1112 \begin{theorem}\r
1113 Suppose that there is a transitive closure set $\mathsf{\mathscr{S}}$ of clients, \r
1114 at sequence number $\mathsf{s_n}$. Then there is some total sequence $\mathsf{T}$ of \r
1115 length $\mathsf{n}$ such that every client $\mathsf{C}$ in $\mathsf{\mathscr{S}}$ \r
1116 sees a partial sequence $\mathsf{P_C}$ consistent with $\mathsf{T}$. \r
1117 \end{theorem}\r
1118 \r
1119 \begin{proof}\r
1120 \r
1121 The definition of consistency of $\mathsf{P_C}$ with $\mathsf{T}$ is that every message \r
1122 $\mathsf{p \in P_C}$ with sequence number $\mathsf{s_p \le s_n}$ is equal to the message \r
1123 in that slot in $\mathsf{T}$. Let $\mathsf{C_1}$ be some client in the transitive closure \r
1124 set, with partial sequence $\mathsf{P_{C_1}}$, and let $\mathsf{u}$ be some message with \r
1125 $\mathsf{s_u > s_n}$ that $\mathsf{C_1}$ shares with another client. Then let $\mathsf{T}$ \r
1126 be the portion of the path of $\mathsf{u}$ ending at sequence number $\mathsf{s_n}$ and \r
1127 $\mathsf{t}$ be the message at that sequence number. Clearly, by Lemma 1, $\mathsf{P_{C_1}}$ \r
1128 is consistent with $\mathsf{T}$. We will show that, for every other client $\mathsf{D}$ \r
1129 with partial sequence $\mathsf{P_D}$, $\mathsf{P_D}$ has some message whose path includes \r
1130 $\mathsf{t}$. Because $\mathsf{D}$ is in the transitive closure, there is a sequence of \r
1131 clients $\mathsf{\mathscr{C} = (C_1, C_2, ..., D)}$ from $\mathsf{C_1}$ to $\mathsf{D}$, \r
1132 where each shares an edge with the next.\r
1133 We prove by induction that $\mathsf{P_D}$ has a message whose path includes $\mathsf{t}$.\r
1134 \begin{itemize}\r
1135 \item Base case: $\mathsf{P_{C_1}}$ includes $\mathsf{u}$, whose path includes $\mathsf{t}$.\r
1136 \r
1137 \item Inductive step: Each client in $\mathsf{\mathscr{C}}$ has a partial sequence with a message \r
1138 that includes $\mathsf{t}$ if the previous client does. Suppose $\mathsf{P_{C_k}}$ has \r
1139 a message $\mathsf{w}$ with a path that includes $\mathsf{t}$, and shares message $\mathsf{x}$ \r
1140 with $\mathsf{P_{C_{k+1}}}$ such that $\mathsf{s_x > s_n}$. By Lemma 1, $\mathsf{w}$ or \r
1141 $\mathsf{x}$, whichever has the least sequence number, is in the path of the other, and therefore \r
1142 by Lemma 2, $\mathsf{t}$ is in the path of $\mathsf{x}$.\r
1143 \r
1144 \item Let $\mathsf{z}$ be the message of $\mathsf{D}$ whose path includes $\mathsf{t}$. \r
1145 By Lemma 1, every message in $\mathsf{P_D}$ with sequence number smaller than $\mathsf{s_w}$ \r
1146 is in the path of $\mathsf{z}$. Since $\mathsf{t}$ is in the path of $\mathsf{z}$, every \r
1147 message in $\mathsf{P_D}$ with smaller sequence number than $\mathsf{s_t = s_n}$ is in $\mathsf{T}$. \r
1148 Therefore, $\mathsf{P_D}$ is consistent with $\mathsf{T}$.\r
1149 \r
1150 \end{itemize}\r
1151 \end{proof}\r
1152 \r
1153 \subsection{Future Work}\r
1154 \paragraph{Support Messages}\r
1155   A message is dead once receiving machine sends an entry with a newer\r
1156   sequence identifier\r
1157 \r
1158 \paragraph{Persistent data structures}\r
1159         Root object w/ fields\r
1160         Other objects can be reachable from root\r
1161         Each object has its own entries\r
1162         Dead objects correspond to dead \r
1163 \r
1164 \paragraph{Multiple App Sharing}\r
1165 \r
1166 Idea is to separate subspace of entries...  Shared with other cloud...\r
1167 \end{document}\r