add event_adder_impl
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2021-12-08 03:58:18 +01:00
parent 33f6620662
commit 872e6f7f9f
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
2 changed files with 35 additions and 1 deletions

View File

@ -181,7 +181,7 @@ add_subdirectory(lib/fmt EXCLUDE_FROM_ALL)
endif(NOT CMAKE_EXE_LINKER_FLAGS MATCHES "-fuse-ld=lld")
endif()
add_executable(fortuna main.cpp generator.cpp generator.h fortuna.cpp fortuna.h accumulator.cpp accumulator.h pool.cpp pool.h event_adder.h)
add_executable(fortuna main.cpp generator.cpp generator.h fortuna.cpp fortuna.h accumulator.cpp accumulator.h pool.cpp pool.h event_adder.h event_adder_impl.h)
# ref: https://cmake.org/pipermail/cmake/2016-May/063400.html
target_link_libraries(fortuna
PRIVATE cryptopp

34
event_adder_impl.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef FORTUNA_EVENT_ADDER_IMPL_H
#define FORTUNA_EVENT_ADDER_IMPL_H
#include "event_adder.h"
#include "pool.h"
namespace fortuna {
namespace accumulator {
class EventAdderImpl final : public EventAdder {
private:
int pool;
static unsigned int source_id;
static accumulator::Pool pools[32];
public:
EventAdderImpl(const unsigned int source_id, const accumulator::Pool pools[32]) {
this->source_id = source_id;
for (unsigned int i = 0; i < pools.size(); i++) {
this->pools[i] = pools[i];
}
this->pool = 0;
}
void add(std::vector<char> event) override {
this->pool = (this->pool + 1) % pools.size();
pools[this->pool].add_entropy(source_id, event);
}
};
} //namespace accumulator
} //namespace fortuna
#endif//FORTUNA_EVENT_ADDER_IMPL_H