Adding checks to slots range when reading
[iotcloud.git] / doc / iotcloud.tex
index 876935ac6921628bfa2ec20c8482bdf3bb56aa88..b85fc026001afb8b9d70b2254acc0547a33e5d6c 100644 (file)
@@ -350,7 +350,6 @@ $MinCRSeqN(CR_s)= s$ \textit{such that} $\tuple{s, id} \in CR_s
 \r
 \begin{algorithmic}[1]\r
 \Function{AddCRLivEnt}{$CR_{s_{live}},cr_s$}\r
-%\State $cr_s \gets GetCR(de_s)$\r
 \State $cr_t \gets GetLiveCR(CR_{s_{live}},cr_s)$\r
 \If{$cr_t = \emptyset$}\r
        \State $CR_{s_{live}} \gets CR_{s_{live}} \cup \{cr_s\}$\Comment{First occurrence}\r
@@ -427,6 +426,28 @@ $MinCRSeqN(CR_s)= s$ \textit{such that} $\tuple{s, id} \in CR_s
 \EndProcedure\r
 \end{algorithmic}\r
 \r
+\begin{algorithmic}[1]\r
+\Procedure{CheckSlotsRange}{$|SL_s|,s_{s_{min}},s_{s_{max}}$}\r
+\State $sz_{SL} \gets s_{s_{max}} - s_{s_{min}} + 1$\r
+\If{$sz_{SL} \neq |SL_s|$}\r
+       \State \Call{Error}{'Sequence numbers range does not match slots set'}\r
+\EndIf\r
+\State $s_{min} \gets MinLastSeqN(MS)$\r
+\State $s_{max} \gets MaxLastSeqN(MS)$\r
+\If{$s_{s_{min}} \leq s_{min}$}\r
+       \State \Call{Error}{'Server sent old slot'}\r
+\EndIf\r
+\If{$s_{s_{max}} > s_{max}$}\r
+       \State \Call{Error}{'Server sent out-of-range slot'}\r
+\EndIf\r
+\State $s_{self} \gets MS_s[id_{self}]$\r
+\State $sz_{expected} \gets s_{max} - s_{self} + 1$\r
+\If{$sz_{SL} \neq sz_{expected}$}\r
+       \State \Call{Error}{'Actual number of slots does not match expected'}\r
+\EndIf\r
+\EndProcedure\r
+\end{algorithmic}\r
+\r
 \begin{algorithmic}[1]\r
 \Function{StoreLastSlot}{$MS_s,sl_l,s_s,sv_s,id_s$}\r
 \State $s_{min} \gets MinLastSeqN(MS_s)$\r
@@ -459,7 +480,6 @@ $MinCRSeqN(CR_s)= s$ \textit{such that} $\tuple{s, id} \in CR_s
 \begin{algorithmic}[1]\r
 \Procedure{ProcessSL}{$SL_g$}\r
 \State $MS_g \gets \emptyset$\r
