Adding collision resolution entry - preserved by checking against last sequence numbe...
[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{algpseudocode}% http://ctan.org/pkg/algorithmicx\r
6 \newtheorem{theorem}{Theorem}\r
7 \newtheorem{defn}{Definition}\r
8 \newcommand{\note}[1]{{\color{red} \bf [[#1]]}}\r
9 \newcommand{\push}[1][1]{\hskip\dimexpr #1\algorithmicindent\relax}\r
10 \begin{document}\r
11 \section{Approach}\r
12 \r
13 \subsection{Keys}\r
14 \r
15 Each device has: user id + password\r
16 \r
17 Server login is:\r
18 hash1(user id), hash1(password)\r
19 \r
20 Symmetric Crypto keys is:\r
21 hash2(user id | password)\r
22 \r
23 Server has finite length queue of entries + max\_entry\_identifier +\r
24 server login key\r
25 \r
26 \subsection{Entry layout}\r
27 Each entry has:\r
28 \begin{enumerate}\r
29 \item Sequence identifier\r
30 \item Random IV (if needed by crypto algorithm)\r
31 \item Encrypted payload\r
32 \end{enumerate}\r
33 \r
34 Payload has:\r
35 \begin{enumerate}\r
36 \item Sequence identifier\r
37 \item Machine id (most probably something like a 64-bit random number \r
38 that is self-generated by client)\r
39 \item HMAC of previous slot\r
40 \item Data entries\r
41 \item HMAC of current slot\r
42 \end{enumerate}\r
43 \r
44 A data entry can be one of these:\r
45 \begin{enumerate}\r
46 \item All or part of a Key-value entry\r
47 \item Slot sequence entry: Machine id + last message identifier \r
48 \newline {The purpose of this is to keep the record of the last slot \r
49 from a certain client if a client's update has to expunge that other \r
50 client's last entry from the queue. This is kept in the slot until \r
51 the entry owner inserts a newer update into the queue.}\r
52 \item Queue state entry: Includes queue size \newline {The purpose \r
53 of this is for the client to tell if the server lies about the number \r
54 of slots in the queue, e.g. if there are 2 queue state entry in the queue, \r
55 e.g. 50 and 70, the client knows that when it sees 50, it should expect \r
56 at most 50 slots in the queue and after it sees 70, it should expect \r
57 50 slots before that queue state entry slot 50 and at most 70 slots. \r
58 The queue state entry slot 70 is counted as slot number 51 in the queue.}\r
59 \item Collision resolution entry: message identifier + machine id of a\r
60 collision winner\r
61 \newline {The purpose of this is to keep keep track of the winner of \r
62 all the collisions until all clients have seen the particular entry.}\r
63 \end{enumerate}\r
64 \r
65 \subsection{Live status}\r
66 \r
67 Live status of entries:\r
68 \begin{enumerate}\r
69 \item Key-Value Entry is dead if either (a) there is a newer key-value pair or (b) it is incomplete.\r
70         \r
71 \item Slot sequence number (of either a message version data\r
72 or user-level data) is dead if there is a newer slot from the same machine.\r
73 \r
74 \item Queue state entry is dead if there is a newer queue state entry.\r
75 {In the case of queue state entries 50 and 70, this means that queue state \r
76 entry 50 is dead and 70 is live. However, not until the number of slots reaches \r
77 70 that queue state entry 50 will be expunged from the queue.}\r
78 \r
79 \item Collision resolution entry is dead if this entry has been seen\r
80 by all clients after a collision happens.\r
81 \end{enumerate}\r
82 \r
83 When data is at the end of the queue ready to expunge, if:\r
84 \begin{enumerate}\r
85 \item The key-value entry is not dead, it must be reinserted at the\r
86 beginning of the queue.\r
87 \r
88 \item If the slot sequence number is not dead, then a message sequence\r
89 entry must be inserted.\r
90 \r
91 \item If the queue state entry is not dead, it must be reinserted at the\r
92 beginning of the queue.\r
93 \end{enumerate}\r
94 \r
95 \r
96 \paragraph{Reads:}\r
97 Client sends a sequence number.  Server replies with either: all data\r
98 entries or all newer data entries.\r
99 \r
100 \paragraph{Writes:}\r
101 Client sends slot, server verifies that sequence number is valid,\r
102 checks entry hash, and replies with an accept message if all checks\r
103 pass.  On success, client updates its sequence number.  On failure,\r
104 server sends updates slots to client and client validates those slots.\r
105 \r
106 \paragraph{Local state on each client:}\r
107 A list of machines and the corresponding latest sequence numbers.\r
108 \r
109 \paragraph{Validation procedure on client:}\r
110 \begin{enumerate}\r
111 \item Decrypt each new slot in order.\r
112 \item For each slot:\r
113     (a) check its HMAC, and\r
114     (b) check that the previous entry HMAC field matches the previous\r
115     entry.\r
116 \item Check that the last message version for our machine matches our\r
117 last message sent.\r
118 \item For all other machines, check that the latest sequence number is\r
119 at least as large (never goes backwards).\r
120 \item That the queue has a current queue state entry.\r
121 \item That the number of entries received is consistent with the size\r
122 specified in the queue state entry.\r
123 \end{enumerate}\r
124 \r
125 Key-value entries can span multiple slots.  They aren't valid until\r
126 they are complete.\r
127 \r
128 \subsection{Resizing Queue}\r
129 Client can make a request to resize the queue. This is done as a write that combines:\r
130   (a) a slot with the message, and\r
131         (b) a request to the server\r
132 \r
133 \subsection{Server Algorithm}\r
134 $s \in SN$ is a sequence number set\\\r
135 $sv \in SV$ is a slot's value\\\r
136 $slot_s = \tuple{s, sv} \in SL \subseteq SN \times SV$ \\\r
137 \r
138 \textbf{State} \\\r
139 \textit{SL = set of live slots on server} \\\r
140 \textit{max = maximum number of slots (input only for resize message)} \\\r
141 \textit{n = number of slots} \\ \\\r
142 \textbf{Helper Function} \\\r
143 $MaxSlot(SL_s)= \tuple{s, sv} \mid \tuple{s, sv}\r
144 \in SL_s \wedge \forall \tuple{s_s, sv_s} \in SL_s, s \geq s_s$ \\\r
145 $MinSlot(SL_s)= \tuple{s, sv} \mid \tuple{s, sv} \r
146 \in SL_s \wedge \forall \tuple{s_s, sv_s} \in SL_s, s \leq s_s$ \\\r
147 $SeqN(\tuple{s, sv})=s$ \\\r
148 $SlotVal(\tuple{s, sv})=sv$ \\\r
149 \r
150 \begin{algorithmic}[1]\r
151 \Function{GetSlot}{$s_g$}\r
152 \State \Return{$\{\tuple{s, sv} \in SL \mid s \geq s_g\}$}\r
153 \EndFunction\r
154 \end{algorithmic}\r
155 \r
156 \begin{algorithmic}[1]\r
157 \Function{PutSlot}{$s_p,sv_p,max'$}\r
158 \If{$(max' \neq \emptyset)$}\Comment{Resize}\r
159 \State $max \gets max'$\r
160 \EndIf\r
161 \State $\tuple{s_n,sv_n} \gets MaxSlot(SL)$\Comment{Last sv}\r
162 \State $s_n \gets SeqN(\tuple{s_n,sv_n})$\r
163 \If{$(s_p = s_n + 1)$}\r
164         \If{$n = max$}\r
165         \State $\tuple{s_m,sv_m} \gets MinSlot(SL)$\Comment{First sv}\r
166                 \State $SL \gets SL - \{\tuple{s_m,sv_m}\}$\r
167         \Else \Comment{$n < max$}\r
168                 \State $n \gets n + 1$\r
169         \EndIf\r
170     \State $SL \gets SL \cup \{\tuple{s_p,sv_p}\}$\r
171         \State \Return{$(true,\emptyset)$}\r
172 \Else\r
173         \State \Return{$(false,\{\tuple{s,sv}\in SL \mid \r
174     s \geq s_p\})$}\r
175 \EndIf\r
176 \EndFunction\r
177 \end{algorithmic}\r
178 \r
179 \subsection{Client Algorithm}\r
180 \textbf{Data Entry} \\\r
181 $de$ is a data entry \\\r
182 $k$ is key of entry \\\r
183 $v$ is value of entry \\\r
184 $kv$ is a key-value entry $\tuple{k,v}$, $kv \in D$ \\\r
185 $ss$ is a slot sequence entry $\tuple{id,s_{last}}$, \r
186 id + last s of a machine, $ss \in D$ \\\r
187 $qs$ is a queue state entry, $qs \in D$ \\\r
188 $cr$ is a collision resolution entry $\tuple{s_{col},id_{col}}$, \r
189 s + id of a machine that wins a collision, $cr \in D$ \\\r
190 $D = \{kv,ss,qs,cr\}$ \\\r
191 $DE = \{de \mid de \in D\}$ \\ \\\r
192 $s \in SN$ is a sequence number set\\\r
193 $id$ is a machine ID\\\r
194 $hmac_p$ is the HMAC value of the previous slot \\\r
195 $hmac_c$ is the HMAC value of the current slot \\\r
196 $Dat_s = \tuple{s,id,hmac_p,DE,hmac_c}$ \\\r
197 $sv_s = \tuple{s, E(Dat_s)} = \r
198 \tuple{s, E(\tuple{s,id,hmac_p,DE,hmac_c})}$ \\ \\\r
199 \r
200 \textbf{States} \\\r
201 \textit{DT = set of $\tuple{k,v}$ on client} \\\r
202 \textit{MS = set of $\tuple{id, s_{last}}$ of all clients on client \r
203 (initially empty)} \\\r
204 \textit{$MS_c$ = set MS to save all $\tuple{id, s_{last}}$ pairs while\r
205 traversing DT after a request to server (initially empty)} \\\r
206 \textit{$SM$ = set of $\tuple{s, id}$ of all slots in a previous read\r
207 (initially empty)} \\\r
208 \textit{$max_c$ = maximum number of slots (initially $max_c > 0$)} \\\r
209 \textit{m = number of slots on client (initially $m = 0 and m \leq n$)} \\\r
210 \textit{$hmac_p$ = the HMAC value of the previous slot ($hmac_p = \emptyset$ \r
211 for the first slot)} \\\r
212 \textit{$id_{self}$ = machine Id of this client} \\\r
213 \textit{SK = Secret Key} \\ \\\r
214 \textbf{Helper Functions} \\\r
215 $MaxSlot(SL_s)= \tuple{s, sv}$ \textit{such that} $\tuple{s, sv}\r
216 \in SL_s \wedge \forall \tuple{s_s, sv_s} \in SL_s, s \geq s_s$ \\\r
217 $MinSlot(SL_s)= \tuple{s, sv}$ \textit{such that} $\tuple{s, sv} \r
218 \in SL_s \wedge \forall \tuple{s_s, sv_s} \in SL_s, s \leq s_s$ \\\r
219 $Slot(SL_s,s_s)= \tuple{s, sv}$ \textit{such that} $\tuple{s, sv} \r
220 \in SL_s \wedge \forall \tuple{s_s, sv_s} \in SL_s, s = s_s$ \\\r
221 $SeqN(\tuple{s, sv})=s$ \\\r
222 $SlotVal(\tuple{s, sv})=sv$ \\\r
223 $Decrypt(SK_s,sv_s)=Dat_s=\tuple{s,id,hmac_p,DE,hmac_c}$ \\\r
224 $GetSeqN(Dat_s = \tuple{s,id,hmac_p,DE,hmac_c})=s$ \\\r
225 $GetMacId(Dat_s = \tuple{s,id,hmac_p,DE,hmac_c})=id$ \\\r
226 $GetPrevHmac(Dat_s = \tuple{s,id,hmac_p,DE,hmac_c})=hmac_p$ \\\r
227 $GetCurrHmac(Dat_s = \tuple{s,id,hmac_p,DE,hmac_c})=hmac_c$ \\\r
228 $GetDatEnt(Dat_s = \tuple{s,id,hmac_p,DE,hmac_c})=DE$ \\\r
229 $GetKV(de_s$ \textit{such that} $de_s \in D \land de_s = kv)=\tuple{k_s,v_s}$ \\\r
230 $GetSS(de_s$ \textit{such that} $de_s \in D \land de_s = ss)=\tuple{id,s_{last}}$ \\\r
231 $GetQS(de_s$ \textit{such that} $de_s \in D \land de_s = qs)=qs_s$ \\\r
232 $GetCR(de_s$ \textit{such that} $de_s \in D \land de_s = cr)=\tuple{s_s,id_s}$ \\\r
233 $GetLastSeqN(MS_s,id_s)= s_{last}$ \textit{such that} $\tuple{id, s_{last}}\r
234 \in MS_s \wedge \forall \tuple{id_s, s_{s_{last}}} \in MS_s, id = id_s$ \\\r
235 $GetMachineId(SM_s,s_s)= id$ \textit{such that} $\tuple{s, id}\r
236 \in SM_s \wedge \forall \tuple{s_s, id_s} \in SM_s, s = s_s$ \\\r
237 $GetS(\tuple{s, id})=s$ \\\r
238 $GetId(\tuple{s, id})=id$ \\\r
239 $GetKey(\tuple{k, v})=k$ \\\r
240 $GetVal(\tuple{k, v})=v$ \\\r
241 $GetKeyVal(DT_s,k_s)= \tuple{k, v}$ \textit{such that} $\tuple{k, v} \r
242 \in DT_s \wedge \forall \tuple{k_s, v_s} \in DT_s, k = k_s$ \\\r
243 \r
244 \begin{algorithmic}[1]\r
245 \Procedure{ReportError}{$msg$}\r
246 \State $Print(msg)$\r
247 \State $Halt()$\r
248 \EndProcedure\r
249 \end{algorithmic}\r
250 \r
251 \begin{algorithmic}[1]\r
252 \Function{ValidHmac}{$Dat_s,SK_s$}\r
253 \State $hmac_{stored} \gets GetCurrHmac(Dat_s)$\r
254 \State $hmac_{computed} \gets Hmac(Dat_s,SK_s)$\r
255 \If{$hmac_{stored} = hmac_{computed}$}\r
256         \State $valid \gets true$\r
257 \Else\r
258         \State $valid \gets false$\r
259 \EndIf\r
260 \State \Return{$valid$}\r
261 \EndFunction\r
262 \end{algorithmic}\r
263 \r
264 \begin{algorithmic}[1]\r
265 \Function{ValidPrevHmac}{$Dat_s,hmac_{p_s}$}\r
266 \If{$hmac_{p_s} = \emptyset$}\Comment{First slot - no previous HMAC}\r
267         \State $valid \gets true$\r
268 \Else\r
269         \State $hmac_{stored} \gets GetPrevHmac(Dat_s)$\r
270         \If{$hmac_{stored} = hmac_{p_s}$}\r
271                 \State $valid \gets true$\r
272         \Else\r
273                 \State $valid \gets false$\r
274         \EndIf\r
275 \EndIf\r
276 \State \Return{$valid$}\r
277 \EndFunction\r
278 \end{algorithmic}\r
279 \r
280 \begin{algorithmic}[1]\r
281 \Function{GetQueSta}{$Dat_s$}\r
282 \State $DE_s \gets GetDatEnt(Dat_s)$\r
283 \State $de_{qs} \gets de_s$ \textit{such that} $de_s \in DE_s, \r
284         de_s \in D \land de_s = qs$\r
285 \If{$de_{qs} \neq \emptyset$}\r
286         \State $qs_{ret} \gets GetQS(de_{qs})$\r
287 \Else\r
288         \State $qs_{ret} \gets \emptyset$\r
289 \EndIf\r
290 \State \Return{$qs_{ret}$}\r
291 \EndFunction\r
292 \end{algorithmic}\r
293 \r
294 \begin{algorithmic}[1]\r
295 \Function{GetSlotSeq}{$Dat_s$}\r
296 \State $DE_s \gets GetDatEnt(Dat_s)$\r
297 \State $de_{ss} \gets de_s$ \textit{such that} $de_s \in DE_s, \r
298         de_s \in D \land de_s = ss$\r
299 \If{$de_{ss} \neq \emptyset$}\r
300         \State $\tuple{id_{ret},s_{last_{ret}}} \gets GetSS(de_{ss})$\r
301 \Else\r
302         \State $\tuple{id_{ret},s_{last_{ret}}} \gets \emptyset$\r
303 \EndIf\r
304 \State \Return{$\tuple{id_{ret},s_{last_{ret}}}$}\r
305 \EndFunction\r
306 \end{algorithmic}\r
307 \r
308 \begin{algorithmic}[1]\r
309 \Function{GetColRes}{$Dat_s$}\r
310 \State $DE_s \gets GetDatEnt(Dat_s)$\r
311 \State $de_{cr} \gets de_s$ \textit{such that} $de_s \in DE_s, \r
312         de_s \in D \land de_s = cr$\r
313 \If{$de_{cr} \neq \emptyset$}\r
314         \State $\tuple{s_{ret},id_{ret}} \gets GetCR(de_{cr})$\r
315 \Else\r
316         \State $\tuple{s_{ret},id_{ret}} \r
317         \gets \emptyset$\r
318 \EndIf\r
319 \State \Return{$\tuple{s_{ret},id_{ret}}$}\r
320 \EndFunction\r
321 \end{algorithmic}\r
322 \r
323 \begin{algorithmic}[1]\r
324 \Function{UpdateLastSeqN}{$id_s,s_s,MS_s$}\r
325 \State $s_t \gets GetLastSeqN(MS_s,id_s)$\r
326 \If{$s_t = \emptyset$}\r
327         \State $MS_s \gets MS_s \cup \{\tuple{id_s,s_s}\}$\Comment{First occurrence}\r
328 \Else\r
329         \If{$s_s > s_t$}\Comment{Update entry with a later s}\r
330         \State $MS_s \gets (MS_s - \{\tuple{id_s,s_t}\}) \cup \r
331                 \{\tuple{id_s,s_s}\}$\r
332     \EndIf\r
333 \EndIf\r
334 \State \Return{$MS_s$}\r
335 \EndFunction\r
336 \end{algorithmic}\r
337 \r
338 \begin{algorithmic}[1]\r
339 \Procedure{CheckLastSeqN}{$MS_s,MS_t$}\Comment{Check $MS_t$ based on $MS_s$}\r
340 \ForAll{$\tuple{id_t,s_{t_{last}}} \in MS_t$}\r
341         \State $s_{s_{last}} \gets GetLastSeqN(MS_s,id_t)$\r
342         \If{$s_{s_{last}} \neq \emptyset$}\r
343                 \If{$id_t = id_{self}$}\r
344                 \If{$s_{s_{last}} \neq s_{t_{last}}$}\r
345                                 \State \Call{ReportError}{'Invalid last $s$ for this machine'}\r
346                         \EndIf\r
347                 \Else\r
348                         \If{$s_{s_{last}} \geq s_{t_{last}}$}\r
349                                 \State $MS_s \gets (MS_s - \{\tuple{id_t,s_{t_{last}}}\}) \cup \r
350                                 \{\tuple{id_t,s_{s_{last}}}\}$\r
351                         \Else\r
352                                 \State \Call{ReportError}{'Invalid last $s$ for machine $id_t$'}\r
353                         \EndIf\r
354                 \EndIf\r
355         \EndIf\r
356 \EndFor\r
357 \EndProcedure\r
358 \end{algorithmic}\r
359 \r
360 \begin{algorithmic}[1]\r
361 \Procedure{CheckColRes}{$SM_s,\tuple{s_t,id_t}$}\Comment{Check $id_s$ in $SM_s$}\r
362 \State $s_t \gets GetS(\tuple{s_t,id_t})$\r
363 \State $id_t \gets GetId(\tuple{s_t,id_t})$\r
364 \State $id_s \gets GetMachineId(SM_s,s_t)$\r
365 \If{$id_s \neq id_t$}\r
366         \State \Call{ReportError}{'Invalid $id_s$ for this slot update'}\r
367 \EndIf\r
368 \EndProcedure\r
369 \end{algorithmic}\r
370 \r
371 \begin{algorithmic}[1]\r
372 \Function{UpdateDT}{$DT_s,Dat_s$}\r
373 \State $DE_s \gets GetDatEnt(Dat_s)$\r
374 \ForAll{$de_s \in DE_s$}\r
375         \If{$de_s$ \textit{such that} $de_s \in D \land de_s = kv$}\r
376                 \State $\tuple{k_s,v_s} \gets GetKV(de_s)$\r
377                 \State $k_s \gets GetKey(\tuple{k_s,v_s})$\r
378                 \State $\tuple{k_s,v_t} \gets GetKeyVal(DT_s,k_s)$\r
379                 \If{$\tuple{k_s,v_t} = \emptyset$}\r
380                         \State $DT_s \gets DT_s \cup \{\tuple{k_s,v_s}\}$\r
381                 \Else\r
382                 \State $DT_s \gets (DT_s - \{\tuple{k_s,v_t}\}) \cup \r
383                         \{\tuple{k_s,v_s}\}$\r
384                 \EndIf\r
385     \EndIf\r
386 \EndFor\r
387 \State \Return{$DT_s$}\r
388 \EndFunction\r
389 \end{algorithmic}\r
390 \r
391 \begin{algorithmic}[1]\r
392 \Function{GetKVPairs}{$s$}\r
393 \State $SL_c \gets \Call{GetSlot}{s}$\r
394 \State $MS_c \gets \emptyset$\r
395 \State $SM_{curr} \gets \emptyset$\r
396 \State $\tuple{s_{c_{max}},sv_{c_{max}}} \gets MaxSlot(SL_c)$\r
397 \State $s_{c_{max}} \gets SeqN(\tuple{s_{c_{max}},sv_{c_{max}}})$\r
398 \State $\tuple{s_{c_{min}},sv_{c_{min}}} \gets MinSlot(SL_c)$\r
399 \State $s_{c_{min}} \gets SeqN(\tuple{s_{c_{min}},sv_{c_{min}}})$\r
400 \For{$s_c \gets s_{c_{min}}$ \textbf{to} $s_{c_{max}}$}\Comment{Process slots \r
401         in $SL_c$ in order}\r
402         \State $\tuple{s_c,sv_c} \gets Slot(SL_c,s_c)$\r
403         \State $SM_{curr} \gets SM_{curr} \cup \{\tuple{s_c,sv_c}\}$\r
404     \State $s_c \gets SeqN(\tuple{s_c,sv_c})$\r
405         \State $sv_c \gets SlotVal(\tuple{s_c,sv_c})$\r
406         \State $Dat_c \gets Decrypt(SK,sv_c)$\r
407         \State $s_{c_{in}} \gets GetSeqN(Dat_c)$\r
408     \If{$s_c \neq s_{c_{in}}$}\r
409                 \State \Call{ReportError}{'Invalid sequence number'}\r
410         \EndIf\r
411         \If{$\neg \Call{ValidPrevHmac}{Dat_c,hmac_p}$}\r
412                 \State \Call{ReportError}{'Invalid previous HMAC value'}\r
413         \EndIf\r
414         \If{$\neg \Call{ValidHmac}{Dat_c,SK}$}\r
415                 \State \Call{ReportError}{'Invalid current HMAC value'}\r
416         \EndIf\r
417         \State $hmac_p \gets Hmac(Dat_c,SK)$\Comment{Update $hmac_p$ for next slot check}\r
418         \State $qs_c \gets \Call{GetQueSta}{Dat_c}$\Comment{Handle qs}\r
419         \If{$qs_c \neq \emptyset \land qs_c > max_c$}\r
420                 \State $max_c \gets qs_c$\r
421         \EndIf\r
422     %Check for last s in Dat\r
423         \State $id_c \gets GetMacId(Dat_c)$\Comment{Handle last s}\r
424         \State $MS_c \gets \Call{UpdateLastSeqN}{id_c,s_c,MS_c}$\r
425     %Check for last s in DE in Dat\r
426     \State $\tuple{id_d,s_{d_{last}}} \gets \Call{GetSlotSeq}{Dat_c}$\Comment{Handle ss}\r
427         \If{$\tuple{id_d,s_{d_{last}}} \neq \emptyset$}\r
428         \State $MS_c \gets \Call{UpdateLastSeqN}{id_d,s_{d_{last}},MS_c}$\r
429         \EndIf\r
430         \State $\tuple{s_e,id_e} \gets \r
431         \Call{GetColRes}{Dat_c}$\Comment{Handle cr}\r
432         \If{$\tuple{s_e,id_e} \neq \emptyset$}\r
433                 \State $s_e \gets GetS(\tuple{s_e,id_e})$\r
434                 \State $id_e \gets GetId(\tuple{s_e,id_e})$\r
435                 \State $s_{c_{last}} \gets GetLastSeqN(MS,id_e)$\r
436                 \If{$s_{c_{last}} < s_e$}\r
437                         \State $\Call{CheckColRes}{SM,\tuple{s_e,id_e}}$\r
438                 \EndIf\r
439     \EndIf\r
440         \State $DT \gets \Call{UpdateDT}{DT,Dat_c}$\r
441 \EndFor\r
442 \State $SM \gets SM_{curr}$\r
443 \If{$m + |SL_c| \leq max_c$}\Comment{Check actual size against $max_c$}\r
444         \State $m \gets m + |SL_c|$\r
445 \Else\r
446         \State \Call{ReportError}{'Actual queue size exceeds $max_c$'}\r
447 \EndIf\r
448 \State $\Call{CheckLastSeqN}{MS_c,MS}$\r
449 \State \Return{$DT$}\r
450 \EndFunction\r
451 \end{algorithmic}\r
452 \r
453 \begin{algorithmic}[1]\r
454 \Function{GetValFromKey}{$k_g$}\r
455 \State $\tuple{k_s,v_s} \gets \tuple{k,v}$ \textit{such that} $\tuple{k,v} \r
456         \in DT \land k = k_g$\r
457 \State $v_s \gets GetVal(\tuple{k_s,v_s})$\r
458 \State \Return{$v_s$}\r
459 \EndFunction\r
460 \end{algorithmic}\r
461 \r
462 \subsection{Formal Guarantees}\r
463 \r
464 \textit{To be completed ...}\r
465 \r
466 \begin{defn}[System Execution]\r
467 Let \\\r
468 \begin{center}\r
469 $Q = \{slot_{sn_1}, slot_{sn_2}, \dots, Slot_{sn_n}\}$, \\\r
470 $SN = \{sn_1, sn_2, \dots, sn_n\}$ \\\r
471 \end{center}\r
472 denote a queue $Q$ of $n$ slots, with each slot entry being denoted by a\r
473 valid sequence number $sn_i \in SN$. $Q$ represents a total order of all \r
474 slot updates from all corresponding machines.\r
475 %\textit{Formalize a system execution as a sequence of slot updates...\r
476 %There is a total order of all slot updates.}\r
477 \end{defn}\r
478 \r
479 \begin{defn}[Transitive Closure]\r
480 A transitive closure $\tau : \tau = \epsilon_{update(slot_i)} R $\r
481 $\epsilon_{receive(slot_i)}$ is a relation from slot update event\r
482 $\epsilon$ to a slot receive event $\epsilon$ for $slot_i$.\r
483 %Define transitive closure relation for slot updates...  There is an\r
484 %edge from a slot update to a slot receive event if the receive event\r
485 %reads from the update event.\r
486 \end{defn}\r
487 \r
488 \begin{defn}[Suborder]\r
489 Let \\\r
490 \begin{center}\r
491 $q = \{slot_{i}, slot_{i+1}, \dots, slot_{j}\}, \r
492 sn_1 \leq i \leq j \leq sn_n \Longrightarrow q \subseteq Q$\r
493 \end{center}\r
494 denote a suborder of the total order. Set q is a sequence of contiguous\r
495 slot updates that is a subset of a total order of all slot updates in Q.\r
496 %Define suborder of total order.  It is a sequence of contiguous slots\r
497 %updates (as observed by a given device).\r
498 \end{defn}\r
499 \r
500 \begin{defn}[Prefix of a suborder]\r
501 Given a suborder \\ \r
502 \begin{center}\r
503 $q' = \{slot_{i}, slot_{i+1}, \dots, slot_{j}, \dots\}, \r
504 sn_1 \leq i \leq j \leq sn_n \Longrightarrow \r
505 q' \subseteq Q$\r
506 \end{center}\r
507 with $slot_{j}$ as a slot update in $q'$, the prefix of $q'$ is a sequence \r
508 of all slot updates $\{slot_{i}, slot_{i+1}, \dots, slot_{j-1}\} \cup\r
509 slot_{j}$.\r
510 %Given a sub order $o=u_{i},u_{i+1},...,u_j, u_{j+i},..., u', ...$ and\r
511 %a slot update $u'$ in $o$, the prefix of $o$ is a sequence of all\r
512 %updates that occur before $u'$ and $u'$.\r
513 \end{defn}\r
514 \r
515 \begin{defn}[Consistency between a suborder and a total order]\r
516 A suborder $q'$ is consistent with a total order $T$ of $Q$, if all\r
517 updates in $q'$ appear in $T$ and they appear in the same order, as \r
518 the following:\r
519 \begin{center}\r
520 $q' = \{slot_{i}, slot_{i+1}, \dots, slot_{j}\},$\r
521 $T = \{slot_{sn_1}, \dots, slot_{i}, slot_{i+1}, \dots, slot_{j}, \dots,\r
522 slot_{sn_n}\},$ \\ $sn_1 \leq i \leq j \leq sn_n \Longrightarrow\r
523 q' \subseteq T$\r
524 \end{center}\r
525 %A suborder $o$ is consistent with a total order $t$, if all updates in $o$ %appear in $t$ and they appear in the same order.\r
526 \end{defn}\r
527 \r
528 \begin{defn}[Consistency between suborders]\r
529 Two suborders U and V are consistent if there exist a total order T \r
530 such that both U and V are suborders of T.\r
531 \begin{center}\r
532 $U = \{slot_{i}, slot_{i+1}, \dots, slot_{j}\},$ \\\r
533 $V = \{slot_{k}, slot_{k+1}, \dots, slot_{l}\},$ \\\r
534 $sn_1 \leq i \leq j \leq k \leq l \leq sn_n,$ \\\r
535 $U \subset T \land V \subset T$ \\\r
536 $T = \{slot_{sn_1}, \dots, slot_{i}, slot_{i+1}, \dots, slot_{j}, $\\\r
537 $\dots, slot_{k}, slot_{k+1}, \dots, slot_{l}, \dots, slot_{sn_n}\}$\r
538 \end{center}\r
539 %Define notion of consistency between suborders...  Two suborders U,V\r
540 %are consistent if there exist a total order T such that both U and V\r
541 %are suborders of T.\r
542 \end{defn}\r
543 \r
544 \begin{defn}[Error-free execution]\r
545 An error-free execution, for which the client does not flag any errors\r
546 is defined by the following criteria:\r
547 \begin{enumerate}\r
548 \item Item 1\r
549 \item Item 2\r
550 \end{enumerate}\r
551 %not flag any errors...\r
552 %Define error-free execution --- execution for which the client does\r
553 %not flag any errors...\r
554 \end{defn}\r
555 \r
556 \begin{theorem} Error-free execution of algorithm ensures that the suborder\r
557 for node n is consistent with the prefix suborder for all other nodes\r
558 that are in the transitive closure.\r
559 \end{theorem}\r
560 \begin{proof}\r
561 \textit{TODO}\r
562 \end{proof}\r
563 \r
564 \begin{defn}[State of Data Structure]\r
565 Define in terms of playing all updates sequentially onto local data\r
566 structure.\r
567 \end{defn}\r
568 \r
569 \begin{theorem}\r
570 Algorithm gives consistent view of data structure.\r
571 \end{theorem}\r
572 \begin{proof}\r
573 \textit{TODO}\r
574 \end{proof}\r
575 \r
576 \subsection{Future Work}\r
577 \paragraph{Support Messages}\r
578   A message is dead once receiving machine sends an entry with a newer\r
579   sequence identifier\r
580 \r
581 \paragraph{Persistent data structures}\r
582         Root object w/ fields\r
583         Other objects can be reachable from root\r
584         Each object has its own entries\r
585         Dead objects correspond to dead \r
586 \r
587 \paragraph{Multiple App Sharing}\r
588 \r
589 Idea is to separate subspace of entries...  Shared with other cloud...\r
590 \end{document}\r
591 \r