Skip to main content
. 2018 Nov 8;18(11):3829. doi: 10.3390/s18113829
Algorithm 3. Substitution of Cluster Head
/*Substitution of the cluster head vIDi on a cluster node vx*/
TVIDi = TVIDi − 0.2;
if (TVIDi < TTv && NAIDi < Nc/2) {
 Broadcast an ALARM message for vIDi;
vx, and each cluster node that hears the ALARM message, executes Algorithm 2;
}
Reset the timer TRG;
Select the trusted non-participating cluster node, whose ID is closer to hv than the others (vt for example), to substitute vIDi;
Select the current participating node whose ID is closest to hv (vm for example) as the new CH;
if (vx is exactly vm) {
 if (vt does not provide ktP)
  Perform the proposed substitution scheme in Step 5;
 else {// vx has stored the kjP of the other participating nodes when they sent kjP to vIDi.
  Compute R and broadcast X(R);
  Receive and verify each new σj;
  if (some current participating nodes do not provide their new σj or provide incorrect σj)
   Perform the proposed substitution scheme in Step 5;
 }
}
else if (vx is exactly vt) {
 Pick kx in [1, q − 1] and send kxP to vm;
 Compute σx after receiving X(R) from vm;
 Send σx to vm;
}
else if (vx is a participating node that has not been substituted) {
 Recompute σx after receiving X(R) from vm;
 Send σx to vm;
}