summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2020-03-14 21:14:52 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2020-03-14 21:14:52 +0100
commit3357cbc91e7ff4d0d455c88785fc455067b34820 (patch)
treec1a39e4e55c3bcc03461838b4d8220c3e5a30987 /src
parent9076a13c78cf64a6afafe98817aed31feda568b1 (diff)
Storage: filter ancestors and overwritable Ref and Stored
Simple but slow implementation of the filtering for now.
Diffstat (limited to 'src')
-rw-r--r--src/channel.cpp8
-rw-r--r--src/identity.cpp12
-rw-r--r--src/network.cpp28
-rw-r--r--src/pubkey.cpp8
-rw-r--r--src/pubkey.h6
-rw-r--r--src/storage.cpp3
6 files changed, 32 insertions, 33 deletions
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> ChannelAcceptData::load(const Ref & ref)
Stored<Channel> 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<Stored<ChannelAccept>> 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<PublicKey> Identity::keyMessage() const
optional<Ref> 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<Record::Item> 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<Digest> plaintextRefs;
for (const auto & obj : collectStoredObjects(*Stored<Object>::load(*self.ref())))
- plaintextRefs.insert(obj.ref.digest());
+ plaintextRefs.insert(obj.ref().digest());
optional<UUID> serviceType;
@@ -308,7 +308,7 @@ void Server::Priv::handlePacket(Server::Peer & peer, const TransportHeader & hea
case TransportHeader::Type::Acknowledged:
if (auto pref = std::get<PartialRef>(item.value)) {
if (holds_alternative<Stored<ChannelAccept>>(peer.channel) &&
- std::get<Stored<ChannelAccept>>(peer.channel).ref.digest() == pref.digest())
+ std::get<Stored<ChannelAccept>>(peer.channel).ref().digest() == pref.digest())
peer.channel.emplace<Stored<Channel>>
(std::get<Stored<ChannelAccept>>(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<Stored<ChannelRequest>>(peer.channel) &&
- std::get<Stored<ChannelRequest>>(peer.channel).ref.digest() < pref.digest())
+ std::get<Stored<ChannelRequest>>(peer.channel).ref().digest() < pref.digest())
break;
if (holds_alternative<Stored<ChannelAccept>>(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<PartialRef>(item.value)) {
if (holds_alternative<Stored<ChannelAccept>>(peer.channel) &&
- std::get<Stored<ChannelAccept>>(peer.channel).ref.digest() < pref.digest())
+ std::get<Stored<ChannelAccept>>(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>(identity));
channel.emplace<Stored<ChannelRequest>>(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<shared_ptr<WaitingRef>>(channel)) {
@@ -488,12 +488,12 @@ void Server::Peer::updateChannel(ReplyBuilder & reply)
if (auto req = Stored<ChannelRequest>::load(*ref)) {
if (auto acc = Channel::acceptRequest(server.self, std::get<Identity>(identity), *req)) {
channel.emplace<Stored<ChannelAccept>>(*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> SecretKey::load(const Stored<PublicKey> & 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> SecretKexKey::load(const Stored<PublicKexKey> & 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<class T>
Stored<Signed<T>> SecretKey::sign(const Stored<T> & 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<T>> Signed<T>::load(const Ref & ref)
vector<Stored<Signature>> sigs;
for (auto item : rec->items("sig"))
if (auto sig = item.as<Signature>())
- 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 <algorithm>
#include <charconv>
#include <chrono>
#include <fstream>
@@ -943,7 +942,7 @@ vector<Stored<Object>> erebos::collectStoredObjects(const Stored<Object> & 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;