Revised client algorithm - part that gets slots from server
authorrtrimana <rtrimana@uci.edu>
Thu, 14 Jul 2016 17:23:18 +0000 (10:23 -0700)
committerrtrimana <rtrimana@uci.edu>
Thu, 14 Jul 2016 17:23:18 +0000 (10:23 -0700)
doc/iotcloud.tex

index 5a362c92fabc495d7e0fca3fc4b5d6a5cc690abe..eb6fca108e8d8819a20d66a56bb33a7d06359803 100644 (file)
@@ -2,7 +2,6 @@
 \newcommand{\tuple}[1]{\ensuremath \langle #1 \rangle}\r
 \usepackage{color}\r
 \usepackage{amsthm}\r
 \newcommand{\tuple}[1]{\ensuremath \langle #1 \rangle}\r
 \usepackage{color}\r
 \usepackage{amsthm}\r
-\usepackage{amsmath}\r
 \usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx\r
 \newtheorem{theorem}{Theorem}\r
 \newtheorem{defn}{Definition}\r
 \usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx\r
 \newtheorem{theorem}{Theorem}\r
 \newtheorem{defn}{Definition}\r
@@ -52,11 +51,15 @@ client's last entry from the queue. This is kept in the slot until
 the entry owner inserts a newer update into the queue.}\r
 \item Queue state entry: Includes queue size \newline {The purpose \r
 of this is for the client to tell if the server lies about the number \r
 the entry owner inserts a newer update into the queue.}\r
 \item Queue state entry: Includes queue size \newline {The purpose \r
 of this is for the client to tell if the server lies about the number \r
-of slots in the queue, e.g. if there are 2 queue state entries in the queue, \r
+of slots in the queue, e.g. if there are 2 queue state entry in the queue, \r
 e.g. 50 and 70, the client knows that when it sees 50, it should expect \r
 at most 50 slots in the queue and after it sees 70, it should expect \r
 50 slots before that queue state entry slot 50 and at most 70 slots. \r
 The queue state entry slot 70 is counted as slot number 51 in the queue.}\r
 e.g. 50 and 70, the client knows that when it sees 50, it should expect \r
 at most 50 slots in the queue and after it sees 70, it should expect \r
 50 slots before that queue state entry slot 50 and at most 70 slots. \r
 The queue state entry slot 70 is counted as slot number 51 in the queue.}\r
+\item Collision resolution entry: Machine id + message identifier of\r
+collision winner\r
+\newline {The purpose of this is to keep keep track of the winner of \r
+all the collisions until all clients have seen the particular entry.}\r
 \end{enumerate}\r
 \r
 \subsection{Live status}\r
 \end{enumerate}\r
 \r
 \subsection{Live status}\r
@@ -72,6 +75,9 @@ or user-level data) is dead if there is a newer slot from the same machine.
 {In the case of queue state entries 50 and 70, this means that queue state \r
 entry 50 is dead and 70 is live. However, not until the number of slots reaches \r
 70 that queue state entry 50 will be expunged from the queue.}\r
 {In the case of queue state entries 50 and 70, this means that queue state \r
 entry 50 is dead and 70 is live. However, not until the number of slots reaches \r
 70 that queue state entry 50 will be expunged from the queue.}\r
+\r
+\item Collision resolution entry is dead if there this entry has been seen\r
+by all clients after a collision happens.\r
 \end{enumerate}\r
 \r
 When data is at the end of the queue ready to expunge, if:\r
 \end{enumerate}\r
 \r
 When data is at the end of the queue ready to expunge, if:\r
@@ -171,109 +177,244 @@ $SlotVal(\tuple{s, sv})=sv$ \\
 \end{algorithmic}\r
 \r
 \subsection{Client Algorithm}\r
 \end{algorithmic}\r
 \r
 \subsection{Client Algorithm}\r
