mirror of
https://github.com/matrix-construct/construct
synced 2024-12-25 23:14:13 +01:00
ircd:Ⓜ️:feds: Add feds::auth; update console cmd.
This commit is contained in:
parent
871fb748eb
commit
59982907d3
4 changed files with 60 additions and 32 deletions
|
@ -31,6 +31,7 @@ namespace ircd::m::feds
|
|||
using closure = std::function<bool (const result &)>;
|
||||
|
||||
bool head(const opts &, const closure &);
|
||||
bool auth(const opts &, const closure &);
|
||||
bool event(const opts &, const closure &);
|
||||
bool state(const opts &, const closure &);
|
||||
bool backfill(const opts &, const closure &);
|
||||
|
|
14
ircd/m.cc
14
ircd/m.cc
|
@ -1245,6 +1245,20 @@ ircd::m::feds::event(const opts &o,
|
|||
return call(o, c);
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::feds::auth(const opts &o,
|
||||
const closure &c)
|
||||
{
|
||||
using prototype = bool (const opts &, const closure &);
|
||||
|
||||
static mods::import<prototype> call
|
||||
{
|
||||
"federation_federation", "ircd::m::feds::auth"
|
||||
};
|
||||
|
||||
return call(o, c);
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::feds::head(const opts &o,
|
||||
const closure &c)
|
||||
|
|
|
@ -10358,58 +10358,42 @@ console_cmd__feds__head(opt &out, const string_view &line)
|
|||
}
|
||||
|
||||
bool
|
||||
console_cmd__feds__auth(opt &out, const string_view &line)
|
||||
console_cmd__feds__event_auth(opt &out, const string_view &line)
|
||||
{
|
||||
const params param{line, " ",
|
||||
{
|
||||
"room_id", "[user_id]"
|
||||
"room_id", "event_id"
|
||||
}};
|
||||
|
||||
const auto &room_id
|
||||
{
|
||||
m::room_id(param.at(0))
|
||||
m::room_id(param.at("room_id"))
|
||||
};
|
||||
|
||||
const m::user::id &user_id
|
||||
const m::event::id &event_id
|
||||
{
|
||||
param.at(1, m::me.user_id)
|
||||
param.at("event_id")
|
||||
};
|
||||
|
||||
using closure_prototype = bool (const string_view &,
|
||||
std::exception_ptr,
|
||||
const json::object &);
|
||||
|
||||
using prototype = void (const m::room::id &,
|
||||
const m::user::id &,
|
||||
const milliseconds &,
|
||||
const std::function<closure_prototype> &);
|
||||
|
||||
static mods::import<prototype> feds__head
|
||||
m::feds::opts opts;
|
||||
opts.room_id = room_id;
|
||||
opts.event_id = event_id;
|
||||
m::feds::auth(opts, [&out](const auto &result)
|
||||
{
|
||||
"federation_federation", "feds__head"
|
||||
};
|
||||
|
||||
feds__head(room_id, user_id, out.timeout, [&out]
|
||||
(const string_view &origin, std::exception_ptr eptr, const json::object &event)
|
||||
{
|
||||
if(eptr)
|
||||
if(result.eptr)
|
||||
return true;
|
||||
|
||||
const json::array auth_events
|
||||
const json::array auth_chain
|
||||
{
|
||||
event.at("auth_events")
|
||||
result.object.at("auth_chain")
|
||||
};
|
||||
|
||||
out << "+ " << std::setw(40) << std::left << origin;
|
||||
for(const json::array auth_event : auth_events)
|
||||
out << "+ " << std::setw(40) << std::left << result.origin;
|
||||
for(const json::object &auth_event : auth_chain)
|
||||
{
|
||||
const auto &auth_event_id
|
||||
{
|
||||
unquote(auth_event.at(0))
|
||||
};
|
||||
|
||||
out << " " << string_view{auth_event_id};
|
||||
out << " " << unquote(auth_event.at("event_id"));
|
||||
};
|
||||
|
||||
out << std::endl;
|
||||
return true;
|
||||
});
|
||||
|
|
|
@ -212,6 +212,35 @@ ircd::m::feds::event(const opts &opts,
|
|||
return handler(opts, closure, requests);
|
||||
}
|
||||
|
||||
bool
|
||||
IRCD_MODULE_EXPORT
|
||||
ircd::m::feds::auth(const opts &opts,
|
||||
const closure &closure)
|
||||
{
|
||||
const auto make_request{[&opts]
|
||||
(auto &request, const auto &origin)
|
||||
{
|
||||
m::v1::event_auth::opts v1opts;
|
||||
v1opts.dynamic = true;
|
||||
v1opts.remote = string_view
|
||||
{
|
||||
strlcpy{request.origin, origin}
|
||||
};
|
||||
|
||||
return m::v1::event_auth
|
||||
{
|
||||
opts.room_id, opts.user_id, request.buf, std::move(v1opts)
|
||||
};
|
||||
}};
|
||||
|
||||
auto requests
|
||||
{
|
||||
creator<m::v1::event_auth>(opts, make_request)
|
||||
};
|
||||
|
||||
return handler(opts, closure, requests);
|
||||
}
|
||||
|
||||
bool
|
||||
IRCD_MODULE_EXPORT
|
||||
ircd::m::feds::head(const opts &opts,
|
||||
|
|
Loading…
Reference in a new issue