mirror of
https://github.com/matrix-construct/construct
synced 2025-02-18 01:30:12 +01:00
ircd:Ⓜ️:fetch: Move auth_chain() to vm::fetch module.
This commit is contained in:
parent
c53a1fa12b
commit
1323b30f34
3 changed files with 80 additions and 85 deletions
|
@ -27,9 +27,6 @@ namespace ircd::m::fetch
|
|||
|
||||
// Primary operations
|
||||
ctx::future<result> start(const m::room::id &, const m::event::id &);
|
||||
|
||||
// Composed operations
|
||||
void auth_chain(const room &, const net::hostport &);
|
||||
}
|
||||
|
||||
struct ircd::m::fetch::result
|
||||
|
|
|
@ -20,7 +20,6 @@ namespace ircd::m::fetch
|
|||
extern std::multimap<room::id, request *> rooms;
|
||||
extern ctx::context request_context;
|
||||
extern conf::item<size_t> requests_max;
|
||||
extern conf::item<seconds> auth_timeout;
|
||||
extern conf::item<seconds> timeout;
|
||||
extern conf::item<bool> enable;
|
||||
extern log::log log;
|
||||
|
@ -77,13 +76,6 @@ ircd::m::fetch::timeout
|
|||
{ "default", 5L },
|
||||
};
|
||||
|
||||
decltype(ircd::m::fetch::auth_timeout)
|
||||
ircd::m::fetch::auth_timeout
|
||||
{
|
||||
{ "name", "ircd.m.fetch.auth.timeout" },
|
||||
{ "default", 15L },
|
||||
};
|
||||
|
||||
decltype(ircd::m::fetch::requests_max)
|
||||
ircd::m::fetch::requests_max
|
||||
{
|
||||
|
@ -128,80 +120,10 @@ ircd::m::fetch::fini()
|
|||
assert(requests.empty());
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// m/fetch.h
|
||||
// <ircd/m/fetch.h>
|
||||
//
|
||||
|
||||
void
|
||||
IRCD_MODULE_EXPORT
|
||||
ircd::m::fetch::auth_chain(const room &room,
|
||||
const net::hostport &remote)
|
||||
try
|
||||
{
|
||||
thread_local char rembuf[64];
|
||||
log::debug
|
||||
{
|
||||
log, "Fetching auth chain for %s in %s from %s",
|
||||
string_view{room.event_id},
|
||||
string_view{room.room_id},
|
||||
string(rembuf, remote),
|
||||
};
|
||||
|
||||
m::v1::event_auth::opts opts;
|
||||
opts.remote = remote;
|
||||
opts.dynamic = true;
|
||||
const unique_buffer<mutable_buffer> buf
|
||||
{
|
||||
16_KiB
|
||||
};
|
||||
|
||||
m::v1::event_auth request
|
||||
{
|
||||
room.room_id, room.event_id, buf, std::move(opts)
|
||||
};
|
||||
|
||||
request.wait(seconds(auth_timeout));
|
||||
request.get();
|
||||
const json::array events
|
||||
{
|
||||
request
|
||||
};
|
||||
|
||||
log::debug
|
||||
{
|
||||
log, "Evaluating %zu auth events in chain for %s in %s from %s",
|
||||
events.size(),
|
||||
string_view{room.event_id},
|
||||
string_view{room.room_id},
|
||||
string(rembuf, remote),
|
||||
};
|
||||
|
||||
m::vm::opts vmopts;
|
||||
vmopts.infolog_accept = true;
|
||||
vmopts.fetch_prev_check = false;
|
||||
vmopts.fetch_state_check = false;
|
||||
vmopts.warnlog &= ~vm::fault::EXISTS;
|
||||
m::vm::eval
|
||||
{
|
||||
events, vmopts
|
||||
};
|
||||
}
|
||||
catch(const std::exception &e)
|
||||
{
|
||||
thread_local char rembuf[64];
|
||||
log::error
|
||||
{
|
||||
log, "Fetching auth chain for %s in %s from %s :%s",
|
||||
string_view{room.event_id},
|
||||
string_view{room.room_id},
|
||||
string(rembuf, remote),
|
||||
e.what(),
|
||||
};
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
ircd::ctx::future<ircd::m::fetch::result>
|
||||
IRCD_MODULE_EXPORT
|
||||
ircd::m::fetch::start(const m::room::id &room_id,
|
||||
|
@ -255,9 +177,8 @@ ircd::m::fetch::for_each(const std::function<bool (request &)> &closure)
|
|||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// s_fetch.h
|
||||
// internal
|
||||
//
|
||||
|
||||
template<class... args>
|
||||
|
|
|
@ -13,9 +13,11 @@ namespace ircd::m::vm::fetch
|
|||
struct evaltab;
|
||||
|
||||
static void hook_handle_prev(const event &, vm::eval &, evaltab &, const room &);
|
||||
static void auth_chain(const room &, const net::hostport &);
|
||||
static void hook_handle_auth(const event &, vm::eval &, evaltab &, const room &);
|
||||
static void hook_handle(const event &, vm::eval &);
|
||||
|
||||
extern conf::item<seconds> auth_timeout;
|
||||
extern conf::item<bool> enable;
|
||||
extern hookfn<vm::eval &> hook;
|
||||
extern log::log log;
|
||||
|
@ -50,6 +52,13 @@ ircd::m::vm::fetch::enable
|
|||
{ "default", true },
|
||||
};
|
||||
|
||||
decltype(ircd::m::vm::fetch::auth_timeout)
|
||||
ircd::m::vm::fetch::auth_timeout
|
||||
{
|
||||
{ "name", "ircd.m.vm.fetch.auth.timeout" },
|
||||
{ "default", 15L },
|
||||
};
|
||||
|
||||
decltype(ircd::m::vm::fetch::hook)
|
||||
ircd::m::vm::fetch::hook
|
||||
{
|
||||
|
@ -190,10 +199,78 @@ ircd::m::vm::fetch::hook_handle_auth(const event &event,
|
|||
// This is a blocking call to recursively fetch and evaluate the auth_chain
|
||||
// for this event. Upon return all of the auth_events for this event will
|
||||
// have themselves been fetched and auth'ed recursively or throws.
|
||||
m::fetch::auth_chain(room, remote);
|
||||
auth_chain(room, remote);
|
||||
tab.auth_exists = tab.auth_count;
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::vm::fetch::auth_chain(const room &room,
|
||||
const net::hostport &remote)
|
||||
try
|
||||
{
|
||||
thread_local char rembuf[64];
|
||||
log::debug
|
||||
{
|
||||
log, "Fetching auth chain for %s in %s from %s",
|
||||
string_view{room.event_id},
|
||||
string_view{room.room_id},
|
||||
string(rembuf, remote),
|
||||
};
|
||||
|
||||
m::v1::event_auth::opts opts;
|
||||
opts.remote = remote;
|
||||
opts.dynamic = true;
|
||||
const unique_buffer<mutable_buffer> buf
|
||||
{
|
||||
16_KiB
|
||||
};
|
||||
|
||||
m::v1::event_auth request
|
||||
{
|
||||
room.room_id, room.event_id, buf, std::move(opts)
|
||||
};
|
||||
|
||||
request.wait(seconds(auth_timeout));
|
||||
request.get();
|
||||
const json::array events
|
||||
{
|
||||
request
|
||||
};
|
||||
|
||||
log::debug
|
||||
{
|
||||
log, "Evaluating %zu auth events in chain for %s in %s from %s",
|
||||
events.size(),
|
||||
string_view{room.event_id},
|
||||
string_view{room.room_id},
|
||||
string(rembuf, remote),
|
||||
};
|
||||
|
||||
m::vm::opts vmopts;
|
||||
vmopts.infolog_accept = true;
|
||||
vmopts.fetch_prev_check = false;
|
||||
vmopts.fetch_state_check = false;
|
||||
vmopts.warnlog &= ~vm::fault::EXISTS;
|
||||
m::vm::eval
|
||||
{
|
||||
events, vmopts
|
||||
};
|
||||
}
|
||||
catch(const std::exception &e)
|
||||
{
|
||||
thread_local char rembuf[64];
|
||||
log::error
|
||||
{
|
||||
log, "Fetching auth chain for %s in %s from %s :%s",
|
||||
string_view{room.event_id},
|
||||
string_view{room.room_id},
|
||||
string(rembuf, remote),
|
||||
e.what(),
|
||||
};
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::vm::fetch::hook_handle_prev(const event &event,
|
||||
vm::eval &eval,
|
||||
|
|
Loading…
Add table
Reference in a new issue