acad12b9ce4cb0425fdd575d5ebfa9425df26e5a
[iotcloud.git] / doc / iotcloud.tex
1 \documentclass[11pt]{article}\r
2 \newcommand{\tuple}[1]{\ensuremath \langle #1 \rangle}\r
3 \usepackage{amsthm}\r
4 \newtheorem{theorem}{Theorem}\r
5 \newtheorem{defn}{Definition}\r
6 \r
7 \begin{document}\r
8 \section{Approach}\r
9 \r
10 \subsection{Keys}\r
11 \r
12 Each device has: user id + password\r
13 \r
14 Server login is:\r
15 hash1(user id), hash1(password)\r
16 \r
17 Symmetric Crypto keys is:\r
18 hash2(user id | password)\r
19 \r
20 Server has finite length queue of entries + max\_entry\_identifier +\r
21 server login key\r
22 \r
23 \subsection{Entry layout}\r
24 Each entry has:\r
25 \begin{enumerate}\r
26 \item Sequence identifier\r
27 \item Random IV (if needed by crypto algorithm)\r
28 \item Encrypted payload\r
29 \end{enumerate}\r
30 \r
31 Payload has:\r
32 \begin{enumerate}\r
33 \item Sequence identifier\r
34 \item Machine id (most probably something like a 64-bit random number \r
35 that is self-generated by client)\r
36 \item HMAC of previous slot\r
37 \item Data entries\r
38 \item HMAC of current slot\r
39 \end{enumerate}\r
40 \r
41 A data entry can be one of these:\r
42 \begin{enumerate}\r
43 \item All or part of a Key-value entry\r
44 \item Slot sequence entry: Machine id + last message identifier \r
45 \newline {The purpose of this is to keep the record of the last slot \r
46 from a certain client if a client's update has to expunge that other \r
47 client's last entry from the queue. This is kept in the slot until \r
48 the entry owner inserts a newer update into the queue.}\r
49 \item Queue state entry: Includes queue size \newline {The purpose \r
50 of this is for the client to tell if the server lies about the number \r
51 of slots in the queue, e.g. if there are 2 queue state entry in the queue, \r
52 e.g. 50 and 70, the client knows that when it sees 50, it should expect \r
53 at most 50 slots in the queue and after it sees 70, it should expect \r
54 50 slots before that queue state entry slot 50 and at most 70 slots. \r
55 The queue state entry slot 70 is counted as slot number 51 in the queue.}\r
56 \end{enumerate}\r
57 \r
58 \subsection{Live status}\r
59 \r
60 Live status of entries:\r
61 \begin{enumerate}\r
62 \item Key-Value Entry is dead if either (a) there is a newer key-value pair or (b) it is incomplete.\r
63         \r
64 \item Slot sequence number (of either a message version data\r
65 or user-level data) is dead if there is a newer slot from the same machine.\r
66 \r
67 \item Queue state entry is dead if there is a newer queue state entry.\r
68 {In the case of queue state entries 50 and 70, this means that queue state \r
69 entry 50 is dead and 70 is live. However, not until the number of slotes reaches \r
70 70 that queue state entry 50 will be expunged from the queue.}\r
71 \end{enumerate}\r
72 \r
73 When data is at the end of the queue ready to expunge, if:\r
74 \begin{enumerate}\r
75 \item The key-value entry is not dead, it must be reinserted at the\r
76 beginning of the queue.\r
77 \r
78 \item If the slot sequence number is not dead, then a message sequence\r
79 entry must be inserted.\r
80 \r
81 \item If the queue state entry is not dead, it must be reinserted at the\r
82 beginning of the queue.\r
83 \end{enumerate}\r
84 \r
85 \r
86 \paragraph{Reads:}\r
87 Client sends a sequence number.  Server replies with either: all data\r
88 entries or all newer data entries.\r
89 \r
90 \paragraph{Writes:}\r
91 Client sends slot, server verifies that sequence number is valid,\r
92 checks entry hash, and replies with an accept message if all checks\r
93 pass.  On success, client updates its sequence number.  On failure,\r
94 server sends updates slots to client and client validates those slots.\r
95 \r
96 \paragraph{Local state on each client:}\r
97 A list of machines and the corresponding latest sequence numbers.\r
98 \r
99 \paragraph{Validation procedure on client:}\r
100 \begin{enumerate}\r
101 \item Decrypt each new slot in order.\r
102 \item For each slot:\r
103     (a) check its HMAC, and\r
104     (b) check that the previous entry HMAC field matches the previous\r
105     entry.\r
106 \item Check that the last message version for our machine matches our\r
107 last message sent.\r
108 \item For all other machines, check that the latest sequence number is\r
109 at least as large (never goes backwards).\r
110 \item That the queue has a current queue state entry.\r
111 \item That the number of entries received is consistent with the size\r
112 specified in the queue state entry.\r
113 \end{enumerate}\r
114 \r
115 Key-value entries can span multiple slots.  They aren't valid until\r
116 they are complete.\r
117 \r
118 \subsection{Resizing Queue}\r
119 Client can make a request to resize the queue. This is done as a write that combines:\r
120   (a) a slot with the message, and\r
121         (b) a request to the server\r
122 \r
123 \subsection{Formal Guarantees}\r
124 \r
125 \textit{To be completed ...}\r
126 \r
127 \begin{defn}[System Execution]\r
128 Formalize a system execution as a sequence of slot updates...  There\r
129 is a total order of all slot updates.\r
130 \end{defn}\r
131 \r
132 \begin{defn}[Transitive Closure]\r
133 Define transitive closure relation for slot updates...  There is an\r
134 edge from a slot update to a slot receive event if the receive event\r
135 reads from the update event.\r
136 \end{defn}\r
137 \r
138 \begin{defn}[Suborder]\r
139 Define suborder of total order.  It is a sequence of contiguous slots\r
140 updates (as observed by a given device).\r
141 \end{defn}\r
142 \r
143 \begin{defn}[Prefix of a suborder]\r
144 Given a sub order $o=u_{i},u_{i+1},...,u_j, u_{j+i},..., u', ...$ and\r
145 a slot update $u'$ in $o$, the prefix of $o$ is a sequence of all\r
146 updates that occur before $u'$ and $u'$.\r
147 \end{defn}\r
148 \r
149 \begin{defn}[Consistency between a suborder and a total order]\r
150 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
151 \end{defn}\r
152 \r
153 \begin{defn}[Consistency between suborders]\r
154 Define notion of consistency between suborders...  Two suborders U,V\r
155 are consistent if there exist a total order T such that both U and V\r
156 are suborders of T.\r
157 \end{defn}\r
158 \r
159 \begin{defn}[Error-free execution]\r
160 Define error-free execution --- execution for which the client does\r
161 not flag any errors...\r
162 \end{defn}\r
163 \r
164 \begin{theorem} Error-free execution of algorithm ensures that the suborder\r
165 for node n is consistent with the prefix suborder for all other nodes\r
166 that are in the transitive closure.\r
167 \end{theorem}\r
168 \begin{proof}\r
169 \textit{TODO}\r
170 \end{proof}\r
171 \r
172 \begin{defn}[State of Data Structure]\r
173 Define in terms of playing all updates sequentially onto local data\r
174 structure.\r
175 \end{defn}\r
176 \r
177 \begin{theorem}\r
178 Algorithm gives consistent view of data structure.\r
179 \end{theorem}\r
180 \begin{proof}\r
181 \textit{TODO}\r
182 \end{proof}\r
183 \r
184 \subsection{Future Work}\r
185 \paragraph{Support Messages}\r
186   A message is dead once receiving machine sends an entry with a newer\r
187   sequence identifier\r
188 \r
189 \paragraph{Persistent data structures}\r
190         Root object w/ fields\r
191         Other objects can be reachable from root\r
192         Each object has its own entries\r
193         Dead objects correspond to dead \r
194 \r
195 \paragraph{Multiple App Sharing}\r
196 \r
197 Idea is to separate subspace of entries...  Shared with other cloud...\r
198 \end{document}\r