Skip to content

Scratchpad

Nishant Aswani edited this page Jan 31, 2021 · 16 revisions

How to update the submodules?

  • git submodule --init (only required first time cloning the repo)
  • git pull --recurse-submodules
  • git submodule update --remote --recursive

git checkout b36cc818db89430b7564d1c56a668937f6dae6ec

Logo

Possibly useful links

More papers

Documentation related

Raft related

ESP chip/Arduino related

GitHub features related

PlatformIO installation (vscode)

Set Election Alarm Old (Nice Task Scheduler Example)

void _server::setElectionAlarm() {
  // Create a new election alarm task for the scheduler
  _task_election_ptr =
      new Task(TASK_ELECTION_INTERVAL * TASK_MILLISECOND, TASK_FOREVER, [&] {
        // Check if there are nodes in the network
        bool isAloneNode = (_mesh.getNodeList(false).size() == 0);

        // Timeout if in follower mode or alone in the network
        if(this->_state == 0 || isAloneNode) {
          // Start a new election if the coin is flipped true or the maximum
          // number of skips reached
          if((this->_mesh.getNodeTime() % 2) ||
             (_task_election_skipped_coin_flips >
              TASK_ELECTION_MAXIMUM_SKIPPED_COIN_FLIPS)) {
            // Reset the flips
            this->_task_election_skipped_coin_flips = 0;

            // If coin toss results in 1, start a new election
            // In this way, we randomize the election duration without worrying
            // about timer overflow
            startNewElection();

          } else {
            this->_task_election_skipped_coin_flips += 1;
          }
        }
      });

  // Add the alarm to scheduler and enable it
  this->_scheduler.addTask(*_task_election_ptr);
  _task_election_ptr->enable();

  this->_logger(DEBUG, "Set the election timer\n");
};