From 3357cbc91e7ff4d0d455c88785fc455067b34820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sat, 14 Mar 2020 21:14:52 +0100 Subject: Storage: filter ancestors and overwritable Ref and Stored Simple but slow implementation of the filtering for now. --- src/channel.cpp | 8 ++++---- src/identity.cpp | 12 ++++++------ src/network.cpp | 28 ++++++++++++++-------------- src/pubkey.cpp | 8 ++++---- src/pubkey.h | 6 +++--- src/storage.cpp | 3 +-- 6 files changed, 32 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/channel.cpp b/src/channel.cpp index 38d263e..50c5f97 100644 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -84,7 +84,7 @@ optional ChannelAcceptData::load(const Ref & ref) Stored ChannelAcceptData::channel() const { - const auto & st = request.ref.storage(); + const auto & st = request.ref().storage(); if (auto secret = SecretKexKey::load(key)) return st.store(Channel( @@ -166,12 +166,12 @@ optional> Channel::acceptRequest(const Identity & self, auto & peers = request->data->peers; if (peers.size() != 2 || std::none_of(peers.begin(), peers.end(), [&self](const auto & x) - { return x.ref.digest() == self.ref()->digest(); }) || + { return x.ref().digest() == self.ref()->digest(); }) || std::none_of(peers.begin(), peers.end(), [&peer](const auto & x) - { return x.ref.digest() == peer.ref()->digest(); })) + { return x.ref().digest() == peer.ref()->digest(); })) return nullopt; - auto & st = request.ref.storage(); + auto & st = request.ref().storage(); auto signKey = SecretKey::load(self.keyMessage()); if (!signKey) diff --git a/src/identity.cpp b/src/identity.cpp index 61059ab..8f606ae 100644 --- a/src/identity.cpp +++ b/src/identity.cpp @@ -61,7 +61,7 @@ Stored Identity::keyMessage() const optional Identity::ref() const { if (p->data.size() == 1) - return p->data[0].ref; + return p->data[0].ref(); return nullopt; } @@ -77,7 +77,7 @@ Identity::Builder Identity::create(const Storage & st) Identity::Builder Identity::modify() const { return Builder (new Builder::Priv { - .storage = p->data[0].ref.storage(), + .storage = p->data[0].ref().storage(), .prev = p->data, .keyIdentity = p->data[0]->data->keyIdentity, .keyMessage = p->data[0]->data->keyMessage, @@ -146,14 +146,14 @@ Ref IdentityData::store(const Storage & st) const vector items; for (const auto p : prev) - items.emplace_back("SPREV", p.ref); + items.emplace_back("SPREV", p.ref()); if (name) items.emplace_back("name", *name); if (owner) - items.emplace_back("owner", owner->ref); - items.emplace_back("key-id", keyIdentity.ref); + items.emplace_back("owner", owner->ref()); + items.emplace_back("key-id", keyIdentity.ref()); if (keyMessage) - items.emplace_back("key-msg", keyMessage->ref); + items.emplace_back("key-msg", keyMessage->ref()); return st.storeObject(Record(std::move(items))); } diff --git a/src/network.cpp b/src/network.cpp index ce0dd30..b31d949 100644 --- a/src/network.cpp +++ b/src/network.cpp @@ -299,7 +299,7 @@ void Server::Priv::handlePacket(Server::Peer & peer, const TransportHeader & hea { unordered_set plaintextRefs; for (const auto & obj : collectStoredObjects(*Stored::load(*self.ref()))) - plaintextRefs.insert(obj.ref.digest()); + plaintextRefs.insert(obj.ref().digest()); optional serviceType; @@ -308,7 +308,7 @@ void Server::Priv::handlePacket(Server::Peer & peer, const TransportHeader & hea case TransportHeader::Type::Acknowledged: if (auto pref = std::get(item.value)) { if (holds_alternative>(peer.channel) && - std::get>(peer.channel).ref.digest() == pref.digest()) + std::get>(peer.channel).ref().digest() == pref.digest()) peer.channel.emplace> (std::get>(peer.channel)->data->channel()); } @@ -371,7 +371,7 @@ void Server::Priv::handlePacket(Server::Peer & peer, const TransportHeader & hea reply.header({ TransportHeader::Type::Acknowledged, pref }); if (holds_alternative>(peer.channel) && - std::get>(peer.channel).ref.digest() < pref.digest()) + std::get>(peer.channel).ref().digest() < pref.digest()) break; if (holds_alternative>(peer.channel)) @@ -392,7 +392,7 @@ void Server::Priv::handlePacket(Server::Peer & peer, const TransportHeader & hea case TransportHeader::Type::ChannelAccept: if (auto pref = std::get(item.value)) { if (holds_alternative>(peer.channel) && - std::get>(peer.channel).ref.digest() < pref.digest()) + std::get>(peer.channel).ref().digest() < pref.digest()) break; auto cres = peer.tempStorage.copy(pref); @@ -475,12 +475,12 @@ void Server::Peer::updateChannel(ReplyBuilder & reply) auto req = Channel::generateRequest(tempStorage, server.self, std::get(identity)); channel.emplace>(req); - reply.header({ TransportHeader::Type::ChannelRequest, req.ref }); - reply.body(req.ref); - reply.body(req->data.ref); - reply.body(req->data->key.ref); + reply.header({ TransportHeader::Type::ChannelRequest, req.ref() }); + reply.body(req.ref()); + reply.body(req->data.ref()); + reply.body(req->data->key.ref()); for (const auto & sig : req->sigs) - reply.body(sig.ref); + reply.body(sig.ref()); } if (holds_alternative>(channel)) { @@ -488,12 +488,12 @@ void Server::Peer::updateChannel(ReplyBuilder & reply) if (auto req = Stored::load(*ref)) { if (auto acc = Channel::acceptRequest(server.self, std::get(identity), *req)) { channel.emplace>(*acc); - reply.header({ TransportHeader::Type::ChannelAccept, acc->ref }); - reply.body(acc->ref); - reply.body(acc.value()->data.ref); - reply.body(acc.value()->data->key.ref); + reply.header({ TransportHeader::Type::ChannelAccept, acc->ref() }); + reply.body(acc->ref()); + reply.body(acc.value()->data.ref()); + reply.body(acc.value()->data->key.ref()); for (const auto & sig : acc.value()->sigs) - reply.body(sig.ref); + reply.body(sig.ref()); } else { channel = monostate(); } diff --git a/src/pubkey.cpp b/src/pubkey.cpp index 6f6c1e7..0e83136 100644 --- a/src/pubkey.cpp +++ b/src/pubkey.cpp @@ -68,14 +68,14 @@ SecretKey SecretKey::generate(const Storage & st) EVP_PKEY_get_raw_private_key(seckey.get(), nullptr, &keyLen); keyData.resize(keyLen); EVP_PKEY_get_raw_private_key(seckey.get(), keyData.data(), &keyLen); - st.storeKey(pubkey.ref, keyData); + st.storeKey(pubkey.ref(), keyData); return SecretKey(std::move(seckey), pubkey); } optional SecretKey::load(const Stored & pub) { - auto keyData = pub.ref.storage().loadKey(pub.ref); + auto keyData = pub.ref().storage().loadKey(pub.ref()); if (!keyData) return nullopt; @@ -211,14 +211,14 @@ SecretKexKey SecretKexKey::generate(const Storage & st) EVP_PKEY_get_raw_private_key(seckey.get(), nullptr, &keyLen); keyData.resize(keyLen); EVP_PKEY_get_raw_private_key(seckey.get(), keyData.data(), &keyLen); - st.storeKey(pubkey.ref, keyData); + st.storeKey(pubkey.ref(), keyData); return SecretKexKey(std::move(seckey), pubkey); } optional SecretKexKey::load(const Stored & pub) { - auto keyData = pub.ref.storage().loadKey(pub.ref); + auto keyData = pub.ref().storage().loadKey(pub.ref()); if (!keyData) return nullopt; diff --git a/src/pubkey.h b/src/pubkey.h index 607352d..c922dc7 100644 --- a/src/pubkey.h +++ b/src/pubkey.h @@ -84,8 +84,8 @@ private: template Stored> SecretKey::sign(const Stored & val) const { - auto st = val.ref.storage(); - auto sig = st.store(Signature(pub(), sign(val.ref.digest()))); + auto st = val.ref().storage(); + auto sig = st.store(Signature(pub(), sign(val.ref().digest()))); return st.store(Signed(val, { sig })); } @@ -103,7 +103,7 @@ optional> Signed::load(const Ref & ref) vector> sigs; for (auto item : rec->items("sig")) if (auto sig = item.as()) - if (sig.value()->verify(data.value().ref)) + if (sig.value()->verify(data.value().ref())) sigs.push_back(sig.value()); return Signed(*data, sigs); diff --git a/src/storage.cpp b/src/storage.cpp index 525d83d..49bac54 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -1,7 +1,6 @@ #include "storage.h" #include "base64.h" -#include #include #include #include @@ -943,7 +942,7 @@ vector> erebos::collectStoredObjects(const Stored & from) auto cur = queue.back(); queue.pop_back(); - auto [it, added] = seen.insert(cur.ref.digest()); + auto [it, added] = seen.insert(cur.ref().digest()); if (!added) continue; -- cgit v1.2.3