# Research on Secure Community Opportunity Network Based on Trust Model
## 3 Trust Community Routing Algorithm
### Routing and forwarding Strategy
\(Node_{resb}\) denotes the remaining cache of the node, whereas \(Node_{buf}\) represents the maximum cache capacity of the node. \(Node_{resn}\) represents the remaining energy of the node, and \(Node_{ene}\) indicates the maximum energy of the node. \(Message_{des}\) designates the message's destination node, and \(Relay_{local}\) characterizes the local community of the relay node. The coefficients \(\alpha\), \(\beta\), and \(\gamma\) are weight factors adjustable to meet the requirements of the network environment. To further mitigate the risk of buffer overflow and potential message loss during message forwarding, this paper introduces additional adjustments to the message queue order based on priority. Messages are then forwarded according to their assigned priority levels. The calculation formula for determining message priority is provided below:  
\[Priority_{mes}=\alpha\frac{Time_{no}-Time_{cre}}{Message_{TTL}}+\beta\frac{Message_{pri}}{ Message_{size}} \tag{11}\]  
where \(Priority_{mes}\) represents the priority of message forwarding, \(Time_{no}\) denotes the current simulation time, \(Time_{cre}\) indicates the message creation time, and \(Message_{TTL}\) represents the message's life cycle. A larger value of \(\frac{Time_{no}-Time_{cre}}{Message_{TTL}}\) indicates a longer forwarding time in the network, approaching the message's expiration time, thereby necessitating prioritized delivery. \(Message_{pri}\) denotes the priority label of the message itself, while \(Message_{size}\) indicates the message size. A higher value of \(\frac{Message_{pri}}{Message_{size}}\) corresponds to a higher priority for messages with a unit size. The weight coefficients \(\alpha\) and \(\beta\) are utilized in the algorithm. The message-forwarding process of the routing algorithm proceeds as follows:  
1. If the neighbor node's local community does not include the message's destination node, and this node's local community contains the message's destination node, the message will not be forwarded. 2. If the neighbor node's local community contains the message's destination node, while this node's local community does not, all messages will be transmitted to the neighbor node. 3. If neither the neighbor node's local community nor this node's local community includes the message's destination node, compare the Scorerel of the neighbor node and this node using Formula (9). If the neighbor node's Scorerel is higher, half of the messages will be transmitted; otherwise, one will be subtracted. 4. If both the neighbor node's local community and this node's local community contain the message's destination node, compare the Scorerel of the neighbor node and this node using Formula (10). If the neighbor node's Scorerel is higher, half of the messages will be transmitted; otherwise, one will be subtracted. 5. During message transmission, prioritize messages in the message queue based on their \(\mathrm{Priority}_{\mathrm{mes}}\), with higher priority messages being forwarded first. Figure 1 delineates the operational workflow of the Secure Community Trust Model (SCTM) routing algorithm. Initially, the algorithm deduces the trust values of neighboring nodes by examining historical interaction records and interactions with identical nodes within the local community. Subsequently, it computes the trust threshold for the security community and purges nodes from the local community that fall below this trust threshold following an update of the community nodes' trust values. After the inclusion of nodes surpassing the trust threshold into the local community, the Algorithm 2 proceeds to select relay nodes and allocate message copies, taking into consideration the node's community  
affiliation, centrality, remaining cache, and residual energy. The process culminates with the initiation of message transmission, preceded by the organization of the message queue.