## 4 SRF-IoT Design
### Calculating Trust  
The calculation of trust value of a node until time \(T\) occurs in this process. The formula to calculate the direct trust that device \(D_{a}\) holds for device \(D_{b}\) until time period \(T\) is given by \(DT(D_{a}.D_{b})_{T}\). The number of packets successfully transmitted between devices \(D_{a}\) and \(D_{b}\) until time period \(T\) is given by \(PT_{ab}(T)\). The total number of packets forwarded by device \(D_{b}\) on behalf of device \(D_{a}\) until time period \(T\) is given by \(PF_{ba}(T)\). Intuitively, the higher the number of packets \(D_{b}\) drops (i.e., \(PT_{ab}(T)-PF_{ba}(T)\)) the lower the trust \(D_{a}\) has in \(D_{b}\) should be. In order to be able to compare between devices, we normalised this by dividing it to the total number of packets that \(D_{b}\) forwards. Therefore, now the higher the proportion of the number of packets \(D_{b}\) drops to the total number of packets forwarded by \(D_{b}\) (i.e., \([PT_{ab}(T)-PF_{ba}(T)]/PF_{ba}(T)\)), the lower the trust \(D_{a}\) has in \(D_{b}\) should be. The outcome of this formula, i.e., \([PT_{ab}(T)-PF_{ba}(T)]/PF_{ba}(T)\), ranges between 0 (if all packets are forwarded) and infinity (if \(D_{a}\) sends many packets, but none are forwarded). Normalisation was the next step so that we get a value between 1 and 0, with 1 corresponding to the former case (maximum trust) and 0 corresponding to the latter case (minimum trust). In order to achieve it, the following function was used:  
\[f(x)=\frac{1}{(1+x)} \tag{1}\]  
The above function takes \(x=0\) to \(f(x)=1\) and \(x=\infty\) to \(f(x)=0\). The value achieved from _[PT\({}_{ab}(T)-{}P_{\text{F}_{\text{Jb}}}(T)\)]/PF\({}_{\text{Jb}}(T)\)_ needs to be scaled to reflect varying degrees of trust in different situations. For example, if a device is initially forwarding all packets, it has high trust value. In a later moment, if it behaves maliciously and drops the packets, its trust value should be reduced. For this purpose, a weight factor \(w\) is added before applying the \(f\) function. A weight factor is added to the equation to punish or reward nodes that may change packet forwarding behaviour accordingly. Based on the previous explanations, direct trust calculations are computed as follows:  
\[DT(D_{a},D_{b})_{T}=\frac{PF_{ba}(T)}{PF_{ba}(T)+w\cdot[PT_{ab}(T)-PF_{ba}(T)]} \tag{2}\]  
which is the result of multiplying the numerator and denominator of initial formula \(f\) by \(PF_{ba}(T)\). Weight factor \(w\) can take the following values:  
\[w= \begin{cases}0.6,&\text{if }node\_verified_{T}\equiv 0\text{ and }PFI(t)\equiv 0\\ 0.8,&\text{if }node\_verified_{T}\equiv 0\text{ and }PFI(t)>0\\ 0.85,&\text{if }node\_verified_{T}\equiv 1\text{ and }PFI(t)\equiv 0\\ 0.5,&\text{if }node\_verified_{T}\equiv 1\text{ and }PFI(t)>0\text{ and}\\ &\hskip 142.26378 pt{}PF_{\text{Jb}}(T)>minimum\_fw\\ 0.0,&\text{otherwise}\end{cases} \]  
where \(PFI(t)\) represents the number of packets forwarded, sniffed by SRF-IDS, for the specified node at time \(t\). To calculate the total number of packets forwarded until time \(T\) we use:  
\[PF_{\text{ba}}(T)=\sum_{n=1}^{T}PFI(n) \tag{3}\]  
The parameter \(node\_verified_{T}\) means that a node is verified by SRF-IDS that is behaving normally until moment \(T\). We use this indicator to increase the weight factor so that a node is trusted by benign nodes, whereas an unverified node has a smaller weight. The fourth case has a condition that \(w\) is smaller if the node is verified, forwards packets, and the total number of packets forwarded are greater than the minimum number of forwarded packets (\(minimum\_fw\)). The value of \(minimum\_fw\) is 5, and it is used as an indicator to check if a node keeps forwarding packets after the initial verification. If a node is verified but the total number of forwarded packets are less than this parameter, weight becomes zero and trust is 100%. This ensures that a verified benign node will be fully trusted until it reaches the threshold \(minimum\_fw\). Weight is then applied in the formula.