diff --git a/include/ircd/m/event/auth.h b/include/ircd/m/event/auth.h index f23c9b76c..f8d322a05 100644 --- a/include/ircd/m/event/auth.h +++ b/include/ircd/m/event/auth.h @@ -51,7 +51,8 @@ struct ircd::m::event::auth::refs struct ircd::m::event::auth::chain { - using closure_bool = std::function; + using closure_bool = event::closure_idx_bool; + using closure = event::closure_idx; event::idx idx; @@ -59,6 +60,8 @@ struct ircd::m::event::auth::chain public: bool for_each(const closure_bool &) const; + bool for_each(const closure &) const; + bool has(const string_view &type) const noexcept; size_t depth() const noexcept; diff --git a/ircd/m_event.cc b/ircd/m_event.cc index 7a20b9560..6e80762dc 100644 --- a/ircd/m_event.cc +++ b/ircd/m_event.cc @@ -1433,10 +1433,9 @@ ircd::m::event::auth::chain::depth() const noexcept { size_t ret(0); - for_each([&ret](const auto &, const auto &) + for_each([&ret](const auto &) { ++ret; - return true; }); return ret; @@ -1447,16 +1446,33 @@ ircd::m::event::auth::chain::has(const string_view &type) const noexcept { bool ret(false); - for_each([&type, &ret] - (const auto &, const auto &event) + for_each(closure_bool{[&type, &ret] + (const auto &idx) { - ret = type == json::get<"type"_>(event); + m::get(std::nothrow, idx, "type", [&type, &ret] + (const auto &value) + { + ret = value == type; + }); + return !ret; - }); + }}); return ret; } +bool +ircd::m::event::auth::chain::for_each(const closure &closure) +const +{ + return for_each(closure_bool{[&closure] + (const auto &idx) + { + closure(idx); + return true; + }}); +} + bool ircd::m::event::auth::chain::for_each(const closure_bool &closure) const diff --git a/modules/console.cc b/modules/console.cc index f6091acec..c73c92551 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -5939,13 +5939,18 @@ console_cmd__event__auth(opt &out, const string_view &line) m::index(event_id) }; - ac.for_each([&out](const auto &idx, const auto &event) + ac.for_each([&out](const auto &idx) { - out << idx - << " " << pretty_oneline(event) - << std::endl; + const m::event::fetch event + { + idx, std::nothrow + }; - return true; + out << idx; + if(event.valid) + out << " " << pretty_oneline(event); + + out << std::endl; }); return true; diff --git a/modules/federation/event_auth.cc b/modules/federation/event_auth.cc index d3d880895..a83a037b9 100644 --- a/modules/federation/event_auth.cc +++ b/modules/federation/event_auth.cc @@ -96,11 +96,12 @@ get__event_auth(client &client, m::index(event_id) }; - chain.for_each([&auth_chain] - (const m::event::idx &event_idx, const m::event &event) + m::event::fetch event; + chain.for_each([&auth_chain, &event] + (const m::event::idx &event_idx) { - auth_chain.append(event); - return true; + if(seek(event, event_idx, std::nothrow)) + auth_chain.append(event); }); return {}; diff --git a/modules/m_event.cc b/modules/m_event.cc index 8207d56b3..9b37ba81d 100644 --- a/modules/m_event.cc +++ b/modules/m_event.cc @@ -598,13 +598,8 @@ ircd::m::event::auth::chain::for_each(const auth::chain &c, while(!aq.empty()); for(const auto &idx : ae) - { - if(!seek(e, idx, std::nothrow)) - continue; - - if(!closure(idx, e)) + if(!closure(idx)) return false; - } return true; }