Fix compiler errors

This commit is contained in:
Sebastian Messmer 2016-06-23 19:16:13 -07:00
parent 1a72d3c226
commit 473e9cc8bb
7 changed files with 11 additions and 17 deletions

View File

@ -4,6 +4,7 @@
#include "../../interface/helpers/BlockStoreWithRandomKeys.h"
#include <cpp-utils/macros.h>
#include "InMemoryBlock.h"
#include <mutex>
#include <unordered_map>

View File

@ -16,7 +16,7 @@ namespace blockstore {
class KnownBlockVersions final {
public:
KnownBlockVersions(const boost::filesystem::path &stateFilePath);
explicit KnownBlockVersions(const boost::filesystem::path &stateFilePath);
KnownBlockVersions(KnownBlockVersions &&rhs);
~KnownBlockVersions();

View File

@ -7,6 +7,5 @@ namespace blockstore {
constexpr unsigned int VersionCountingBlock::HEADER_LENGTH;
constexpr uint16_t VersionCountingBlock::FORMAT_VERSION_HEADER;
constexpr uint64_t VersionCountingBlock::VERSION_ZERO;
constexpr uint64_t VersionCountingBlock::VERSION_DELETED;
}
}

View File

@ -60,13 +60,13 @@ private:
// This header is prepended to blocks to allow future versions to have compatibility.
static constexpr uint16_t FORMAT_VERSION_HEADER = 0;
static constexpr uint64_t VERSION_ZERO = 0;
std::mutex _mutex;
DISALLOW_COPY_AND_ASSIGN(VersionCountingBlock);
public:
static constexpr uint64_t VERSION_ZERO = 0;
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 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);
uint64_t version = _readVersion(data);
if(!knownBlockVersions->checkAndUpdateVersion(lastClientId, key, version)) {
if (knownBlockVersions->getBlockVersion(lastClientId, key) == VERSION_DELETED) {
cpputils::logging::LOG(cpputils::logging::WARN) << "Decrypting block " << key.ToString() <<
" failed because it was marked as deleted. Was the block reintroduced 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;
" failed due to decreasing version number. Was the block rolled back or re-introduced by an attacker?";
}
return true;
}
@ -148,8 +142,8 @@ inline VersionCountingBlock::VersionCountingBlock(cpputils::unique_ref<Block> ba
_version(_readVersion(_dataWithHeader)),
_dataChanged(false),
_mutex() {
if (_version == VERSION_DELETED) {
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.");
if (_version == std::numeric_limits<uint64_t>::max()) {
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.");
}
}

View File

@ -14,7 +14,7 @@ namespace versioncounting {
class VersionCountingBlockStore final: public BlockStore {
public:
VersionCountingBlockStore(cpputils::unique_ref<BlockStore> baseBlockStore, KnownBlockVersions knownBlockVersions);
VersionCountingBlockStore(cpputils::unique_ref<BlockStore> baseBlockStore, const boost::filesystem::path &integrityFilePath);
Key createKey() 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)
: _baseBlockStore(std::move(baseBlockStore)), _knownBlockVersions(std::move(knownBlockVersions)) {
inline VersionCountingBlockStore::VersionCountingBlockStore(cpputils::unique_ref<BlockStore> baseBlockStore, const boost::filesystem::path &integrityFilePath)
: _baseBlockStore(std::move(baseBlockStore)), _knownBlockVersions(integrityFilePath) {
}
inline Key VersionCountingBlockStore::createKey() {

View File

@ -23,7 +23,7 @@ public:
TempFile stateFile;
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());
}
};

View File

@ -24,7 +24,7 @@ public:
VersionCountingBlockStoreTest():
stateFile(false),
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)) {
}
TempFile stateFile;