# Research on Secure Community Opportunity Network Based on Trust Model
## 3 Trust Community Routing Algorithm
### Node Community Division  
Partitioning security communities according to node trust values enables nodes to prioritize selecting trusted nodes within these communities as next-hop relay nodes during information transmission, thereby enhancing the security of message delivery. Given the inability of nodes within opportunistic networks to ascertain the global network status and to mitigate the storage burden arising from excessive community information retention, this study advocates for nodes to solely maintain a local community table locally. Furthermore, dynamic trust thresholds are employed for community organization, calculated by averaging the trust values of all neighboring nodes. The calculation formula is articulated as follows:\[Threshold=\frac{1}{m}\sum_{j\in\{A.connections\}}Trust_{(A,j)} \tag{5}\]  
where \(m\) represents the number of links established by node \(A\), and \(Trust_{(A,j)}\) denotes the comprehensive trust value of node \(A\) towards the neighbor node i at the opposite end of the link.  
Additionally, as time progresses, nodes persist in adding other network nodes to their local communities. With the expansion of a node's local community table, the significance of community division decreases. When a node's local community encompasses most of the network nodes, community division becomes irrelevant. To tackle this issue, this paper adopts a decay function to update the trust values of nodes in the local table and eliminates nodes below the trust threshold to mitigate community redundancy. The decay function for node trust value is detailed as follows:  
\[Trust_{(A,B)}=Trust_{(A,B)old}\times(1-\frac{Time_{n}-Time_{l}}{Time_{n}})\gamma \tag{6}\]  
where \(Trust_{(A,B)old}\) denotes the most recent comprehensive trust value of node \(A\) concerning node \(B\), \(Time_{n}\) signifies the current system time, and \(Time_{l}\) denotes the time of the last trust value update. \(\gamma\) denotes the decay function.  
By employing dynamic trust thresholds and trust value attenuation, we can establish robust security communities, mitigating the formation of overly expansive communities within social opportunistic networks and guaranteeing the efficacy of community segmentation. The steps for dividing the security community are outlined as follows:  
1. The node maintains two sets locally: the acquaintance set and the local community. Upon encountering other nodes in the network, it initiates the calculation of the node's trust value and determines the corresponding trust threshold.
2. Nodes exceeding the trust threshold are incorporated into the node's acquaintance set and local community.
3. The node traverses its acquaintance set, computes the trust value for each neighboring node within this set using the transitive trust formula, and includes nodes surpassing the trust threshold into its local community. \[Trust_{(A,C)}=Trust_{(A,B)}\times Trust_{(B,C)}\] (7)
4. The trust value gradually diminishes over time. Prior to data transmission, the node updates the trust value of nodes within both the acquaintance set and the local community. Nodes falling below the threshold are subsequently removed from both sets.