This repository has been archived on 2022-02-10. You can view files and clone it, but cannot push or open issues or pull requests.
fortuna/seed_file_management.h
surtur 795b9ffe54
All checks were successful
continuous-integration/drone/push Build is passing
add proper SeedFileManager implementation
a couple of fixes/necessary additions were made along the way, namely:
* add a default constructor for DoTask
* rework of the mutex/lock_guard/unique_lock logic in generator/fortuna
* add .fortuna.seed to the list of the ignored (.gitignore)
* add helper function to util for convertin bytes to blocks (16b==block)
* add a wrapper for around the SeedFileManager instance and a way to see
  if it's dead or alive (so that it can be restarted if needed)
* the timeout for saving of the seed file has been decreased to a more
  reasonable value than 10 minutes (I wouldn't want to lose potentially
  up to 10 minutes worth of entropy)
2022-01-09 11:58:38 +01:00

48 lines
980 B
C++

#ifndef FORTUNA_SEED_FILE_MANAGER_H
#define FORTUNA_SEED_FILE_MANAGER_H
#include "accumulator.h"
#include "do_task.h"
#include <chrono>
#include <string>
namespace fortuna {
class SeedFileManager {
public:
struct conf
{
// std::chrono::minutes write_interval{10};
// 10 minutes (as the standard recommends) is a lot, go with 120s
std::chrono::seconds write_interval{120};
std::string seed_f_path = "./.fortuna.seed";
std::size_t seed_f_length = 64;
conf(){};
};
auto is_job_running() -> bool;
auto do_stuff() -> void;
SeedFileManager(const fortuna::accumulator::Accumulator& accumulator) noexcept;
~SeedFileManager() noexcept;
protected:
auto set_job_running(bool) -> void;
private:
const conf config;
bool running = false;
DoTask do_task;
fortuna::accumulator::Accumulator accumulator;
auto write_seed_file() -> void;
auto update_seed_file() -> void;
}; // class SeedFileManager
} // namespace fortuna
#endif // FORTUNA_SEED_FILE_MANAGER_H