0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-07 04:28:59 +02:00

ircd:Ⓜ️ Add additional event::conforms checks; comments.

This commit is contained in:
Jason Volk 2018-03-09 07:11:00 -08:00
parent 9fa98055ff
commit 1cfe841462
2 changed files with 35 additions and 0 deletions

View file

@ -147,6 +147,15 @@ struct ircd::m::event::fetch
friend void seek(fetch &, const event::id &);
};
/// Device to evaluate the conformity of an event object. This is an 'in vitro'
/// or 'pure' evaluation: it determines if the event is reasonably sane enough
/// to be evaluated further using only the information in the event itself. It
/// requires nothing external and conducts no IO etc..
///
/// This evaluation does not throw or stop when a check fails: instead it
/// collects the failures allowing the user to further determine how to proceed
/// at their own discretion.
///
struct ircd::m::event::conforms
{
enum code :uint;
@ -173,6 +182,10 @@ struct ircd::m::event::conforms
friend std::ostream &operator<<(std::ostream &, const conforms &);
};
/// Report codes corresponding to the checks conducted by event::conforms.
/// Developers: If you add a code here you must also add a string reflection
/// in the definition file.
///
enum ircd::m::event::conforms::code
:uint
{
@ -191,6 +204,10 @@ enum ircd::m::event::conforms::code
MISSING_PREV_STATE, ///< for state_key'ed, empty prev_state
DEPTH_NEGATIVE, ///< depth < 0
DEPTH_ZERO, ///< for non-m.room.create, depth=0
MISSING_SIGNATURES, ///< no signatures
MISSING_ORIGIN_SIGNATURE, ///< no signature for origin
MISMATCH_ORIGIN_SENDER, ///< sender mxid host not from origin
MISMATCH_ORIGIN_EVENT_ID, ///< event_id mxid host not from origin
_NUM_
};

View file

@ -788,6 +788,10 @@ ircd::m::event_conforms_reflects
"MISSING_PREV_STATE",
"DEPTH_NEGATIVE",
"DEPTH_ZERO",
"MISSING_SIGNATURES",
"MISSING_ORIGIN_SIGNATURE",
"MISMATCH_ORIGIN_SENDER",
"MISMATCH_ORIGIN_EVENT_ID",
};
std::ostream &
@ -855,6 +859,20 @@ ircd::m::event::conforms::conforms(const event &e)
if(false)
set(INVALID_ORIGIN);
if(empty(json::get<"signatures"_>(e)))
set(MISSING_SIGNATURES);
if(empty(json::object{json::get<"signatures"_>(e).get(json::get<"origin"_>(e))}))
set(MISSING_ORIGIN_SIGNATURE);
if(!has(INVALID_OR_MISSING_SENDER_ID))
if(json::get<"origin"_>(e) != m::id::user{json::get<"sender"_>(e)}.host())
set(MISMATCH_ORIGIN_SENDER);
if(!has(INVALID_OR_MISSING_EVENT_ID))
if(json::get<"origin"_>(e) != m::id::event{json::get<"event_id"_>(e)}.host())
set(MISMATCH_ORIGIN_EVENT_ID);
if(json::get<"type"_>(e) == "m.room.redaction")
if(!valid(m::id::EVENT, json::get<"redacts"_>(e)))
set(INVALID_OR_MISSING_REDACTS_ID);