diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2020-01-11 16:13:40 +0100 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2020-01-11 16:13:40 +0100 |
commit | ec402bfaa90cdb52276f5ccc2525e799cb4419d7 (patch) | |
tree | 1e0c6db70894bbcd45f5d23b7dff498b3feb6c97 /src/storage.cpp | |
parent | 7d403431e354c4a24d7dfdbef3a39ab7297ae7b5 (diff) |
Request missing data from network
Diffstat (limited to 'src/storage.cpp')
-rw-r--r-- | src/storage.cpp | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/src/storage.cpp b/src/storage.cpp index 608f82b..6b2e4f8 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -316,6 +316,19 @@ optional<Ref> Storage::ref(const Digest & digest) const return Ref::create(*this, digest); } +Digest PartialStorage::Priv::storeBytes(const vector<uint8_t> & content) const +{ + array<uint8_t, Digest::size> arr; + int ret = blake2b(arr.data(), content.data(), nullptr, + Digest::size, content.size(), 0); + if (ret != 0) + throw runtime_error("failed to compute digest"); + + Digest digest(arr); + backend->storeBytes(digest, content); + return digest; +} + optional<vector<uint8_t>> PartialStorage::Priv::loadBytes(const Digest & digest) const { auto ocontent = backend->loadBytes(digest); @@ -339,6 +352,15 @@ optional<PartialObject> PartialStorage::loadObject(const Digest & digest) const return nullopt; } +PartialRef PartialStorage::storeObject(const PartialObject & obj) const +{ return ref(p->storeBytes(obj.encode())); } + +PartialRef PartialStorage::storeObject(const PartialRecord & val) const +{ return storeObject(PartialObject(val)); } + +PartialRef PartialStorage::storeObject(const Blob & val) const +{ return storeObject(PartialObject(val)); } + optional<Object> Storage::loadObject(const Digest & digest) const { if (auto content = p->loadBytes(digest)) @@ -380,17 +402,7 @@ optional<Digest> Storage::Priv::copy(const ObjectT<S> & pobj, vector<Digest> * m if (fail) return nullopt; - auto content = pobj.encode(); - - array<uint8_t, Digest::size> arr; - int ret = blake2b(arr.data(), content.data(), nullptr, - Digest::size, content.size(), 0); - if (ret != 0) - throw runtime_error("failed to compute digest"); - - Digest digest(arr); - backend->storeBytes(digest, content); - return digest; + return storeBytes(pobj.encode()); } variant<Ref, vector<Digest>> Storage::copy(const PartialRef & pref) const |