## 4 The Trust Evaluation Process
### Trust Calculation for One-Hop Neighbor Nodes
#### 4.2.1 Direct Trust Calculation for One-Hop Neighbor Nodes
Other, if two sensor nodes are neighbors, the packet loss caused by node movement is 0. That is:  
\[P_{loss2}=\left\{ \begin{array}{l}0,d_{ab}{<}\ \mathrm{r}\\ \infty,d_{ab}\geq\mathrm{r}\end{array} \right. \tag{4}\]  
In each time slot, all anchor node broadcast information for their neighbor nodes and record the number of broadcasted packets \(n\). The anchor nodes which receive the information also record the number of successfully received packets \(n_{s-anchor}\). The number of all the loss packets is \(n-n_{s-anchor}\). Because a part of packet loss is caused by unreliable acoustic channel \(P_{loss1}\), the number of loss packets caused by malicious nodes should be \(n_{f}=n-n_{s-anchor}-P_{loss1}\). Thus, the number of successfully received packets \(n_{s}\) should be corrected as \(n_{s}=n-n_{f}=n_{s-anchor}+P_{loss1}\). In the next time slot, if two neighbor nodes are still be neighboring, we obtain \(P_{loss2}=0\). Otherwise, if two neighbor nodes move out of the communication range, we obtain \(P_{loss2}=\infty\). In this case, the packet loss caused by malicious nodes \(n_{f}\) is not updated and keeps the calculated value in the last time slot. Therefore, even if the receiver node cannot receive any packets, the sender node will not be erroneously assigned with a low trust value. According to packet loss, we use the main idea of [34] based on Bayesian Formulation to evaluate trust relationship. In [34], the reputation of a sensor nodes is first calculated based on the beta distribution, which is indexed by two parameters \((\alpha,\beta)\) and can be expressed using the gamma function \(\Gamma(\cdot)\) as \(P(x)=\frac{\Gamma(\alpha+\beta)}{\Gamma(\alpha)\Gamma(\beta)}x^{\alpha-1}(1-x )^{\beta-1},\forall 0\leq x\leq 1,\alpha\geq 0,\beta\geq 0\). The reputation of node \(j\) evaluated by node \(i\) is given as \(R_{ij}=Beta(\alpha_{j}+1,\beta_{j}+1)\), where \(\alpha_{j}\) and \(\beta_{j}\) represents the cooperative and non-cooperative interactions between node \(i\) and \(j\), respectively. The trust of a sensor node is the statistical expectation of the reputation function and is calculated as:  
\[T_{ij}=E(R_{ij})=E(Beta(\alpha_{j}+1,\beta_{j}+1))=\frac{\alpha_{j}+1}{\alpha_ {j}+\beta_{j}+2} \tag{5}\]  
Therefore, based on \(n\) and \(n_{s}\), and according to the reference [34], in which trust is denoted by \((\alpha_{j}+1)/(\alpha_{j}+\beta_{j}+2)\), the trust of an anchor node \(j\) can be calculated by node \(i\) as  
\[T_{ij}=\frac{n_{s}+1}{n_{s}+n_{f}+2}=\frac{n_{s}+1}{n+2} \tag{6}\]In UWSNs, packet loss caused by unreliable acoustic channel and inevitable node movement is heavy. Getting statistics like packet loss as trust evidence is not reliable enough in underwater environment. Therefore, in this paper, we further propose using packet error to evaluate trust for sensor nodes based on the main idea of [30]. In [30], the main idea is to make use of the known locations of anchor nodes and the constraints that the locations must satisfy with the measurements (e.g., distance, angle) derived from the localization beacon signals. The anchor node which performs malicious node detection is named as detecting node. The detecting node first sends a localization request message to the target anchor node. The target node will send back a localization beacon packet which contains its own location information upon receiving the request message. Once the detecting node receives the beacon packet, it first estimates the distance between them. In addition, because the detecting node both knows its own location and receives the target node's location, it can also calculate the distance between them. Finally, the detecting node compares the estimated distance and the calculated one. If the difference between them is larger than the maximum distance error, the detecting node can infer that the position information in the received beacon packet must be wrong. Similarly, in this paper, each anchor node broadcast their location information to neighbor nodes. They pretend to be unknown nodes to localize each other.