0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 10:12:39 +01:00

ircd:Ⓜ️:room::auth: Add central interface for chain fetch/eval.

This commit is contained in:
Jason Volk 2019-03-27 13:44:33 -07:00
parent b73bb789b2
commit 1c5b7d2d71
3 changed files with 67 additions and 49 deletions

View file

@ -22,6 +22,10 @@ struct ircd::m::room::auth
static bool for_each(const auth &, const closure_bool &); static bool for_each(const auth &, const closure_bool &);
static void make_refs(const auth &, json::stack::array &, const types &, const m::id::user & = {}); static void make_refs(const auth &, json::stack::array &, const types &, const m::id::user & = {});
using fetch_closure = std::function<bool (const json::object &)>;
static bool chain_fetch(const auth &, const net::hostport &, const fetch_closure &);
static void chain_eval(const auth &, const net::hostport &);
m::room room; m::room room;
public: public:

View file

@ -2259,6 +2259,35 @@ ircd::m::room::head::reset(const head &h)
// room::auth // room::auth
// //
void
ircd::m::room::auth::chain_eval(const auth &a,
const net::hostport &h)
{
using prototype = bool (const auth &, const net::hostport &);
static mods::import<prototype> call
{
"s_fetch", "ircd::m::room::auth::chain_eval"
};
call(a, h);
}
bool
ircd::m::room::auth::chain_fetch(const auth &a,
const net::hostport &h,
const fetch_closure &c)
{
using prototype = bool (const auth &, const net::hostport &, const fetch_closure &);
static mods::import<prototype> call
{
"s_fetch", "ircd::m::room::auth::chain_fetch"
};
return call(a, h, c);
}
ircd::json::array ircd::json::array
ircd::m::room::auth::make_refs(const mutable_buffer &buf, ircd::m::room::auth::make_refs(const mutable_buffer &buf,
const types &types, const types &types,

View file

@ -106,30 +106,38 @@ ircd::m::fetch::hook_handler(const event &event,
} }
// //
// util // auth chain fetch
// //
namespace ircd::m::fetch void
IRCD_MODULE_EXPORT
ircd::m::room::auth::chain_eval(const auth &auth,
const net::hostport &remote)
{ {
extern "C" void m::vm::opts opts;
auth_chain_fetch(const m::room::id &room_id, opts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
const m::event::id &event_id, opts.infolog_accept = true;
const net::hostport &remote, opts.warnlog |= m::vm::fault::STATE;
const milliseconds &timeout, opts.warnlog &= ~m::vm::fault::EXISTS;
const std::function<bool (const m::event &)> &); opts.errorlog &= ~m::vm::fault::STATE;
extern "C" void chain_fetch(auth, remote, [&opts]
auth_chain_eval(const m::room::id &room_id, (const json::object &event)
const m::event::id &event_id, {
const net::hostport &remote); m::vm::eval
{
m::event{event}, opts
};
return true;
});
} }
extern "C" void bool
ircd::m::fetch::auth_chain_fetch(const m::room::id &room_id, IRCD_MODULE_EXPORT
const m::event::id &event_id, ircd::m::room::auth::chain_fetch(const auth &auth,
const net::hostport &remote, const net::hostport &remote,
const milliseconds &timeout, const fetch_closure &closure)
const std::function<bool (const m::event &)> &closure)
{ {
m::v1::event_auth::opts opts; m::v1::event_auth::opts opts;
opts.remote = remote; opts.remote = remote;
@ -141,52 +149,29 @@ ircd::m::fetch::auth_chain_fetch(const m::room::id &room_id,
m::v1::event_auth request m::v1::event_auth request
{ {
room_id, event_id, buf, std::move(opts) auth.room.room_id, auth.room.event_id, buf, std::move(opts)
}; };
request.wait(timeout); request.wait(seconds(20)); //TODO: conf
request.get(); request.get();
const json::array &auth_chain const json::array &auth_chain
{ {
request request
}; };
std::vector<m::event> events{auth_chain.count()}; std::vector<json::object> events(auth_chain.count());
std::transform(begin(auth_chain), end(auth_chain), begin(events), [] std::copy(begin(auth_chain), end(auth_chain), begin(events));
(const json::object &pdu) std::sort(begin(events), end(events), []
(const json::object &a, const json::object &b)
{ {
return m::event{pdu}; return a.at<uint64_t>("depth") < b.at<uint64_t>("depth");
}); });
std::sort(begin(events), end(events));
for(const auto &event : events) for(const auto &event : events)
if(!closure(event)) if(!closure(event))
return; return false;
}
extern "C" void
ircd::m::fetch::auth_chain_eval(const m::room::id &room_id,
const m::event::id &event_id,
const net::hostport &remote)
{
m::vm::opts opts;
opts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
opts.infolog_accept = true;
opts.warnlog |= m::vm::fault::STATE;
opts.warnlog &= ~m::vm::fault::EXISTS;
opts.errorlog &= ~m::vm::fault::STATE;
auth_chain_fetch(room_id, event_id, remote, seconds(30), [&opts]
(const auto &event)
{
m::vm::eval
{
event, opts
};
return true; return true;
});
} }
// //