From 6cf5244bc514042fe419fffe1cd26a7f5e3c778f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Thu, 16 Apr 2020 21:42:45 +0200 Subject: Remove optional from load result Makes loading of data well-defined for arbitrary object contents. Introduce zero reference and object to represent missing or mismatched parts. --- src/network.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/network.cpp') diff --git a/src/network.cpp b/src/network.cpp index b31d949..91f1923 100644 --- a/src/network.cpp +++ b/src/network.cpp @@ -298,7 +298,7 @@ Server::Peer & Server::Priv::getPeer(const sockaddr_in & paddr) void Server::Priv::handlePacket(Server::Peer & peer, const TransportHeader & header, ReplyBuilder & reply) { unordered_set plaintextRefs; - for (const auto & obj : collectStoredObjects(*Stored::load(*self.ref()))) + for (const auto & obj : collectStoredObjects(Stored::load(*self.ref()))) plaintextRefs.insert(obj.ref().digest()); optional serviceType; @@ -397,9 +397,11 @@ void Server::Priv::handlePacket(Server::Peer & peer, const TransportHeader & hea auto cres = peer.tempStorage.copy(pref); if (auto r = std::get_if(&cres)) { - if (auto acc = ChannelAccept::load(*r)) { + auto acc = ChannelAccept::load(*r); + if (holds_alternative(peer.identity) && + acc.isSignedBy(std::get(peer.identity).keyMessage())) { reply.header({ TransportHeader::Type::Acknowledged, pref }); - peer.channel.emplace>(acc->data->channel()); + peer.channel.emplace>(acc.data->channel()); } } } @@ -485,8 +487,10 @@ void Server::Peer::updateChannel(ReplyBuilder & reply) if (holds_alternative>(channel)) { if (auto ref = std::get>(channel)->check(reply)) { - if (auto req = Stored::load(*ref)) { - if (auto acc = Channel::acceptRequest(server.self, std::get(identity), *req)) { + auto req = Stored::load(*ref); + if (holds_alternative(identity) && + req->isSignedBy(std::get(identity).keyMessage())) { + 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()); -- cgit v1.2.3