fortuna: improve mtx handling, introduce accu_mtx
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
b682b0251d
commit
c0933d355d
|
@ -145,7 +145,9 @@ auto Fortuna::seed_file_manager_service() -> void {
|
||||||
p_ul.unlock();
|
p_ul.unlock();
|
||||||
auto right_now{fortuna::Util::current_time()};
|
auto right_now{fortuna::Util::current_time()};
|
||||||
std::unique_lock<std::mutex> mtx_l(mtx);
|
std::unique_lock<std::mutex> mtx_l(mtx);
|
||||||
|
std::unique_lock<std::mutex> a_ul(accu_mtx);
|
||||||
SeedFileManager sfm(this->accumulator);
|
SeedFileManager sfm(this->accumulator);
|
||||||
|
a_ul.unlock();
|
||||||
mtx_l.unlock();
|
mtx_l.unlock();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
11
fortuna.h
11
fortuna.h
|
@ -19,6 +19,7 @@ public:
|
||||||
static constexpr const unsigned int reseed_interval{10000};
|
static constexpr const unsigned int reseed_interval{10000};
|
||||||
static constexpr const char num_of_pools{32};
|
static constexpr const char num_of_pools{32};
|
||||||
std::mutex mtx;
|
std::mutex mtx;
|
||||||
|
std::mutex accu_mtx;
|
||||||
std::mutex print_mtx;
|
std::mutex print_mtx;
|
||||||
std::thread th_gen;
|
std::thread th_gen;
|
||||||
std::thread th_accu;
|
std::thread th_accu;
|
||||||
|
@ -48,22 +49,22 @@ public:
|
||||||
// p. 153
|
// p. 153
|
||||||
set_reseed_ctr_to_null();
|
set_reseed_ctr_to_null();
|
||||||
std::unique_lock<std::mutex> p_ul(print_mtx);
|
std::unique_lock<std::mutex> p_ul(print_mtx);
|
||||||
|
std::unique_lock<std::mutex> a_ul(accu_mtx);
|
||||||
try {
|
try {
|
||||||
std::unique_lock<std::mutex> ul(mtx);
|
|
||||||
R.initialize_pools();
|
R.initialize_pools();
|
||||||
ul.unlock();
|
a_ul.unlock();
|
||||||
fmt::print("[i] fortuna: pools initialized\n");
|
fmt::print("[i] fortuna: pools initialized\n");
|
||||||
p_ul.unlock();
|
p_ul.unlock();
|
||||||
ul.lock();
|
a_ul.lock();
|
||||||
accumulator.set_gen(R.Gen);
|
accumulator.set_gen(R.Gen);
|
||||||
ul.unlock();
|
a_ul.unlock();
|
||||||
// FIXME: bogus first reseed here, P_0 definitely hasn't collected
|
// FIXME: bogus first reseed here, P_0 definitely hasn't collected
|
||||||
// enough entropy by now
|
// enough entropy by now
|
||||||
incr_reseed_ctr();
|
incr_reseed_ctr();
|
||||||
p_ul.lock();
|
p_ul.lock();
|
||||||
fmt::print("first reseed\n");
|
fmt::print("first reseed\n");
|
||||||
p_ul.unlock();
|
p_ul.unlock();
|
||||||
ul.lock();
|
std::unique_lock<std::mutex> ul(mtx);
|
||||||
R.Gen.reseed("fortuna");
|
R.Gen.reseed("fortuna");
|
||||||
ul.unlock();
|
ul.unlock();
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue