mirror of
https://github.com/matrix-construct/construct
synced 2024-12-01 19:22:53 +01:00
ircd:Ⓜ️:event::conforms: Add checks for duplicate / self / missing auth refs.
This commit is contained in:
parent
20eb440408
commit
1bd9ce0d1e
2 changed files with 25 additions and 0 deletions
|
@ -64,6 +64,7 @@ enum ircd::m::event::conforms::code
|
||||||
INVALID_CONTENT_MEMBERSHIP, ///< for m.room.member, content.membership
|
INVALID_CONTENT_MEMBERSHIP, ///< for m.room.member, content.membership
|
||||||
MISSING_PREV_EVENTS, ///< for non-m.room.create, empty prev_events
|
MISSING_PREV_EVENTS, ///< for non-m.room.create, empty prev_events
|
||||||
MISSING_PREV_STATE, ///< for state_key'ed, empty prev_state
|
MISSING_PREV_STATE, ///< for state_key'ed, empty prev_state
|
||||||
|
MISSING_AUTH_EVENTS, ///< for non-m.room.create, empty auth_events
|
||||||
DEPTH_NEGATIVE, ///< depth < 0
|
DEPTH_NEGATIVE, ///< depth < 0
|
||||||
DEPTH_ZERO, ///< for non-m.room.create, depth=0
|
DEPTH_ZERO, ///< for non-m.room.create, depth=0
|
||||||
MISSING_SIGNATURES, ///< no signatures
|
MISSING_SIGNATURES, ///< no signatures
|
||||||
|
@ -73,8 +74,10 @@ enum ircd::m::event::conforms::code
|
||||||
SELF_REDACTS, ///< event redacts itself
|
SELF_REDACTS, ///< event redacts itself
|
||||||
SELF_PREV_EVENT, ///< event_id self-referenced in prev_events
|
SELF_PREV_EVENT, ///< event_id self-referenced in prev_events
|
||||||
SELF_PREV_STATE, ///< event_id self-referenced in prev_state
|
SELF_PREV_STATE, ///< event_id self-referenced in prev_state
|
||||||
|
SELF_AUTH_EVENT, ///< event_id self-referenced in auth_events
|
||||||
DUP_PREV_EVENT, ///< duplicate references in prev_events
|
DUP_PREV_EVENT, ///< duplicate references in prev_events
|
||||||
DUP_PREV_STATE, ///< duplicate references in prev_state
|
DUP_PREV_STATE, ///< duplicate references in prev_state
|
||||||
|
DUP_AUTH_EVENT, ///< duplicate references in auth_events
|
||||||
|
|
||||||
_NUM_
|
_NUM_
|
||||||
};
|
};
|
||||||
|
|
|
@ -168,6 +168,7 @@ ircd::m::event_conforms_reflects
|
||||||
"INVALID_CONTENT_MEMBERSHIP",
|
"INVALID_CONTENT_MEMBERSHIP",
|
||||||
"MISSING_PREV_EVENTS",
|
"MISSING_PREV_EVENTS",
|
||||||
"MISSING_PREV_STATE",
|
"MISSING_PREV_STATE",
|
||||||
|
"MISSING_AUTH_EVENTS",
|
||||||
"DEPTH_NEGATIVE",
|
"DEPTH_NEGATIVE",
|
||||||
"DEPTH_ZERO",
|
"DEPTH_ZERO",
|
||||||
"MISSING_SIGNATURES",
|
"MISSING_SIGNATURES",
|
||||||
|
@ -177,8 +178,10 @@ ircd::m::event_conforms_reflects
|
||||||
"SELF_REDACTS",
|
"SELF_REDACTS",
|
||||||
"SELF_PREV_EVENT",
|
"SELF_PREV_EVENT",
|
||||||
"SELF_PREV_STATE",
|
"SELF_PREV_STATE",
|
||||||
|
"SELF_AUTH_EVENT",
|
||||||
"DUP_PREV_EVENT",
|
"DUP_PREV_EVENT",
|
||||||
"DUP_PREV_STATE",
|
"DUP_PREV_STATE",
|
||||||
|
"DUP_AUTH_EVENT",
|
||||||
};
|
};
|
||||||
|
|
||||||
std::ostream &
|
std::ostream &
|
||||||
|
@ -287,6 +290,10 @@ ircd::m::event::conforms::conforms(const event &e)
|
||||||
set(MISSING_PREV_STATE);
|
set(MISSING_PREV_STATE);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if(json::get<"type"_>(e) != "m.room.create")
|
||||||
|
if(empty(json::get<"auth_events"_>(e)))
|
||||||
|
set(MISSING_AUTH_EVENTS);
|
||||||
|
|
||||||
if(json::get<"depth"_>(e) != json::undefined_number && json::get<"depth"_>(e) < 0)
|
if(json::get<"depth"_>(e) != json::undefined_number && json::get<"depth"_>(e) < 0)
|
||||||
set(DEPTH_NEGATIVE);
|
set(DEPTH_NEGATIVE);
|
||||||
|
|
||||||
|
@ -324,6 +331,21 @@ ircd::m::event::conforms::conforms(const event &e)
|
||||||
|
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
for(const json::array &ps : json::get<"auth_events"_>(p))
|
||||||
|
{
|
||||||
|
if(unquote(ps.at(0)) == json::get<"event_id"_>(e))
|
||||||
|
set(SELF_AUTH_EVENT);
|
||||||
|
|
||||||
|
j = 0;
|
||||||
|
for(const json::array &ps_ : json::get<"auth_events"_>(p))
|
||||||
|
if(i != j++)
|
||||||
|
if(ps_.at(0) == ps.at(0))
|
||||||
|
set(DUP_AUTH_EVENT);
|
||||||
|
|
||||||
|
++i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in a new issue