more sync code
This commit is contained in:
@@ -1,8 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "./crdtnotes.hpp"
|
||||
|
||||
#include <solanaceae/contact/contact_model3.hpp>
|
||||
|
||||
#include <set>
|
||||
#include <random>
|
||||
|
||||
// fwd
|
||||
struct CRDTNotesContactSyncModelI;
|
||||
|
||||
namespace Events {
|
||||
|
||||
// - DocID
|
||||
@@ -67,6 +74,37 @@ struct CRDTNotesEventI {
|
||||
// gets called on incoming packets
|
||||
// calls CRDTNotesContactSyncModelI on contacts
|
||||
class CRDTNotesSync final : public CRDTNotesEventI {
|
||||
// pull inside????
|
||||
CRDTNotes& _notes;
|
||||
Contact3Registry& _cr;
|
||||
|
||||
std::default_random_engine _rng;
|
||||
|
||||
std::unordered_map<CRDTNotes::DocID, std::set<Contact3Handle>> _docs_contacts;
|
||||
|
||||
public:
|
||||
CRDTNotesSync(CRDTNotes& notes, Contact3Registry& cr);
|
||||
|
||||
~CRDTNotesSync(void);
|
||||
|
||||
// called from main thread periodically
|
||||
float iterate(float time_delta);
|
||||
|
||||
public: // CRDTNotes api
|
||||
CRDTNotes::Doc* getDoc(const CRDTNotes::DocID& doc_id);
|
||||
|
||||
// adds a doc and assosiates contact (and self)
|
||||
// if secret, only self is added (and thats why contact is needed)
|
||||
std::optional<CRDTNotes::DocID> addNewDoc(Contact3Handle c, bool secret = false);
|
||||
|
||||
// adds a doc by id to a contact
|
||||
// (for gossip or manual add)
|
||||
bool addDoc(const CRDTNotes::DocID& doc_id, Contact3Handle c);
|
||||
|
||||
std::vector<CRDTNotes::DocID> getDocList(void);
|
||||
std::vector<CRDTNotes::DocID> getDocList(Contact3Handle c);
|
||||
|
||||
void merge(const CRDTNotes::DocID& doc_id, std::string_view new_text);
|
||||
|
||||
public:
|
||||
void onCRDTNSyncEvent(Events::NGCEXT_crdtns_gossip&& e) override;
|
||||
|
||||
Reference in New Issue
Block a user