mirror of
https://github.com/matrix-construct/construct
synced 2024-09-26 18:38:52 +02:00
ircd:Ⓜ️ Add a check_id(event) suite.
This commit is contained in:
parent
90bf8f03b8
commit
639b132250
2 changed files with 54 additions and 0 deletions
|
@ -40,6 +40,8 @@ namespace ircd::m
|
|||
// Topological comparison
|
||||
bool before(const event &a, const event &b);
|
||||
|
||||
bool check_id(const event &) noexcept;
|
||||
bool check_id(const event &, const string_view &room_version) noexcept;
|
||||
id::event make_id(const event &, id::event::buf &buf, const const_buffer &hash);
|
||||
id::event make_id(const event &, id::event::buf &buf);
|
||||
|
||||
|
|
|
@ -3711,6 +3711,58 @@ ircd::m::make_id(const event &event,
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::check_id(const event &event)
|
||||
noexcept
|
||||
{
|
||||
if(!event.event_id)
|
||||
return false;
|
||||
|
||||
const string_view &version
|
||||
{
|
||||
event.event_id.version()
|
||||
};
|
||||
|
||||
return check_id(event, version);
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::check_id(const event &event,
|
||||
const string_view &room_version)
|
||||
noexcept try
|
||||
{
|
||||
const auto &version
|
||||
{
|
||||
room_version?: json::get<"event_id"_>(event)? "1": "4"
|
||||
};
|
||||
|
||||
thread_local char buf[64];
|
||||
m::event::id check_id; switch(hash(version))
|
||||
{
|
||||
case "1"_:
|
||||
case "2"_:
|
||||
check_id = m::event::id{json::get<"event_id"_>(event)};
|
||||
break;
|
||||
|
||||
case "3"_:
|
||||
check_id = m::event::id::v3{buf, event};
|
||||
break;
|
||||
|
||||
case "4"_:
|
||||
case "5"_:
|
||||
default:
|
||||
check_id = m::event::id::v4{buf, event};
|
||||
break;
|
||||
}
|
||||
|
||||
return event.event_id == check_id;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::before(const event &a,
|
||||
const event &b)
|
||||
|
|
Loading…
Reference in a new issue