0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-28 16:34:13 +01:00

ircd:Ⓜ️:event: Add event::auth examination device.

This commit is contained in:
Jason Volk 2019-02-08 02:50:10 -08:00
parent 2a431fa26a
commit ef740d339b
3 changed files with 91 additions and 0 deletions

View file

@ -15,3 +15,25 @@ namespace ircd::m
{
bool is_power_event(const event &);
}
struct ircd::m::event::auth
{
using closure_bool = event::closure_idx_bool;
event::idx idx;
public:
bool for_each(const closure_bool &) const;
bool has(const event::idx &) const noexcept;
size_t count() const noexcept;
auth(const event::idx &idx) noexcept;
};
inline
ircd::m::event::auth::auth(const event::idx &idx)
noexcept
:idx{idx}
{
assert(idx);
}

View file

@ -79,6 +79,7 @@ struct ircd::m::event
{
struct prev;
struct refs;
struct auth;
struct fetch;
struct conforms;

View file

@ -1125,6 +1125,74 @@ ircd::m::is_power_event(const m::event &event)
return false;
}
//
// event::auth
//
size_t
ircd::m::event::auth::count()
const noexcept
{
assert(idx);
size_t ret(0);
for_each([&ret](const auto &)
{
++ret;
return true;
});
return ret;
}
bool
ircd::m::event::auth::has(const event::idx &idx)
const noexcept
{
return !for_each([&idx](const event::idx &ref)
{
return ref != idx; // true to continue, false to break
});
}
bool
ircd::m::event::auth::for_each(const closure_bool &closure)
const
{
auto &column
{
dbs::event_auth
};
const byte_view<string_view> &key
{
idx
};
auto it
{
column.begin(key)
};
for(; it; ++it)
{
const auto parts
{
dbs::event_auth_key(it->first)
};
const auto &ref
{
std::get<0>(parts)
};
assert(idx != ref);
if(!closure(ref))
return false;
}
return true;
}
///////////////////////////////////////////////////////////////////////////////
//
// event/refs.h