## 5 The Proposed Routing Method
### Distributed and Lightweight Trust Mechanism (W-Trust)
#### 5.1.1 Direct Trust  
The direct trust of the node \(i\) relative to the node \(j\) is displayed as \(T_{ij}^{direct}\). It is the immediate trust produced by the node \(i\) for the node \(j\). \(T_{ij}^{direct}\) is obtained from the direct interaction between the two nodes over a time period such as \((t-1,t]\). To calculate \(T_{ij}^{direct}\) at the interval \((t-1,t]\) using Equation (7), the node \(i\) calculates the packet sending rate and the packet receiving rate from/ to the node \(j\) during this time interval.  
\[T_{ij}^{direct}(t)=\lambda PSR_{j}(t)+(1-\lambda)PRR_{j}(t) \tag{7}\]  
Figure 3: An example of a black hole attack.  
where \(\lambda\in[0,1]\) is an adjustable weight coefficient. \(PSR_{j}(t)\) and \(PRR_{j}(t)\) are the packet sending rate and the packet receiving rate of the node \(j\) at the time interval \((t-1,t]\), respectively. They are obtained from Equations (8) and (9), respectively.  
\[PSR_{j}(t)=\frac{M_{j}^{sent}(t)}{M_{j}^{all-sent}(t)} \tag{8}\]  
so that \(M_{j}^{sent}(t)\) demonstrates all packets sent from the node \(j\) to the node \(i\) at the interval \((t-1,t]\). Moreover, \(M_{j}^{all-sent}(t)\) represents the total number of packets that must be sent to the node \(i\) at \((t-1,t]\).  
\[PRR_{j}(t)=\frac{M_{j}^{received}(t)}{M_{j}^{all-received}(t)} \tag{9}\]  
where \(M_{j}^{received}(t)\) indicates all packets received by the node \(j\) at the interval \((t-1,t]\). Furthermore, \(M_{j}^{all-received}(t)\) is the total number of packets that must be received from the node \(i\) at \((t-1,t]\).  
Now, \(T_{ij}^{direct}\) is standardized based on Equation (10).  
\[T_{ij}^{standard}(t)=\frac{T_{ij}^{direct}(t)-\mu_{ij}}{\sigma_{ij}} \tag{10}\]  
where \(\mu_{ij}\) and \(\sigma_{ij}\) are the average and standard deviation of \(T_{ij}^{direct}(t)\), respectively. They are calculated according to Equations (10) and (11).  
\[\mu_{ij}=\frac{1}{M}\sum_{k=1}^{M}T_{ij}^{direct}(k) \tag{11}\]  
\[\sigma_{ij}=\sqrt{\frac{1}{M}\sum_{k=1}^{M}\left(T_{ij}^{direct}(k)-\mu_{ij} \right)^{2}} \tag{12}\]  
In Equations (11) and (12), \(M>0\) is a fixed number that indicates the number of direct trusts measured between the node \(i\) and the node \(j\) at a certain time.  
According to Equation (10), if the direct trust calculated for the node \(j\) by the node \(i\) is less than \(\mu_{ij}\) (i.e., \(T_{ij}^{standard}(t)<0\)), the node \(i\) recognizes this node as a malicious node and reduces the direct trust associated with this node based on a penalty factor to isolate this node and avoid its hostile activities on the network. In addition, if the direct trust calculated for the node \(j\) by the node \(i\) is higher than \(\mu_{ij}\) (i.e., \(T_{ij}^{standard}(t)\geq 0\)), the node \(i\) recognizes this node as an honest node and increases its direct trust with regard to a reward factor to improve its participation in the routing process. This weight coefficient is calculated through Equation (13).  
\[\Psi=1-e^{-T_{ij}^{standard}} \tag{13}\]  
Next, the node \(i\) uses the technique of the window mean with exponentially weighted moving average (WMEWMA) to update \(T_{ij}^{direct}\). This technique considers a window with the length \(w\). This window is applied to save the last \(w\) values of \(T_{ij}^{direct}\). This helps the node \(i\) to consider both the last and historical values of \(T_{ij}^{direct}\) and have a better estimation of \(T_{ij}^{direct}\). Accordingly, \(T_{ij}^{direct}\) is updated by the node \(i\) according to Equation (14).  
\[T_{ij}^{direct}(l)=(1-\beta)\frac{\sum\limits_{k=l-w}^{l-1}T_{ij}^{direct}(k)}{w }+\beta T_{ij}^{direct}(t) \tag{14}\]  
where \(\beta\) is an adjustable parameter in \([0,1]\) and \(w\) is the window length.  
Finally, the weighted direct trust of the node \(i\) relative to the node \(j\) is obtained through Equation (15).  
\[T_{ij}^{Weighted-direct}=\Psi T_{ij}^{direct}(l) \tag{15}\]