Fix compiler errors
This commit is contained in:
parent
1a72d3c226
commit
473e9cc8bb
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "../../interface/helpers/BlockStoreWithRandomKeys.h"
|
#include "../../interface/helpers/BlockStoreWithRandomKeys.h"
|
||||||
#include <cpp-utils/macros.h>
|
#include <cpp-utils/macros.h>
|
||||||
|
#include "InMemoryBlock.h"
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
@ -16,7 +16,7 @@ namespace blockstore {
|
|||||||
|
|
||||||
class KnownBlockVersions final {
|
class KnownBlockVersions final {
|
||||||
public:
|
public:
|
||||||
KnownBlockVersions(const boost::filesystem::path &stateFilePath);
|
explicit KnownBlockVersions(const boost::filesystem::path &stateFilePath);
|
||||||
KnownBlockVersions(KnownBlockVersions &&rhs);
|
KnownBlockVersions(KnownBlockVersions &&rhs);
|
||||||
~KnownBlockVersions();
|
~KnownBlockVersions();
|
||||||
|
|
||||||
|
@ -7,6 +7,5 @@ namespace blockstore {
|
|||||||
constexpr unsigned int VersionCountingBlock::HEADER_LENGTH;
|
constexpr unsigned int VersionCountingBlock::HEADER_LENGTH;
|
||||||
constexpr uint16_t VersionCountingBlock::FORMAT_VERSION_HEADER;
|
constexpr uint16_t VersionCountingBlock::FORMAT_VERSION_HEADER;
|
||||||
constexpr uint64_t VersionCountingBlock::VERSION_ZERO;
|
constexpr uint64_t VersionCountingBlock::VERSION_ZERO;
|
||||||
constexpr uint64_t VersionCountingBlock::VERSION_DELETED;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,13 +60,13 @@ private:
|
|||||||
|
|
||||||
// This header is prepended to blocks to allow future versions to have compatibility.
|
// This header is prepended to blocks to allow future versions to have compatibility.
|
||||||
static constexpr uint16_t FORMAT_VERSION_HEADER = 0;
|
static constexpr uint16_t FORMAT_VERSION_HEADER = 0;
|
||||||
static constexpr uint64_t VERSION_ZERO = 0;
|
|
||||||
|
|
||||||
std::mutex _mutex;
|
std::mutex _mutex;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(VersionCountingBlock);
|
DISALLOW_COPY_AND_ASSIGN(VersionCountingBlock);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static constexpr uint64_t VERSION_ZERO = 0;
|
||||||
static constexpr unsigned int CLIENTID_HEADER_OFFSET = sizeof(FORMAT_VERSION_HEADER);
|
static constexpr unsigned int CLIENTID_HEADER_OFFSET = sizeof(FORMAT_VERSION_HEADER);
|
||||||
static constexpr unsigned int VERSION_HEADER_OFFSET = sizeof(FORMAT_VERSION_HEADER) + sizeof(uint32_t);
|
static constexpr unsigned int VERSION_HEADER_OFFSET = sizeof(FORMAT_VERSION_HEADER) + sizeof(uint32_t);
|
||||||
static constexpr unsigned int HEADER_LENGTH = sizeof(FORMAT_VERSION_HEADER) + sizeof(uint32_t) + sizeof(VERSION_ZERO);
|
static constexpr unsigned int HEADER_LENGTH = sizeof(FORMAT_VERSION_HEADER) + sizeof(uint32_t) + sizeof(VERSION_ZERO);
|
||||||
@ -110,14 +110,8 @@ inline bool VersionCountingBlock::_checkVersion(const cpputils::Data &data, cons
|
|||||||
uint32_t lastClientId = _readClientId(data);
|
uint32_t lastClientId = _readClientId(data);
|
||||||
uint64_t version = _readVersion(data);
|
uint64_t version = _readVersion(data);
|
||||||
if(!knownBlockVersions->checkAndUpdateVersion(lastClientId, key, version)) {
|
if(!knownBlockVersions->checkAndUpdateVersion(lastClientId, key, version)) {
|
||||||
if (knownBlockVersions->getBlockVersion(lastClientId, key) == VERSION_DELETED) {
|
|
||||||
cpputils::logging::LOG(cpputils::logging::WARN) << "Decrypting block " << key.ToString() <<
|
cpputils::logging::LOG(cpputils::logging::WARN) << "Decrypting block " << key.ToString() <<
|
||||||
" failed because it was marked as deleted. Was the block reintroduced by an attacker?";
|
" failed due to decreasing version number. Was the block rolled back or re-introduced by an attacker?";
|
||||||
} else {
|
|
||||||
cpputils::logging::LOG(cpputils::logging::WARN) << "Decrypting block " << key.ToString() <<
|
|
||||||
" failed due to decreasing version number. Was the block rolled back by an attacker?";
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -148,8 +142,8 @@ inline VersionCountingBlock::VersionCountingBlock(cpputils::unique_ref<Block> ba
|
|||||||
_version(_readVersion(_dataWithHeader)),
|
_version(_readVersion(_dataWithHeader)),
|
||||||
_dataChanged(false),
|
_dataChanged(false),
|
||||||
_mutex() {
|
_mutex() {
|
||||||
if (_version == VERSION_DELETED) {
|
if (_version == std::numeric_limits<uint64_t>::max()) {
|
||||||
throw std::runtime_error("Loaded block is marked as deleted. This shouldn't happen because in case of a version number overflow, the block isn't stored at all.");
|
throw std::runtime_error("Version overflow when loading. This shouldn't happen because in case of a version number overflow, the block isn't stored at all.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ namespace versioncounting {
|
|||||||
|
|
||||||
class VersionCountingBlockStore final: public BlockStore {
|
class VersionCountingBlockStore final: public BlockStore {
|
||||||
public:
|
public:
|
||||||
VersionCountingBlockStore(cpputils::unique_ref<BlockStore> baseBlockStore, KnownBlockVersions knownBlockVersions);
|
VersionCountingBlockStore(cpputils::unique_ref<BlockStore> baseBlockStore, const boost::filesystem::path &integrityFilePath);
|
||||||
|
|
||||||
Key createKey() override;
|
Key createKey() override;
|
||||||
boost::optional<cpputils::unique_ref<Block>> tryCreate(const Key &key, cpputils::Data data) override;
|
boost::optional<cpputils::unique_ref<Block>> tryCreate(const Key &key, cpputils::Data data) override;
|
||||||
@ -33,8 +33,8 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
inline VersionCountingBlockStore::VersionCountingBlockStore(cpputils::unique_ref<BlockStore> baseBlockStore, KnownBlockVersions knownBlockVersions)
|
inline VersionCountingBlockStore::VersionCountingBlockStore(cpputils::unique_ref<BlockStore> baseBlockStore, const boost::filesystem::path &integrityFilePath)
|
||||||
: _baseBlockStore(std::move(baseBlockStore)), _knownBlockVersions(std::move(knownBlockVersions)) {
|
: _baseBlockStore(std::move(baseBlockStore)), _knownBlockVersions(integrityFilePath) {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Key VersionCountingBlockStore::createKey() {
|
inline Key VersionCountingBlockStore::createKey() {
|
||||||
|
@ -23,7 +23,7 @@ public:
|
|||||||
|
|
||||||
TempFile stateFile;
|
TempFile stateFile;
|
||||||
unique_ref<BlockStore> createBlockStore() override {
|
unique_ref<BlockStore> createBlockStore() override {
|
||||||
return make_unique_ref<VersionCountingBlockStore>(make_unique_ref<FakeBlockStore>(), KnownBlockVersions(stateFile.path()));
|
return make_unique_ref<VersionCountingBlockStore>(make_unique_ref<FakeBlockStore>(), stateFile.path());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ public:
|
|||||||
VersionCountingBlockStoreTest():
|
VersionCountingBlockStoreTest():
|
||||||
stateFile(false),
|
stateFile(false),
|
||||||
baseBlockStore(new FakeBlockStore),
|
baseBlockStore(new FakeBlockStore),
|
||||||
blockStore(make_unique_ref<VersionCountingBlockStore>(std::move(cpputils::nullcheck(std::unique_ptr<FakeBlockStore>(baseBlockStore)).value()), KnownBlockVersions(stateFile.path()))),
|
blockStore(make_unique_ref<VersionCountingBlockStore>(std::move(cpputils::nullcheck(std::unique_ptr<FakeBlockStore>(baseBlockStore)).value()), stateFile.path())),
|
||||||
data(DataFixture::generate(BLOCKSIZE)) {
|
data(DataFixture::generate(BLOCKSIZE)) {
|
||||||
}
|
}
|
||||||
TempFile stateFile;
|
TempFile stateFile;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user