-%\State $SM_{curr} \gets \emptyset$\r
 \State $\tuple{s_{g_{min}},sv_{g_{min}}} \gets MinSlot(SL_g)$\r
 \State $\tuple{s_{g_{max}},sv_{g_{max}}} \gets MaxSlot(SL_g)$\r
 \For{$s_g \gets s_{g_{min}}$ \textbf{to} $s_{g_{max}}$}\Comment{Process slots \r
@@ -467,7 +487,6 @@ $MinCRSeqN(CR_s)= s$ \textit{such that} $\tuple{s, id} \in CR_s
        \State $\tuple{s_g,sv_g} \gets Slot(SL_g,s_g)$\r
        \State $Dat_g \gets Decrypt(SK,sv_g)$\r
        \State $id_g \gets GetMacId(Dat_g)$\r
-       %\State $SM_{curr} \gets SM_{curr} \cup \{\tuple{s_g,id_g}\}$\r
        \State $SM \gets SM \cup \{\tuple{s_g,id_g}\}$\r
        \State $s_{g_{in}} \gets GetSeqN(Dat_g)$\r
     \If{$s_g \neq s_{g_{in}}$}\r
@@ -476,7 +495,7 @@ $MinCRSeqN(CR_s)= s$ \textit{such that} $\tuple{s, id} \in CR_s
        \State $DE_g \gets GetDatEnt(Dat_g)$\r
        \State $hmac_{p_{stored}} \gets GetPrevHmac(Dat_g)$\r
        \If{$\neg \Call{ValidPrevHmac}{s_g,DE_g,hmac_{p_g},hmac_{p_{stored}}}$}\r
-               \State \Call{ReportError}{'Invalid previous HMAC value'}\r
+               \State \Call{Error}{'Invalid previous HMAC value'}\r
        \EndIf\r
        \State $hmac_{c_g} \gets GetCurrHmac(Dat_g)$\r
        \If{$\neg \Call{ValidHmac}{DE_g,SK,hmac_{c_g}}$}\r
@@ -504,19 +523,18 @@ $MinCRSeqN(CR_s)= s$ \textit{such that} $\tuple{s, id} \in CR_s
                \ForAll{$de_{g_{cr}} \in DE_{g_{cr}}$}\r
                        \State $cr_g \gets GetCR(de_{g_{cr}})$\r
                        \State $\Call{CheckCollision}{MS,SM,cr_g}$\r
-                       %\State $CR_{live} \gets \Call{AddCRLivEnt}{CR_{live},de_{g_{cr}}}$\r
                        \State $CR_{live} \gets \Call{AddCRLivEnt}{CR_{live},cr_g}$\r
                \EndFor\r
        \EndIf\r
        \State $sl_{last} \gets \Call{StoreLastSlot}{MS,sl_{last},s_g,sv_g,id_g}$\r
        \State $DT \gets \Call{UpdateDT}{DT,DE_g,LV,s_g}$\r
 \EndFor\r
-%\State $SM \gets SM_{curr}$\r
 \If{$m + |SL_g| \leq max_g$}\Comment{Check actual size against $max_g$}\r
        \State $m \gets m + |SL_g|$\r
 \Else\r
        \State \Call{Error}{'Actual $SL$ size on server exceeds $max_g$'}\r
 \EndIf\r
+\State $\Call{CheckSlotsRange}{SL_g,s_{g_{min}},s_{g_{max}}}$\r
 \State $\Call{CheckLastSeqN}{MS_g,MS}$\r
 \State $\Call{UpdateSSLivEnt}{SS_{live},MS}$\r
 \State $\Call{UpdateCRLivEnt}{CR_{live},MS}$\r
@@ -543,10 +561,6 @@ $MinCRSeqN(CR_s)= s$ \textit{such that} $\tuple{s, id} \in CR_s
 \subsubsection{Writing Slots}\r
 \textbf{States} \\\r
 \textit{$cp$ = data entry $DE$ maximum size/capacity} \\\r
-%\textit{$cr_p$ = saved cr entry $\tuple{s,id}$ on client if there is a collision\r
-%(sent in the following slot)} \\\r
-%\textit{$cr_{p_{last}}$ = saved cr entry $\tuple{s,id}$ on client if there is a \r
-%collision in reinserting the last slot (sent in the following slot)} \\\r
 \textit{$ck_p$ = counter of $kv \in KV$ for putting pairs (initially 0)} \\\r
 \textit{$ck_g$ = counter of $kv \in KV$ for getting pairs (initially 0)} \\\r
 \textit{$cs_p$ = counter of $ss \in SS$ for putting pairs (initially 0)} \\\r
@@ -639,6 +653,9 @@ $\tuple{ck,\tuple{k, v}} \in KV_s \wedge
 \r
 \begin{algorithmic}[1]\r
 \Function{HandleCollision}{$SL_s,s_s$}\r
+\If{$SL_s = \emptyset$}\r
+       \State \Call{Error}{'No slots received from server'}\r
+\EndIf\r
 \State $\tuple{s_{col},sv_{col}} \gets GetColSeqN(SL_s,s_s)$\r
 \State $Dat_{col} \gets Decrypt(SK,sv_{col})$\r
 \State $id_{col} \gets GetMacId(Dat_{col})$\r