From fce349f8f1c53d3e205a8d86b79784fdfd2b7b7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Mon, 8 May 2023 22:07:20 +0200 Subject: Send identity update on channel finalization --- src/network.cpp | 39 +++++++++++++++++++++++++++++++++++---- src/network.h | 4 ++++ 2 files changed, 39 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/network.cpp b/src/network.cpp index 226095b..1eb33d0 100644 --- a/src/network.cpp +++ b/src/network.cpp @@ -499,8 +499,8 @@ void Server::Priv::handlePacket(Server::Peer & peer, const TransportHeader & hea if (auto pref = std::get(item.value)) { if (holds_alternative>(peer.channel) && std::get>(peer.channel).ref().digest() == pref.digest()) - peer.channel.emplace> - (std::get>(peer.channel)->data->channel()); + peer.finalizeChannel(reply, + std::get>(peer.channel)->data->channel()); } break; @@ -607,7 +607,7 @@ void Server::Priv::handlePacket(Server::Peer & peer, const TransportHeader & hea 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.finalizeChannel(reply, acc.data->channel()); } } } @@ -767,6 +767,19 @@ void Server::Peer::updateChannel(ReplyBuilder & reply) } } +void Server::Peer::finalizeChannel(ReplyBuilder & reply, unique_ptr ch) +{ + channel.emplace>(move(ch)); + + vector hitems; + for (const auto & r : server.self.refs()) + reply.header(TransportHeader::Item { + TransportHeader::Type::AnnounceUpdate, r }); + for (const auto & r : server.self.updates()) + reply.header(TransportHeader::Item { + TransportHeader::Type::AnnounceUpdate, r }); +} + void Server::Peer::updateService(ReplyBuilder & reply) { decltype(serviceQueue) next; @@ -823,7 +836,7 @@ void Server::Peer::trySendOutQueue() void ReplyBuilder::header(TransportHeader::Item && item) { for (const auto & x : mheader) - if (x.type == item.type && x.value == item.value) + if (x == item) return; mheader.emplace_back(std::move(item)); } @@ -871,6 +884,24 @@ optional WaitingRef::check(ReplyBuilder & reply) } +bool TransportHeader::Item::operator==(const Item & other) const +{ + if (type != other.type) + return false; + + if (value.index() != other.value.index()) + return false; + + if (holds_alternative(value)) + return std::get(value).digest() == + std::get(other.value).digest(); + + if (holds_alternative(value)) + return std::get(value) == std::get(other.value); + + throw runtime_error("unhandled transport header item type"); +} + optional TransportHeader::load(const PartialRef & ref) { return load(*ref); diff --git a/src/network.h b/src/network.h index a6ba3cd..1c1bb57 100644 --- a/src/network.h +++ b/src/network.h @@ -67,6 +67,7 @@ struct Server::Peer void send(const struct TransportHeader &, const vector &, bool secure); void updateIdentity(ReplyBuilder &); void updateChannel(ReplyBuilder &); + void finalizeChannel(ReplyBuilder &, unique_ptr); void updateService(ReplyBuilder &); void trySendOutQueue(); }; @@ -106,6 +107,9 @@ struct TransportHeader struct Item { const Type type; const variant value; + + bool operator==(const Item &) const; + bool operator!=(const Item & other) const { return !(*this == other); } }; TransportHeader(const vector & items): items(items) {} -- cgit v1.2.3