+\textbf{Data Entry} \\\r
+$de$ is a data entry \\\r
+$k$ is key of entry \\\r
+$v$ is value of entry \\\r
+$kv$ is a key-value entry $\tuple{k,v}$, $kv \in D$ \\\r
+$ss$ is a slot sequence entry $\tuple{id,s_{last}}$, \r
+id + last s of a machine, $ss \in D$ \\\r
+$qs$ is a queue state entry, $qs \in D$ \\\r
+$D = \{kv,ss,qs\}$ \\\r
+$DE = \{de \mid de \in D\}$ \\ \\\r
+$s \in SN$ is a sequence number set\\\r
+$id$ is a machine ID\\\r
+$hmac_p$ is the HMAC value of the previous slot \\\r
+$hmac_c$ is the HMAC value of the current slot \\\r
+$Dat_s = \tuple{s,id,hmac_p,DE,hmac_c}$ \\\r
+$sv_s = \tuple{s, E(Dat_s)} = \r
+\tuple{s, E(\tuple{s,id,hmac_p,DE,hmac_c})}$ \\ \\\r
+\r
+\textbf{States} \\\r
+\textit{DT = set of $\tuple{k,v}$ on client} \\\r
+\textit{MS = set of $\tuple{id, s_{last}}$ of all clients on client \r
+(initially empty)} \\\r
+\textit{$MS_c$ = set MS to save all $\tuple{id, s_{last}}$ pairs while\r
+traversing DT after a request to server (initially empty)} \\\r
+\textit{$max_c$ = maximum number of slots (initially $max_c > 0$)} \\\r
+\textit{m = number of slots on client (initially $m = 0 \mid m \leq n$)} \\\r
+\textit{$hmac_p$ = the HMAC value of the previous slot ($hmac_p = \emptyset$ \r
+for the first slot)} \\\r
+\textit{$id_{self}$ = machine Id of this client} \\\r
+\textit{SK = Secret Key} \\ \\\r
+\textbf{Helper Functions} \\\r
+$MaxSlot(SL_s)= \tuple{s, sv} \mid \tuple{s, sv}\r
+\in SL_s \wedge \forall \tuple{s_s, sv_s} \in SL_s, s \geq s_s$ \\\r
+$MinSlot(SL_s)= \tuple{s, sv} \mid \tuple{s, sv} \r
+\in SL_s \wedge \forall \tuple{s_s, sv_s} \in SL_s, s \leq s_s$ \\\r
+$SeqN(\tuple{s, sv})=s$ \\\r
+$SlotVal(\tuple{s, sv})=sv$ \\\r
+$Decrypt(SK_s,sv_s)=Dat_s=\tuple{s,id,hmac_p,DE,hmac_c}$ \\\r
+$ComputeHash(bit_s)$ is a hash function that generates hash value on $bit_s$ \\\r
+$ComputeHmac(bit_s,SK_s)$ is a HMAC function that generates HMAC value on $bit_s$ \r
+based on key $SK_s$\\\r
+$GetSeqN(Dat_s = \tuple{s,id,hmac_p,DE,hmac_c})=s$ \\\r
+$GetMacId(Dat_s = \tuple{s,id,hmac_p,DE,hmac_c})=id$ \\\r
+$GetPrevHmac(Dat_s = \tuple{s,id,hmac_p,DE,hmac_c})=hmac_p$ \\\r
+$GetCurrHmac(Dat_s = \tuple{s,id,hmac_p,DE,hmac_c})=hmac_c$ \\\r
+$GetDatEnt(Dat_s = \tuple{s,id,hmac_p,DE,hmac_c})=DE$ \\\r
+$GetQS(de_s \mid de_s \in D \land de_s = qs)=qs$ \\\r
+$GetSS(de_s \mid de_s \in D \land de_s = ss)=ss$ \\\r
+$GetKV(de_s \mid de_s \in D \land de_s = kv)=kv=\tuple{k,v}$ \\\r
+$GetLastSeqN(MS_s,id_s)= s_{last} \mid \tuple{id, s_{last}}\r
+\in MS_s \wedge \forall \tuple{id_s, s_{s_{last}}} \in MS_s, \r
+id = id_s$ \\\r
+$GetKey(\tuple{k, v})=k$ \\\r
+$GetVal(\tuple{k, v})=v$ \\\r
+$GetKeyVal(DT_s,k_s)= \tuple{k, v} \mid \tuple{k, v} \r
+\in DT_s \wedge \forall \tuple{k_s, v_s} \in DT_s, k = k_s$ \\\r
+\r
 \begin{algorithmic}[1]\r
 \begin{algorithmic}[1]\r
