# Research on Secure Community Opportunity Network Based on Trust Model
## 3 Trust Community Routing Algorithm
### Node Trust Degree Measurement  
In an opportunistic network, message transmission relies on the store-carry-forward mechanism, necessitating active participation and collaboration among network nodes. However, ensuring the absence of malicious nodes among these entities is imperative to avert the risks of network attacks. Thus, the assessment of node trustworthiness and the selection of trusted nodes form the cornerstone of secure message transmission. To this end, this paper advocates leveraging the historical forwarding behavior of nodes to quantify node trust, thereby identifying reliable relay nodes conducive to safe transmission. The calculation of node trust entails a comprehensive consideration of both direct and indirect trust. Direct trust is evaluated based on the node's historical interaction records, while indirect trust pertains to those of other nodes within the local community. **Definition 1**. : _Node trust._  
This parameter indicates the potential for neighboring nodes to assist in the successful forwarding of messages by the focal node. For any pair of nodes, \(A\) and \(B\), within the opportunistic network, the trust value between nodes is computed as depicted in Formula (1):  
\[Trust_{(A,B)}=\alpha Trust_{(A,B)}+(1-\alpha)iTrust_{(A,B)} \tag{1}\]  
among them, \(Trust_{(A,B)}\) represents the comprehensive trust degree of node \(A\) towards node \(B\), \(dTrust_{(A,B)}\) denotes the direct trust, \(iTrust_{(A,B)}\) signifies the indirect trust, and \(\alpha\) serves as the weight factor. **Definition 2**. : _Direct Trust._  
This paper employs the Bayesian trust model to forecast the subsequent forwarding behavior of nodes. The Bayesian trust model conceptualizes trust as a random variable following the \(\beta\) distribution, leveraging the node's historical interaction records as the prior distribution, and computing the posterior distribution to predict the node's future forwarding behavior. The parameter \(\alpha\) in the \(\beta\) distribution is determined by the number of successful historical node interactions, while the parameter \(\beta\) is influenced by the number of failed interactions. The expectation of this \(\beta\) distribution is then utilized todepict the Bayesian trust of the node. Bayesian trust offers an intuitive representation of a node's message forwarding success rate and future forwarding tendencies. A higher value indicates a node's greater capability in forwarding messages. The calculation formula is articulated as follows:  
\[Trust_{by}=\frac{\alpha}{\alpha+\beta}=\frac{message_{suc}}{message_{fal}} \tag{2}\]  
where \(message_{suc}\) represents the number of successful node interactions, and \(message_{fal}\) represents the number of failed node interactions. By utilizing Formula (2), this study thoroughly examines the node's three historical interaction records to compute the node's direct trust degree. The calculation formula for direct trust is expressed as follows:  
\[dTrust_{(A,B)}=w_{1}\times AllTrust_{(A,B)}+w_{2}\times RecTrust_{(A,B)}+w_{3} \times TraTrust_{(A,B)} \tag{3}\]  
where \(AllTrust_{(A,B)}\) is calculated by incorporating the historical interaction records between node \(B\) and all other nodes in the network into Formula (2). This value can effectively depict the overall forwarding behavior of node \(B\) within the social opportunistic network. \(RecTrust_{(A,B)}\) is computed by integrating the historical interaction record of node \(B\) receiving messages sent by node \(A\) into Formula (2), thus reflecting node \(B\)'s proficiency in receiving messages from node \(A\). Similarly, \(TraTrust_{(A,B)}\) is derived from the historical interaction records of node \(B\) forwarding messages received from node \(A\), illustrating node \(B\)'s capability in successfully forwarding messages from node A. The coefficients \(w_{1}\), \(w_{2}\), and \(w_{3}\) represent different weight coefficients, whose values can be adjusted according to various network environments.