From 86b465cfccef5552aa111941fb74ec622e2e7c03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Thu, 17 Aug 2023 21:54:45 +0200 Subject: Network: use digest instead of partial ref in protocol header --- src/network/protocol.cpp | 39 +++++++++++++++++++-------------------- src/network/protocol.h | 4 ++-- 2 files changed, 21 insertions(+), 22 deletions(-) (limited to 'src/network') diff --git a/src/network/protocol.cpp b/src/network/protocol.cpp index c2c6c5d..fb3a5ea 100644 --- a/src/network/protocol.cpp +++ b/src/network/protocol.cpp @@ -215,9 +215,8 @@ bool NetworkProtocol::Header::Item::operator==(const Item & other) const 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); if (holds_alternative(value)) return std::get(value) == std::get(other.value); @@ -242,43 +241,43 @@ optional NetworkProtocol::Header::load(const PartialObj if (auto ref = item.asRef()) items.emplace_back(Item { .type = Type::Acknowledged, - .value = *ref, + .value = ref->digest(), }); } else if (item.name == "REQ") { if (auto ref = item.asRef()) items.emplace_back(Item { .type = Type::DataRequest, - .value = *ref, + .value = ref->digest(), }); } else if (item.name == "RSP") { if (auto ref = item.asRef()) items.emplace_back(Item { .type = Type::DataResponse, - .value = *ref, + .value = ref->digest(), }); } else if (item.name == "ANN") { if (auto ref = item.asRef()) items.emplace_back(Item { .type = Type::AnnounceSelf, - .value = *ref, + .value = ref->digest(), }); } else if (item.name == "ANU") { if (auto ref = item.asRef()) items.emplace_back(Item { .type = Type::AnnounceUpdate, - .value = *ref, + .value = ref->digest(), }); } else if (item.name == "CRQ") { if (auto ref = item.asRef()) items.emplace_back(Item { .type = Type::ChannelRequest, - .value = *ref, + .value = ref->digest(), }); } else if (item.name == "CAC") { if (auto ref = item.asRef()) items.emplace_back(Item { .type = Type::ChannelAccept, - .value = *ref, + .value = ref->digest(), }); } else if (item.name == "STP") { if (auto val = item.asUUID()) @@ -290,7 +289,7 @@ optional NetworkProtocol::Header::load(const PartialObj if (auto ref = item.asRef()) items.emplace_back(Item { .type = Type::ServiceRef, - .value = *ref, + .value = ref->digest(), }); } } @@ -298,38 +297,38 @@ optional NetworkProtocol::Header::load(const PartialObj return NetworkProtocol::Header(items); } -PartialObject NetworkProtocol::Header::toObject() const +PartialObject NetworkProtocol::Header::toObject(const PartialStorage & st) const { vector ritems; for (const auto & item : items) { switch (item.type) { case Type::Acknowledged: - ritems.emplace_back("ACK", std::get(item.value)); + ritems.emplace_back("ACK", st.ref(std::get(item.value))); break; case Type::DataRequest: - ritems.emplace_back("REQ", std::get(item.value)); + ritems.emplace_back("REQ", st.ref(std::get(item.value))); break; case Type::DataResponse: - ritems.emplace_back("RSP", std::get(item.value)); + ritems.emplace_back("RSP", st.ref(std::get(item.value))); break; case Type::AnnounceSelf: - ritems.emplace_back("ANN", std::get(item.value)); + ritems.emplace_back("ANN", st.ref(std::get(item.value))); break; case Type::AnnounceUpdate: - ritems.emplace_back("ANU", std::get(item.value)); + ritems.emplace_back("ANU", st.ref(std::get(item.value))); break; case Type::ChannelRequest: - ritems.emplace_back("CRQ", std::get(item.value)); + ritems.emplace_back("CRQ", st.ref(std::get(item.value))); break; case Type::ChannelAccept: - ritems.emplace_back("CAC", std::get(item.value)); + ritems.emplace_back("CAC", st.ref(std::get(item.value))); break; case Type::ServiceType: @@ -337,7 +336,7 @@ PartialObject NetworkProtocol::Header::toObject() const break; case Type::ServiceRef: - ritems.emplace_back("SRF", std::get(item.value)); + ritems.emplace_back("SRF", st.ref(std::get(item.value))); break; } } diff --git a/src/network/protocol.h b/src/network/protocol.h index 8aa22a2..4794ba6 100644 --- a/src/network/protocol.h +++ b/src/network/protocol.h @@ -107,7 +107,7 @@ struct NetworkProtocol::Header struct Item { const Type type; - const variant value; + const variant value; bool operator==(const Item &) const; bool operator!=(const Item & other) const { return !(*this == other); } @@ -116,7 +116,7 @@ struct NetworkProtocol::Header Header(const vector & items): items(items) {} static optional
load(const PartialRef &); static optional
load(const PartialObject &); - PartialObject toObject() const; + PartialObject toObject(const PartialStorage &) const; const vector items; }; -- cgit v1.2.3