-\Function{CallClient}{$uid,pw,d,m,max,s,Data*,Result*$}\r
-\textit{\r
-\newline{// uid = user identification}\r
-\newline{// pw = password}\r
-\newline{// d = new data for write}\r
-\newline{// m = client message (read/write/resize)}\r
-\newline{// max = maximum number of slots (input only for resize message)}\r
-\newline{// n = number of slots}\r
-\newline{// s = sequence number for server request}\r
-\newline{// t = sequence numbers of slots on server}\r
-\newline{// mid = machine identification}\r
-\newline{// seq = sequence number inside slot}\r
-\newline{// newSlot = new slot}\r
-\newline{// expSlot = expunged/expired slot}\r
-\newline{// slotSeqE = slot sequence entry}\r
-\newline{// M = list of all machines/devices with their respective latest s on client}\r
-\newline{// Data = array of slots written/read (input only for write)}\r
-\newline{// Result = array of decrypted and valid slots after a read}\r
-\newline{// Slot = one data slot)}\r
-\newline{// DSlot = one decrypted data slot)}\r
-}\r
-\State $SK = Hash(uid + pw)$\r
-\If{$m = read$}\r
-       \State $Data \gets CallServer(m,max,s,Data)$\r
-       \If{$Data = \emptyset$}\r
-               \State $ReportError(\emptyset,read)$\r
-       \Else\r
-               \If{$\neg HasCurrentQueueStateEntry(Data)$}\r
-                       \State $ReportError(DSlot_i,read)$\r
-               \EndIf\r
-               \ForAll{$Slot_i \in Data$}\r
-                       \State $DSlot_i \gets Decrypt(SK,Slot_i)$\Comment{Check s and HMAC}\r
-                       \If{$\neg (ValidSeqN(DSlot_i) \land ValidHmac(DSlot_i) \land $\\\r
-                               \push[1] $ValidPrevHmac(DSlot_i))$}\r
-                               \State $ReportError(DSlot_i,read)$\r
-                       \Else\Comment{Check only live entries}\r
-                               \If{$IsLiveSlotSequenceEntry(DSlot_i)$}\r
-                                       \State $lastS \gets LastSeqN(DSlot_i)$\r
-                                       \State $lastMid \gets LastMachineId(DSlot_i)$\r
-                                       \If{$lastS \neq LastSeqN(lastMid,M)$}\r
-                                               \State $ReportError(DSlot_i,read)$\r
-                                       \EndIf\r
-                               \ElsIf{$IsLiveKeyValueEntry(DSlot_i)$}\r
-                                       \State $mid \gets MachineId(DSlot_i)$\r
-                                       \State $seq \gets SeqN(DSlot_i)$\r
-                                       \If{$IsOwnMid(mid)$}\r
-                                               \If{$IsLastS(mid,seq,Data) \land $\\\r
-                                               \push[1] $(seq \neq LastSeqN(mid,M))$}\r
-                                                       \State $ReportError(DSlot_i,read)$\r
-                                               \EndIf\r
-                                       \Else\Comment{Check s for other machines}\r
-                                               \If{$IsLastS(mid,seq,Data) \land $\\\r
-                                               \push[1] $(seq < LastSeqN(mid,M))$}\r
-                                                       \State $ReportError(DSlot_i,read)$\r
-                                               \EndIf\r
-                                       \EndIf\Comment{Check queue state entry}\r
-                               \ElsIf{$IsLiveQueueStateEntry(DSlot_i)$}\r
-                                       \If{$IsCurrentQueueState(DSlot_i)$}\r
-                                               \If{$Length(Data) > QueueLength(DSlot_i)$}\r
-                                                       \State $ReportError(DSlot_i,read)$\r
-                                               \EndIf\r
-                                       \EndIf\r
-                               \Else\r
-                                       \State $ReportError(DSlot_i,read)$\r
-                               \EndIf\r
-                       \EndIf\r
-                       \State $Result \gets Concat(Result, DSlot_i)$\r
-               \EndFor\r
-       \EndIf\r
+\Function{CreateSK}{$uid,pw$}\r
+\State $SK = ComputeHash(uid + pw)$\r
+\State \Return{$SK$}\r
+\EndFunction\r
+\end{algorithmic}\r
+\r
+\begin{algorithmic}[1]\r
+\Function{Hmac}{$Dat_s,SK_s$}\r
+\State \Return{$ComputeHmac(Dat_s,SK_s)$}\r
+\EndFunction\r
+\end{algorithmic}\r
+\r
+\begin{algorithmic}[1]\r
+\Function{ValidHmac}{$Dat_s,SK_s$}\r
+\State $hmac_{stored} \gets GetCurrHmac(Dat_s)$\r
+\State $hmac_{computed} \gets \Call{Hmac}{Dat_s,SK_s}$\r
+\If{$hmac_{stored} = hmac_{computed}$}\r
+       \State \Return{$true$}\r
+\Else\r
+       \State \Return{$false$}\r
+\EndIf\r
+\EndFunction\r
+\end{algorithmic}\r
 \r
 \r
-\ElsIf{$m = write$}\r
-       \State $newSlot \gets CreateSlot(d)$\r
-       \State $Data[1] \gets Encrypt(SK,newSlot)$\r
-       \State $Data \gets CallServer(m,max,s,Data)$\r
-       \If{$Data = \emptyset$}\r
-               \State $ReportError(\emptyset,write)$\r
-       \Else\Comment Check for valid return value from server\r
-               \If{$\neg ValidOldLastEntry(Data[1])$}\r
-                       \State $ReportError(Data[1],write)$\r
-               \Else\Comment{Check if we need slot sequence entry}\r
-                       \If{$Length(Data) = 2$}\r
-                               \State $expSlot \gets Decrypt(SK,Data[2])$\r
-                               \State $mid \gets MachineId(expSlot)$\r
-                               \State $seq \gets SeqN(expSlot)$\r
-                               \If{$seq = LastSeqN(mid,M)$}\Comment{Liveness check}\r
-                                       \State $slotSeqE \gets CreateSlotSeqE(mid,seq)$\r
-                                       \State $Data[1] \gets Encrypt(SK,slotSeqE)$\r
-                                       \State $Data \gets CallServer(m,max,s,Data)$\r
-                               \EndIf\r
+\begin{algorithmic}[1]\r
+\Function{ValidPrevHmac}{$Dat_s,hmac_{p_s}$}\r
+\If{$hmac_{p_s} = \emptyset$}\Comment{First slot - no previous HMAC}\r
+       \State \Return{$true$}\r
+\EndIf\r
+\State $hmac_{stored} \gets GetPrevHmac(Dat_s)$\r
+\If{$hmac_{stored} = hmac_{p_s}$}\r
+       \State \Return{$true$}\r
+\Else\r
+       \State \Return{$false$}\r
+\EndIf\r
+\EndFunction\r
+\end{algorithmic}\r
+\r
+\begin{algorithmic}[1]\r
+\Function{GetQueSta}{$Dat_s$}\r
+\State $DE_s \gets GetDatEnt(Dat_s)$\r
+%\State $qs_{ret} \gets max_s$\r
+%\ForAll{$de_i \in DE_s$}\r
+%      \If{$de_i \mid de_i \in D \land de_i = qs$}\r
+%      \State $qs_i \gets GetQS(de_i)$\r
+%        \If{$qs_i > qs_{ret}$}\r
+%              \State $qs_{ret} \gets qs_i$\r
+%        \EndIf\r
+%    \EndIf\r
+%\EndFor\r
+\State $de_{qs} \gets de_s \mid de_s \in DE_s, de_s \in D \land de_s = qs$\r
+\State $qs_{ret} \gets GetQS(de_{qs})$\r
+%\If{$qs_{ret} > max_s$}\r
+%\State $qs_{ret} \gets qs_i$\r
+%\EndIf\r
+\State \Return{$qs_{ret}$}\r
+\EndFunction\r
+\end{algorithmic}\r
+\r
+\begin{algorithmic}[1]\r
+\Function{GetSlotSeq}{$Dat_s$}\r
+\State $DE_s \gets GetDatEnt(Dat_s)$\r
+%\ForAll{$de_i \in DE_s$}\r
+       %\If{$de_i \mid de_i \in D \land de_i = ss$}\r
+       %\State $\tuple{id_{ret},s_{last_{ret}}} \gets GetSS(de_i)$\r
+    %\EndIf\r
+%\EndFor\r
+\State $de_{ss} \gets de_s \mid de_s \in DE_s, de_s \in D \land de_s = ss$\r
+\State $\tuple{id_{ret},s_{last_{ret}}} \gets GetSS(de_{ss})$\r
+\State \Return{$\tuple{id_{ret},s_{last_{ret}}}$}\r
+\EndFunction\r
+\end{algorithmic}\r
+\r
+\begin{algorithmic}[1]\r
+\Function{UpdateLastSeqN}{$id_s,s_s,MS_s$}\r
+\State $s_t \gets GetLastSeqN(MS_s,id_s)$\r
+\If{$s_t = \emptyset$}\r
+       \State $MS_s \gets MS_s \cup \{\tuple{id_s,s_s}\}$\Comment{First occurrence}\r
+\Else\r
+       \If{$s_s > s_t$}\Comment{Update entry with a later s}\r
+       \State $MS_s \gets (MS_s - \{\tuple{id_s,s_t}\}) \cup \r
+               \{\tuple{id_s,s_s}\}$\r
+    \EndIf\r
+\EndIf\r
+\State \Return{$MS_s$}\r
+\EndFunction\r
+\end{algorithmic}\r
+\r
+\begin{algorithmic}[1]\r
+\Function{CheckLastSeqN}{$MS_s,MS_t$}\Comment{Check $MS_t$ based on $MS_s$}\r
+\ForAll{$\tuple{id_t,s_{t_{last}}} \in MS_t$}\r
+       \State $s_{s_{last}} \gets GetLastSeqN(MS_s,id_t)$\r
+       \If{$s_{s_{last}} \neq \emptyset$}\r
+               \If{$id_t = id_{self}$}\r
+               \If{$s_{s_{last}} \neq s_{t_{last}}$}\r
+                               \State $error \gets$ 'Invalid last $s$ for this machine'\r
+                               \State \Return{error}\r
+                       \EndIf\r
+               \Else\r
+                       \If{$s_{s_{last}} \geq s_{t_{last}}$}\r
+                               \State $MS_s \gets (MS_s - \{\tuple{id_t,s_{t_{last}}}\}) \cup \r
+                               \{\tuple{id_t,s_{s_{last}}}\}$\r
                        \Else\r
                        \Else\r
-                               \State $ReportError(Data,write)$\r
+                               \State $error \gets$ 'Invalid last $s$ for machine $id_t$'\r
+                               \State \Return{error}\r
                        \EndIf\r
                \EndIf\r
        \EndIf\r
                        \EndIf\r
                \EndIf\r
        \EndIf\r
+\EndFor\r
+\State \Return{$\emptyset$}\r
+\EndFunction\r
+\end{algorithmic}\r
+\r
+\begin{algorithmic}[1]\r
+\Function{UpdateDT}{$DT_s,Dat_s$}\r
+\State $DE_s \gets GetDatEnt(Dat_s)$\r
+\ForAll{$de_i \in DE_s$}\r
+       \If{$de_i \mid de_i \in D \land de_i = kv$}\r
+               \State $\tuple{k_s,v_s} \gets GetKV(de_i)$\r
+               \State $k_s \gets GetKey(\tuple{k_s,v_s})$\r
+               \State $\tuple{k_s,v_t} \gets GetKeyVal(DT_s,k_s)$\r
+               \If{$\tuple{k_s,v_t} = \emptyset$}\r
+                       \State $DT_s \gets DT_s \cup \{\tuple{k_s,v_s}\}$\r
+               \Else\r
+               \State $DT_s \gets (DT_s - \{\tuple{k_s,v_t}\}) \cup \r
+                       \{\tuple{k_s,v_s}\}$\r
+               \EndIf\r
+    \EndIf\r
+\EndFor\r
+\State \Return{$DT_s$}\r
+\EndFunction\r
+\end{algorithmic}\r
 \r
 \r
-\ElsIf{$m = resize$}\r
-       \State $Data \gets CallServer(m,max,s,Data)$\r
-       \If{$Data = \emptyset$}\r
-               \State $ReportError(\emptyset,resize)$\r
+\begin{algorithmic}[1]\r
+\Function{GetKVPairs}{$s$}\r
+\State $SL_c \gets \Call{GetSlot}{s}$\r
+\State $MS_c \gets \emptyset$\r
+\ForAll{$\tuple{s_i,sv_i} \in SL_c$}\r
+       \State $s_i \gets SeqN(\tuple{s_i,sv_i})$\r
+       \State $sv_i \gets SlotVal(\tuple{s,sv_i})$\r
+       \State $Dat_i \gets Decrypt(SK,sv_i)$\r
+       \State $s_s \gets GetSeqN(Dat_s)$\r
+    \If{$s_i \neq s_s$}\r
+               \State $error \gets$ 'Invalid sequence number'\r
+       \EndIf\r
+       \If{$\Call{ValidPrevHmac}{Dat_i,hmac_p} = false$}\r
+               \State $error \gets$ 'Invalid previous HMAC value'\r
        \EndIf\r
        \EndIf\r
+       \If{$\Call{ValidHmac}{Dat_i,SK} = false$}\r
+               \State $error \gets$ 'Invalid current HMAC value'\r
+       \EndIf\r
+       \State $hmac_p \gets \Call{Hmac}{Dat_i,SK}$\Comment{Update $hmac_p$ for next slot check}\r
+       %\State $max_c \gets \Call{GetQueSta}{Dat_i,max_c}$\Comment{Handle qs}\r
+       \State $qs_c \gets \Call{GetQueSta}{Dat_i}$\Comment{Handle qs}\r
+       \If{$qs_c > max_c$}\r
+               \State $max_c \gets qs_c$\r
+       \EndIf\r
+    %Check for last s in Dat\r
+       \State $id_i \gets GetMacId(Dat_i)$\Comment{Handle last s}\r
+       \State $MS_c \gets \Call{UpdateLastSeqN}{id_i,s_i,MS_c}$\r
+    %Check for last s in DE in Dat\r
+    \State $\tuple{id_j,s_{j_{last}}} \gets \Call{GetSlotSeq}{Dat_i}$\Comment{Handle ss}\r
+    \State $MS_c \gets \Call{UpdateLastSeqN}{id_j,s_{j_{last}},MS_c}$\r
+       \State $DT \gets \Call{UpdateDT}{DT,Dat_i}$\r
+\EndFor\r
+\If{$m + |SL_c| \leq max_c$}\Comment{Check actual size against $max_c$}\r
+       \State $m \gets m + |SL_c|$\r
+\Else\r
+       \State $error \gets$ 'Actual queue size exceeds $max_c$'\r
 \EndIf\r
 \EndIf\r
-\State \Return{$Result$}\r
+       \State $error \gets \Call{CheckLastSeqN}{MS_c,MS}$\r
+\State \Return{$DT$}\r
+\EndFunction\r
+\end{algorithmic}\r
+\r
+\begin{algorithmic}[1]\r
+\Function{GetValFromKey}{$k_g$}\r
+\State $\tuple{k_s,v_s} \gets \tuple{k,v} \mid \tuple{k,v} \in DT \land k = k_g$\r
+\State $v_s \gets GetVal(\tuple{k_s,v_s})$\r
+\State \Return{$v_s$}\r
 \EndFunction\r
 \end{algorithmic}\r
 \r
 \EndFunction\r
 \end{algorithmic}\r
 \r