## 5 The Proposed Routing Method
### Trust-Based Clustering Process (T-Clustering)  
In this section, the trust-based clustering process (T-Clustering) is presented in the proposed method. In this process, the cluster head nodes (CHs) are only selected from the honest nodes whose trust level is greater than \(T_{threshold}\). In general, T-Clustering includes several steps: selecting CHs, joining the cluster, leaving the cluster, and supporting the cluster. * **Selecting a CH node:** In CTSRD, each IoT node periodically exchanges a beacon message with its neighbors. This message contains information about the location, remaining energy, and trust value of the corresponding node. According to this message, each IoT node holds a neighborhood table for recording the information obtained from its single-hop neighboring nodes. According to the information in this table, each node such as \(n_{i}\) uses Equation (18) to calculate its chance (\(S_{i}\)) to be selected as CH. This chance depends on four parameters, including the centrality of the node, the remaining energy, the neighbor degree, and the distance to the base station. \[S_{i}=\frac{\left(\frac{E_{i}}{E_{\max}}\right)\times\left(\frac{Deq_{i}}{N}\right) }{\left(\frac{1}{N_{i}}\sum\limits_{n_{j}\in Niel}^{N}d\left(n_{i},n_{j} \right)\right)\times\left(\frac{d\left(n_{i}BS\right)}{d_{\max}}\right)}\] (18) where \(E_{i}\) and \(E_{\max}\) are the remaining energy and the primary energy of \(n_{i}\), respectively. Furthermore, \(Deg_{i}\) indicates the neighbor degree of \(n_{i}\), which is obtained from the neighborhood table. \(N\) is the total number of all IoT nodes. \(d\left(n_{i},n_{j}\right)\) and \(d\left(n_{i},BS\right)\) represent the distance between \(n_{i}\) and the neighboring node (such as \(n_{j}\)), and the distance between \(n_{i}\) and BS, respectively. They are calculated based on Equations (19) and (20), respectively. \(N_{i}\) is the number of neighbors of \(n_{i}\) and is obtained from the neighborhood table. \(Nei\) reflects the set of neighbors of \(n_{i}\). Moreover, \(d_{\max}\) indicates the maximum distance between IoT nodes and BS. It is estimated according to the dimensions of the network. For example, if the dimensions are \(p\times q\), then \(d_{\max}=\sqrt{p^{2}+q^{2}}\). \[d\left(n_{i},n_{j}\right)=\sqrt{\left(x_{i}-x_{j}\right)^{2}+\left(y_{i}-y_{ j}\right)^{2}}\] (19) \[d\left(n_{i},BS\right)=\sqrt{\left(x_{i}-x_{BS}\right)^{2}+\left(y_{i}-y_{ BS}\right)^{2}}\] (20) so that \(\left(x_{i},y_{i}\right)\), \(\left(x_{j},y_{j}\right)\), and \(\left(x_{BS},y_{BS}\right)\) are the spatial coordinates of \(n_{i}\), \(n_{j}\), and BS, respectively. Then, each IoT node such as \(n_{i}\) shares its chance (\(S_{i}\)) with other IoT nodes through the beacon messages. Finally, a node with the highest chance introduces itself as a node. * **Joining the cluster:** After IoT nodes have received beacon messages from each other, they extract the chances of neighboring nodes from these messages. Then, each IoT node such as \(n_{i}\) compares its chance (\(S_{i}\)) to the chances of other neighboring nodes. If \(n_{i}\) has the highest chance compared to neighbors, it broadcasts a CH-candidate message to its neighbors to inform them of its status. Otherwise, if the chance of \(n_{i}\) is less than other neighboring nodes, it waits for receiving CH-candidate messages from other neighboring nodes. Suppose that \(n_{i}\) receives multiple CH-candidate messages from different neighboring nodes. In this case, \(n_{i}\) is connected to the safest CH, which is a node with the highest trust level. Then, the CH transfers an ACK message to the cluster member node. * **Leaving the cluster:** In IoT, the energy of cluster member nodes may end and these nodes die due to resource depletion. Therefore, it is necessary for CHs to be aware of the status of their members at any moment. To achieve this, CMs periodically send a beacon message to their CH to announce their membership to the cluster.