fragment events + 256bit uuids
This commit is contained in:
parent
1bfd04680e
commit
2e7d5538d1
@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
|
|||||||
|
|
||||||
add_library(fragment_store
|
add_library(fragment_store
|
||||||
./fragment_store/fragment_store_i.hpp
|
./fragment_store/fragment_store_i.hpp
|
||||||
|
./fragment_store/fragment_store_i.cpp
|
||||||
./fragment_store/types.hpp
|
./fragment_store/types.hpp
|
||||||
./fragment_store/meta_components.hpp
|
./fragment_store/meta_components.hpp
|
||||||
./fragment_store/meta_components_id.inl
|
./fragment_store/meta_components_id.inl
|
||||||
|
@ -33,23 +33,34 @@ FragmentStore::FragmentStore(void) {
|
|||||||
{ // random namespace
|
{ // random namespace
|
||||||
const auto num0 = _rng();
|
const auto num0 = _rng();
|
||||||
const auto num1 = _rng();
|
const auto num1 = _rng();
|
||||||
|
const auto num2 = _rng();
|
||||||
|
const auto num3 = _rng();
|
||||||
|
|
||||||
_session_uuid_namespace[0] = (num0 >> 0) & 0xff;
|
_session_uuid_namespace[0+0] = (num0 >> 0) & 0xff;
|
||||||
_session_uuid_namespace[1] = (num0 >> 8) & 0xff;
|
_session_uuid_namespace[0+1] = (num0 >> 8) & 0xff;
|
||||||
_session_uuid_namespace[2] = (num0 >> 16) & 0xff;
|
_session_uuid_namespace[0+2] = (num0 >> 16) & 0xff;
|
||||||
_session_uuid_namespace[3] = (num0 >> 24) & 0xff;
|
_session_uuid_namespace[0+3] = (num0 >> 24) & 0xff;
|
||||||
|
|
||||||
_session_uuid_namespace[4] = (num1 >> 0) & 0xff;
|
_session_uuid_namespace[4+0] = (num1 >> 0) & 0xff;
|
||||||
_session_uuid_namespace[5] = (num1 >> 8) & 0xff;
|
_session_uuid_namespace[4+1] = (num1 >> 8) & 0xff;
|
||||||
_session_uuid_namespace[6] = (num1 >> 16) & 0xff;
|
_session_uuid_namespace[4+2] = (num1 >> 16) & 0xff;
|
||||||
_session_uuid_namespace[7] = (num1 >> 24) & 0xff;
|
_session_uuid_namespace[4+3] = (num1 >> 24) & 0xff;
|
||||||
|
|
||||||
|
_session_uuid_namespace[8+0] = (num2 >> 0) & 0xff;
|
||||||
|
_session_uuid_namespace[8+1] = (num2 >> 8) & 0xff;
|
||||||
|
_session_uuid_namespace[8+2] = (num2 >> 16) & 0xff;
|
||||||
|
_session_uuid_namespace[8+3] = (num2 >> 24) & 0xff;
|
||||||
|
|
||||||
|
_session_uuid_namespace[12+0] = (num3 >> 0) & 0xff;
|
||||||
|
_session_uuid_namespace[12+1] = (num3 >> 8) & 0xff;
|
||||||
|
_session_uuid_namespace[12+2] = (num3 >> 16) & 0xff;
|
||||||
|
_session_uuid_namespace[12+3] = (num3 >> 24) & 0xff;
|
||||||
}
|
}
|
||||||
registerSerializers();
|
registerSerializers();
|
||||||
}
|
}
|
||||||
|
|
||||||
FragmentStore::FragmentStore(
|
FragmentStore::FragmentStore(
|
||||||
std::array<uint8_t, 8> session_uuid_namespace
|
std::array<uint8_t, 16> session_uuid_namespace
|
||||||
) : _session_uuid_namespace(std::move(session_uuid_namespace)) {
|
) : _session_uuid_namespace(std::move(session_uuid_namespace)) {
|
||||||
registerSerializers();
|
registerSerializers();
|
||||||
}
|
}
|
||||||
@ -58,22 +69,34 @@ FragmentHandle FragmentStore::fragmentHandle(FragmentID fid) {
|
|||||||
return {_reg, fid};
|
return {_reg, fid};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint8_t> FragmentStore::generateNewUID(std::array<uint8_t, 8>& uuid_namespace) {
|
std::vector<uint8_t> FragmentStore::generateNewUID(std::array<uint8_t, 16>& uuid_namespace) {
|
||||||
std::vector<uint8_t> new_uid(uuid_namespace.cbegin(), uuid_namespace.cend());
|
std::vector<uint8_t> new_uid(uuid_namespace.cbegin(), uuid_namespace.cend());
|
||||||
new_uid.resize(new_uid.size() + 8);
|
new_uid.resize(new_uid.size() + 16);
|
||||||
|
|
||||||
const auto num0 = _rng();
|
const auto num0 = _rng();
|
||||||
const auto num1 = _rng();
|
const auto num1 = _rng();
|
||||||
|
const auto num2 = _rng();
|
||||||
|
const auto num3 = _rng();
|
||||||
|
|
||||||
new_uid[uuid_namespace.size()+0] = (num0 >> 0) & 0xff;
|
new_uid[uuid_namespace.size()+0] = (num0 >> 0) & 0xff;
|
||||||
new_uid[uuid_namespace.size()+1] = (num0 >> 8) & 0xff;
|
new_uid[uuid_namespace.size()+1] = (num0 >> 8) & 0xff;
|
||||||
new_uid[uuid_namespace.size()+2] = (num0 >> 16) & 0xff;
|
new_uid[uuid_namespace.size()+2] = (num0 >> 16) & 0xff;
|
||||||
new_uid[uuid_namespace.size()+3] = (num0 >> 24) & 0xff;
|
new_uid[uuid_namespace.size()+3] = (num0 >> 24) & 0xff;
|
||||||
|
|
||||||
new_uid[uuid_namespace.size()+4] = (num1 >> 0) & 0xff;
|
new_uid[uuid_namespace.size()+4+0] = (num1 >> 0) & 0xff;
|
||||||
new_uid[uuid_namespace.size()+5] = (num1 >> 8) & 0xff;
|
new_uid[uuid_namespace.size()+4+1] = (num1 >> 8) & 0xff;
|
||||||
new_uid[uuid_namespace.size()+6] = (num1 >> 16) & 0xff;
|
new_uid[uuid_namespace.size()+4+2] = (num1 >> 16) & 0xff;
|
||||||
new_uid[uuid_namespace.size()+7] = (num1 >> 24) & 0xff;
|
new_uid[uuid_namespace.size()+4+3] = (num1 >> 24) & 0xff;
|
||||||
|
|
||||||
|
new_uid[uuid_namespace.size()+8+0] = (num2 >> 0) & 0xff;
|
||||||
|
new_uid[uuid_namespace.size()+8+1] = (num2 >> 8) & 0xff;
|
||||||
|
new_uid[uuid_namespace.size()+8+2] = (num2 >> 16) & 0xff;
|
||||||
|
new_uid[uuid_namespace.size()+8+3] = (num2 >> 24) & 0xff;
|
||||||
|
|
||||||
|
new_uid[uuid_namespace.size()+12+0] = (num3 >> 0) & 0xff;
|
||||||
|
new_uid[uuid_namespace.size()+12+1] = (num3 >> 8) & 0xff;
|
||||||
|
new_uid[uuid_namespace.size()+12+2] = (num3 >> 16) & 0xff;
|
||||||
|
new_uid[uuid_namespace.size()+12+3] = (num3 >> 24) & 0xff;
|
||||||
|
|
||||||
return new_uid;
|
return new_uid;
|
||||||
}
|
}
|
||||||
@ -114,6 +137,8 @@ FragmentID FragmentStore::newFragmentMemoryOwned(
|
|||||||
// TODO: memory comp
|
// TODO: memory comp
|
||||||
_reg.emplace<std::unique_ptr<std::vector<uint8_t>>>(new_frag) = std::move(new_data);
|
_reg.emplace<std::unique_ptr<std::vector<uint8_t>>>(new_frag) = std::move(new_data);
|
||||||
|
|
||||||
|
throwEventConstruct(new_frag);
|
||||||
|
|
||||||
return new_frag;
|
return new_frag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,6 +184,8 @@ FragmentID FragmentStore::newFragmentFile(
|
|||||||
|
|
||||||
_reg.emplace<FragComp::Ephemeral::MetaFileType>(new_frag, mft);
|
_reg.emplace<FragComp::Ephemeral::MetaFileType>(new_frag, mft);
|
||||||
|
|
||||||
|
throwEventConstruct(new_frag);
|
||||||
|
|
||||||
// meta needs to be synced to file
|
// meta needs to be synced to file
|
||||||
std::function<write_to_storage_fetch_data_cb> empty_data_cb = [](const uint8_t*, uint64_t) -> uint64_t { return 0; };
|
std::function<write_to_storage_fetch_data_cb> empty_data_cb = [](const uint8_t*, uint64_t) -> uint64_t { return 0; };
|
||||||
if (!syncToStorage(new_frag, empty_data_cb)) {
|
if (!syncToStorage(new_frag, empty_data_cb)) {
|
||||||
@ -476,6 +503,7 @@ size_t FragmentStore::scanStoragePath(std::string_view path) {
|
|||||||
if (it.meta_ext == ".meta.msgpack") {
|
if (it.meta_ext == ".meta.msgpack") {
|
||||||
// uh
|
// uh
|
||||||
// read binary header
|
// read binary header
|
||||||
|
assert(false);
|
||||||
} else if (it.meta_ext == ".meta.json") {
|
} else if (it.meta_ext == ".meta.json") {
|
||||||
std::ifstream file(it.frag_path.generic_u8string() + it.meta_ext);
|
std::ifstream file(it.frag_path.generic_u8string() + it.meta_ext);
|
||||||
if (!file.is_open()) {
|
if (!file.is_open()) {
|
||||||
@ -506,6 +534,8 @@ size_t FragmentStore::scanStoragePath(std::string_view path) {
|
|||||||
std::cerr << "FS warning: missing deserializer for meta key '" << k << "'\n";
|
std::cerr << "FS warning: missing deserializer for meta key '" << k << "'\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// throw new frag event here
|
||||||
|
throwEventConstruct(fh);
|
||||||
count++;
|
count++;
|
||||||
} else {
|
} else {
|
||||||
assert(false);
|
assert(false);
|
||||||
@ -553,8 +583,6 @@ static bool deserl_json_data_comp_type(FragmentHandle fh, const nlohmann::json&
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: dserl comp type
|
|
||||||
|
|
||||||
void FragmentStore::registerSerializers(void) {
|
void FragmentStore::registerSerializers(void) {
|
||||||
_sc.registerSerializerJson<FragComp::DataEncryptionType>(serl_json_data_enc_type);
|
_sc.registerSerializerJson<FragComp::DataEncryptionType>(serl_json_data_enc_type);
|
||||||
_sc.registerDeSerializerJson<FragComp::DataEncryptionType>(deserl_json_data_enc_type);
|
_sc.registerDeSerializerJson<FragComp::DataEncryptionType>(deserl_json_data_enc_type);
|
||||||
|
@ -18,10 +18,8 @@
|
|||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
struct FragmentStore : public FragmentStoreI {
|
struct FragmentStore : public FragmentStoreI {
|
||||||
FragmentRegistry _reg;
|
|
||||||
|
|
||||||
std::minstd_rand _rng{std::random_device{}()};
|
std::minstd_rand _rng{std::random_device{}()};
|
||||||
std::array<uint8_t, 8> _session_uuid_namespace;
|
std::array<uint8_t, 16> _session_uuid_namespace;
|
||||||
|
|
||||||
std::string _default_store_path;
|
std::string _default_store_path;
|
||||||
|
|
||||||
@ -31,7 +29,7 @@ struct FragmentStore : public FragmentStoreI {
|
|||||||
SerializerCallbacks<FragmentID> _sc;
|
SerializerCallbacks<FragmentID> _sc;
|
||||||
|
|
||||||
FragmentStore(void);
|
FragmentStore(void);
|
||||||
FragmentStore(std::array<uint8_t, 8> session_uuid_namespace);
|
FragmentStore(std::array<uint8_t, 16> session_uuid_namespace);
|
||||||
|
|
||||||
// HACK: get access to the reg
|
// HACK: get access to the reg
|
||||||
FragmentHandle fragmentHandle(FragmentID fid);
|
FragmentHandle fragmentHandle(FragmentID fid);
|
||||||
@ -39,7 +37,7 @@ struct FragmentStore : public FragmentStoreI {
|
|||||||
// TODO: make the frags ref counted
|
// TODO: make the frags ref counted
|
||||||
|
|
||||||
// TODO: check for exising
|
// TODO: check for exising
|
||||||
std::vector<uint8_t> generateNewUID(std::array<uint8_t, 8>& uuid_namespace);
|
std::vector<uint8_t> generateNewUID(std::array<uint8_t, 16>& uuid_namespace);
|
||||||
std::vector<uint8_t> generateNewUID(void);
|
std::vector<uint8_t> generateNewUID(void);
|
||||||
|
|
||||||
// ========== new fragment ==========
|
// ========== new fragment ==========
|
||||||
|
23
src/fragment_store/fragment_store_i.cpp
Normal file
23
src/fragment_store/fragment_store_i.cpp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#include "./fragment_store_i.hpp"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
void FragmentStoreI::throwEventConstruct(const FragmentID fid) {
|
||||||
|
std::cout << "FSI debug: event construct " << entt::to_integral(fid) << "\n";
|
||||||
|
dispatch(
|
||||||
|
FragmentStore_Event::fragment_construct,
|
||||||
|
Fragment::Events::FragmentConstruct{
|
||||||
|
FragmentHandle{_reg, fid}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FragmentStoreI::throwEventUpdate(const FragmentID fid) {
|
||||||
|
std::cout << "FSI debug: event updated " << entt::to_integral(fid) << "\n";
|
||||||
|
dispatch(
|
||||||
|
FragmentStore_Event::fragment_updated,
|
||||||
|
Fragment::Events::FragmentUpdated{
|
||||||
|
FragmentHandle{_reg, fid}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
@ -1,6 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <solanaceae/util/event_provider.hpp>
|
||||||
|
|
||||||
#include <entt/entity/registry.hpp>
|
#include <entt/entity/registry.hpp>
|
||||||
|
#include <entt/entity/handle.hpp>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
@ -9,7 +12,52 @@ enum class FragmentID : uint32_t {};
|
|||||||
using FragmentRegistry = entt::basic_registry<FragmentID>;
|
using FragmentRegistry = entt::basic_registry<FragmentID>;
|
||||||
using FragmentHandle = entt::basic_handle<FragmentRegistry>;
|
using FragmentHandle = entt::basic_handle<FragmentRegistry>;
|
||||||
|
|
||||||
struct FragmentStoreI {
|
namespace Fragment::Events {
|
||||||
virtual ~FragmentStoreI(void) {}
|
|
||||||
|
struct FragmentConstruct {
|
||||||
|
const FragmentHandle e;
|
||||||
|
};
|
||||||
|
struct FragmentUpdated {
|
||||||
|
const FragmentHandle e;
|
||||||
|
};
|
||||||
|
//struct MessageDestory {
|
||||||
|
//const Message3Handle e;
|
||||||
|
//};
|
||||||
|
|
||||||
|
} // Fragment::Events
|
||||||
|
|
||||||
|
enum class FragmentStore_Event : uint32_t {
|
||||||
|
fragment_construct,
|
||||||
|
fragment_updated,
|
||||||
|
//message_destroy,
|
||||||
|
|
||||||
|
MAX
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FragmentStoreEventI {
|
||||||
|
using enumType = FragmentStore_Event;
|
||||||
|
|
||||||
|
virtual ~FragmentStoreEventI(void) {}
|
||||||
|
|
||||||
|
virtual bool onEvent(const Fragment::Events::FragmentConstruct&) { return false; }
|
||||||
|
virtual bool onEvent(const Fragment::Events::FragmentUpdated&) { return false; }
|
||||||
|
//virtual bool onEvent(const Fragment::Events::MessageDestory&) { return false; }
|
||||||
|
|
||||||
|
// mm3
|
||||||
|
// send text
|
||||||
|
// send file path
|
||||||
|
};
|
||||||
|
using FragmentStoreEventProviderI = EventProviderI<FragmentStoreEventI>;
|
||||||
|
|
||||||
|
struct FragmentStoreI : public FragmentStoreEventProviderI {
|
||||||
|
static constexpr const char* version {"1"};
|
||||||
|
|
||||||
|
FragmentRegistry _reg;
|
||||||
|
|
||||||
|
virtual ~FragmentStoreI(void) {}
|
||||||
|
|
||||||
|
void throwEventConstruct(const FragmentID fid);
|
||||||
|
void throwEventUpdate(const FragmentID fid);
|
||||||
|
//void throwEventDestroy();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -185,6 +185,10 @@ void MessageFragmentStore::handleMessage(const Message3Handle& m) {
|
|||||||
fuid_open.emplace_back(Message::Components::OpenFragments::OpenFrag{msg_ts, msg_ts, fragment_uid});
|
fuid_open.emplace_back(Message::Components::OpenFragments::OpenFrag{msg_ts, msg_ts, fragment_uid});
|
||||||
|
|
||||||
std::cout << "MFS: created new fragment " << bin2hex(fragment_uid) << "\n";
|
std::cout << "MFS: created new fragment " << bin2hex(fragment_uid) << "\n";
|
||||||
|
|
||||||
|
_fs_ignore_event = true;
|
||||||
|
_fs.throwEventConstruct(fh);
|
||||||
|
_fs_ignore_event = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if this is still empty, something is very wrong and we exit here
|
// if this is still empty, something is very wrong and we exit here
|
||||||
|
@ -47,6 +47,7 @@ class MessageFragmentStore : public RegistryMessageModelEventI {
|
|||||||
Contact3Registry& _cr;
|
Contact3Registry& _cr;
|
||||||
RegistryMessageModel& _rmm;
|
RegistryMessageModel& _rmm;
|
||||||
FragmentStore& _fs;
|
FragmentStore& _fs;
|
||||||
|
bool _fs_ignore_event {false};
|
||||||
|
|
||||||
// for message components only
|
// for message components only
|
||||||
MessageSerializerCallbacks _sc;
|
MessageSerializerCallbacks _sc;
|
||||||
|
Loading…
Reference in New Issue
Block a user