0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-26 00:32:35 +01:00

modules/s_fetch: Improve recursive eval.

This commit is contained in:
Jason Volk 2019-04-26 03:41:11 -07:00
parent e7251730a3
commit 564a64e5d6
2 changed files with 16 additions and 7 deletions

View file

@ -245,6 +245,8 @@ bootstrap(const string_view &host,
m::vm::copts opts;
opts.infolog_accept = true;
opts.fetch_prev_check = false;
opts.fetch_state_check = false;
const m::event::id::buf event_id
{
m::vm::eval

View file

@ -298,9 +298,9 @@ ircd::m::fetch::auth_chain(const room &room,
};
m::vm::opts vmopts;
vmopts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
vmopts.infolog_accept = true;
vmopts.fetch = false;
vmopts.fetch_prev_check = false;
vmopts.fetch_state_check = false;
for(const auto &event : events)
m::vm::eval
{
@ -382,9 +382,6 @@ try
if(type == "m.room.create")
return;
if(eval.copts && my(event))
return;
const m::event::id &event_id
{
at<"event_id"_>(event)
@ -409,6 +406,7 @@ try
};
size_t auth_exists(0);
m::event::id::buf auth_id_missing;
if(opts.fetch_auth_check) for(size_t i(0); i < auth_count; ++i)
{
const auto &auth_id
@ -418,18 +416,25 @@ try
if(m::exists(auth_id))
++auth_exists;
else if(!auth_id_missing)
auth_id_missing = auth_id;
}
if(opts.fetch_auth_check && auth_exists < auth_count)
{
assert(bool(auth_id_missing));
const net::hostport remote
{
eval.opts->node_id?
eval.opts->node_id:
json::get<"origin"_>(event)
!my_host(json::get<"origin"_>(event))?
string_view(json::get<"origin"_>(event)):
!my_host(auth_id_missing.host())?
auth_id_missing.host():
string_view{}
};
if(!opts.fetch_auth || !bool(m::fetch::enable) || !remote || my_host(host(remote)))
if(!opts.fetch_auth || !bool(m::fetch::enable) || !remote)
throw vm::error
{
vm::fault::EVENT, "Failed to fetch auth_events for %s in %s",
@ -437,7 +442,9 @@ try
json::get<"room_id"_>(*eval.event_)
};
const scope_restore auth_id{room.event_id, auth_id_missing};
auth_chain(room, remote);
auth_exists = auth_count;
}
const size_t prev_count