From e4b5eb30af94991e19ac324d5e6ec616e6a71d36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 3 Dec 2023 22:52:26 +0100 Subject: Contacts with extended identity --- include/erebos/contact.h | 2 +- include/erebos/identity.h | 31 +++++++++++++++++++++++++++++++ src/contact.cpp | 14 +++++++++----- src/identity.h | 31 ------------------------------- 4 files changed, 41 insertions(+), 37 deletions(-) diff --git a/include/erebos/contact.h b/include/erebos/contact.h index 963e22a..9008ce7 100644 --- a/include/erebos/contact.h +++ b/include/erebos/contact.h @@ -57,7 +57,7 @@ struct ContactData Ref store(const Storage &) const; vector> prev; - vector>> identity; + vector identity; optional name; }; diff --git a/include/erebos/identity.h b/include/erebos/identity.h index 7829361..4792330 100644 --- a/include/erebos/identity.h +++ b/include/erebos/identity.h @@ -71,6 +71,37 @@ private: Identity(std::shared_ptr && p); }; +struct IdentityData; +struct IdentityExtension; + +struct StoredIdentityPart +{ + using Part = variant< + Stored>, + Stored>>; + + StoredIdentityPart(Part p): part(move(p)) {} + + static StoredIdentityPart load(const Ref &); + Ref store(const Storage & st) const; + + bool operator==(const StoredIdentityPart & other) const + { return part == other.part; } + bool operator<(const StoredIdentityPart & other) const + { return part < other.part; } + + const Ref & ref() const; + const Stored> & base() const; + + vector previous() const; + vector roots() const; + optional name() const; + optional owner() const; + bool isSignedBy(const Stored &) const; + + Part part; +}; + DECLARE_SHARED_TYPE(optional) } diff --git a/src/contact.cpp b/src/contact.cpp index 01aa710..9ab5699 100644 --- a/src/contact.cpp +++ b/src/contact.cpp @@ -91,7 +91,7 @@ Digest Contact::leastRoot() const void Contact::Priv::init() { std::call_once(initFlag, [this]() { - vector>> idata; + vector idata; for (const auto & c : findPropertyComponents(data, "identity")) for (const auto & i : c->identity) idata.push_back(i); @@ -111,9 +111,13 @@ ContactData ContactData::load(const Ref & ref) if (!rec) return ContactData(); + vector identity; + for (const auto & r : rec->items("identity").asRef()) + identity.push_back(StoredIdentityPart::load(r)); + return ContactData { .prev = rec->items("PREV").as(), - .identity = rec->items("identity").as>(), + .identity = move(identity), .name = rec->item("name").asText(), }; } @@ -125,7 +129,7 @@ Ref ContactData::store(const Storage & st) const for (const auto & prev : prev) items.emplace_back("PREV", prev.ref()); for (const auto & idt : identity) - items.emplace_back("identity", idt); + items.emplace_back("identity", idt.ref()); if (name) items.emplace_back("name", *name); @@ -155,7 +159,7 @@ Stored ContactService::handlePairingComplete(const Peer & peer) server.localHead().update([&] (const Stored & local) { auto cdata = local.ref().storage().store(ContactData { .prev = {}, - .identity = peer.identity()->finalOwner().data(), + .identity = peer.identity()->finalOwner().extData(), .name = std::nullopt, }); @@ -176,7 +180,7 @@ void ContactService::handlePairingResult(Context & ctx, Stored) { auto cdata = ctx.local().ref().storage().store(ContactData { .prev = {}, - .identity = ctx.peer().identity()->finalOwner().data(), + .identity = ctx.peer().identity()->finalOwner().extData(), .name = std::nullopt, }); diff --git a/src/identity.h b/src/identity.h index c3d9e2c..1653f51 100644 --- a/src/identity.h +++ b/src/identity.h @@ -15,37 +15,6 @@ using std::vector; namespace erebos { -struct IdentityData; -struct IdentityExtension; - -struct StoredIdentityPart -{ - using Part = variant< - Stored>, - Stored>>; - - StoredIdentityPart(Part p): part(move(p)) {} - - static StoredIdentityPart load(const Ref &); - Ref store(const Storage & st) const; - - bool operator==(const StoredIdentityPart & other) const - { return part == other.part; } - bool operator<(const StoredIdentityPart & other) const - { return part < other.part; } - - const Ref & ref() const; - const Stored> & base() const; - - vector previous() const; - vector roots() const; - optional name() const; - optional owner() const; - bool isSignedBy(const Stored &) const; - - Part part; -}; - struct IdentityData { static IdentityData load(const Ref &); -- cgit v1.2.3