0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 10:08:56 +02:00

ircd:Ⓜ️ Add addl name:: keys; cleanup event related.

This commit is contained in:
Jason Volk 2018-01-20 05:48:39 -08:00
parent b05caee36f
commit 63ddbf8fbe
3 changed files with 47 additions and 118 deletions

View file

@ -27,24 +27,6 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsubobject-linkage"
///////////////////////////////////////////////////////////////////////////////
// Protocol notes
//
// 10.4
// The total size of any event MUST NOT exceed 65 KB.
//
// There are additional restrictions on sizes per key:
// sender MUST NOT exceed 255 bytes (including domain).
// room_id MUST NOT exceed 255 bytes.
// state_key MUST NOT exceed 255 bytes.
// type MUST NOT exceed 255 bytes.
// event_id MUST NOT exceed 255 bytes.
//
// Some event types have additional size restrictions which are specified in
// the description of the event. Additional keys have no limit other than that
// implied by the total 65 KB limit on events.
//
namespace ircd::m
{
struct event;
@ -53,10 +35,13 @@ namespace ircd::m
bool my(const event &);
size_t degree(const event &);
std::string pretty(const event &);
std::string pretty_oneline(const event &);
}
id::event event_id(const event &, id::event::buf &buf, const const_raw_buffer &hash);
id::event event_id(const event &, id::event::buf &buf);
id::event event_id(const event &);
}
/// The _Main Event_. Most fundamental primitive of the Matrix protocol.
@ -88,9 +73,6 @@ struct ircd::m::event
json::property<name::unsigned_, string_view>
>
{
enum lineage : int;
enum temporality : int;
struct fetch;
struct sync;
struct prev;
@ -103,10 +85,10 @@ struct ircd::m::event
static database *events;
using super_type::tuple;
event(const id &, const mutable_buffer &buf);
event(fetch &);
event() = default;
using super_type::operator=;
event(const id &, const mutable_buffer &buf);
event() = default;
};
namespace ircd::m
@ -117,12 +99,6 @@ namespace ircd::m
std::string pretty(const event::prev &);
std::string pretty_oneline(const event::prev &);
string_view reflect(const event::temporality &);
string_view reflect(const event::lineage &);
event::temporality temporality(const event &, const int64_t &rel);
event::lineage lineage(const event &);
}
struct ircd::m::event::prev
@ -139,28 +115,6 @@ struct ircd::m::event::prev
using super_type::operator=;
};
enum ircd::m::event::prev::cond
:int
{
SELF_LOOP,
};
enum ircd::m::event::temporality
:int
{
FUTURE = 1, ///< Event has a depth 1 or more into the future.
PRESENT = 0, ///< Event has a depth equal to the current depth.
PAST = -1, ///< Event has a depth less than the current depth.
};
enum ircd::m::event::lineage
:int
{
ROOT = 0, ///< Event has no parents (must be m.room.create then)
FORWARD = 1, ///< Event has one parent at the previous depth
MERGE = 2, ///< Event has multiple parents at the previous depth
};
inline bool
ircd::m::my(const event &event)
{

View file

@ -26,15 +26,20 @@ namespace ircd::m::name
constexpr const char *const hashes {"hashes"};
constexpr const char *const membership {"membership"};
constexpr const char *const method {"method"};
constexpr const char *const old_verify_keys {"old_verify_keys"};
constexpr const char *const origin {"origin"};
constexpr const char *const origin_server_ts {"origin_server_ts"};
constexpr const char *const prev_events {"prev_events"};
constexpr const char *const prev_state {"prev_state"};
constexpr const char *const room_id {"room_id"};
constexpr const char *const sender {"sender"};
constexpr const char *const server_name {"server_name"};
constexpr const char *const signatures {"signatures"};
constexpr const char *const state_key {"state_key"};
constexpr const char *const tls_fingerprints {"tls_fingerprints"};
constexpr const char *const type {"type"};
constexpr const char *const unsigned_ {"unsigned"};
constexpr const char *const uri {"uri"};
constexpr const char *const valid_until_ts {"valid_until_ts"};
constexpr const char *const verify_keys {"verify_keys"};
}

View file

@ -25,86 +25,39 @@ ircd::database *
ircd::m::event::events
{};
ircd::m::event::event(const id &id,
const mutable_buffer &buf)
ircd::m::id::event
ircd::m::event_id(const event &event,
id::event::buf &buf)
{
fetch tab
const json::strung preimage
{
id, buf
event
};
new (this) event{tab};
}
ircd::m::event::event(fetch &tab)
{
io::acquire(tab);
if(bool(tab.error))
std::rethrow_exception(tab.error);
new (this) super_type{tab.pdu};
}
ircd::m::event::temporality
ircd::m::temporality(const event &event,
const int64_t &rel)
{
const auto &depth
const fixed_buffer<const_raw_buffer, sha256::digest_size> hash
{
json::get<"depth"_>(event)
sha256{const_buffer{preimage}}
};
return depth > rel? event::temporality::FUTURE:
depth == rel? event::temporality::PRESENT:
event::temporality::PAST;
return event_id(event, buf, hash);
}
ircd::m::event::lineage
ircd::m::lineage(const event &event)
ircd::m::id::event
ircd::m::event_id(const event &event,
id::event::buf &buf,
const const_raw_buffer &hash)
{
const json::array prev[]
char readable[b58encode_size(sha256::digest_size)];
return id::event
{
json::get<"prev_events"_>(event),
json::get<"auth_events"_>(event),
json::get<"prev_state"_>(event),
buf, b58encode(readable, hash), my_host()
};
const auto count{std::accumulate(begin(prev), end(prev), size_t(0), []
(auto ret, const auto &array)
{
return ret += array.count();
})};
return count > 1? event::lineage::MERGE:
count == 1? event::lineage::FORWARD:
event::lineage::ROOT;
}
ircd::string_view
ircd::m::reflect(const event::lineage &lineage)
ircd::m::id::event
ircd::m::event_id(const event &event)
{
switch(lineage)
{
case event::lineage::MERGE: return "MERGE";
case event::lineage::FORWARD: return "FORWARD";
case event::lineage::ROOT: return "ROOT";
}
return "?????";
}
ircd::string_view
ircd::m::reflect(const event::temporality &temporality)
{
switch(temporality)
{
case event::temporality::FUTURE: return "FUTURE";
case event::temporality::PRESENT: return "PRESENT";
case event::temporality::PAST: return "PAST";
}
return "?????";
return at<"event_id"_>(event);
}
size_t
@ -369,3 +322,20 @@ ircd::m::pretty_oneline(const event &event)
resizebuf(s, ret);
return ret;
}
//
// event
//
ircd::m::event::event(const id &id,
const mutable_buffer &buf)
{
/*
fetch tab
{
id, buf
};
new (this) event{tab};
*/
}