0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-16 15:00:51 +01:00

ircd:Ⓜ️:room: Expose bootstrap to interface.

This commit is contained in:
Jason Volk 2019-06-07 04:47:17 -07:00
parent 1f1b3033f9
commit 8e0ac58987
3 changed files with 73 additions and 23 deletions

View file

@ -174,6 +174,10 @@ struct ircd::m::room
static event::idx index(const id &, std::nothrow_t); static event::idx index(const id &, std::nothrow_t);
static event::idx index(const id &); static event::idx index(const id &);
static void bootstrap(const event &, const string_view &host);
static void bootstrap(const event::id &, const string_view &host);
static event::id::buf bootstrap(const id &, const id::user &, const string_view &host);
static size_t purge(const room &); // cuidado! static size_t purge(const room &); // cuidado!
}; };

View file

@ -57,7 +57,7 @@ ircd::m::join(const room &room,
if(!exists(room)) if(!exists(room))
{ {
const auto &room_id(room.room_id); const auto &room_id(room.room_id);
return bootstrap(room_id.host(), room_id, user_id); //TODO: host return bootstrap(room_id, user_id, room_id.host()); //TODO: host
} }
json::iov event; json::iov event;
@ -121,7 +121,7 @@ ircd::m::join(const m::room::alias &room_alias,
}; };
if(!exists(room_id)) if(!exists(room_id))
return bootstrap(room_alias.host(), room_id, user_id); return bootstrap(room_id, user_id, room_alias.host());
const m::room room const m::room room
{ {
@ -160,10 +160,6 @@ bootstrap_backfill(const string_view &host,
const m::room::id &, const m::room::id &,
const m::event::id &); const m::event::id &);
static void
bootstrap_worker(const string_view &host,
const m::event::id &);
conf::item<seconds> conf::item<seconds>
make_join_timeout make_join_timeout
{ {
@ -236,9 +232,10 @@ lazychain_enable
}; };
event::id::buf event::id::buf
bootstrap(std::string host, IRCD_MODULE_EXPORT
const m::room::id &room_id, ircd::m::room::bootstrap(const m::room::id &room_id,
const m::user::id &user_id) const m::user::id &user_id,
const string_view &host)
{ {
log::debug log::debug
{ {
@ -253,27 +250,49 @@ bootstrap(std::string host,
bootstrap_make_join(host, room_id, user_id) bootstrap_make_join(host, room_id, user_id)
}; };
context bootstrap(event_id, host); // asynchronous; returns quickly
{
"joinstrap", 128_KiB,
context::POST | context::DETACH,
[host(std::move(host)), event_id(std::string(event_id))]
{
bootstrap_worker(host, event_id);
}
};
return event_id; return event_id;
} }
void void
bootstrap_worker(const string_view &host, IRCD_MODULE_EXPORT
const m::event::id &event_id) ircd::m::room::bootstrap(const m::event::id &event_id,
const string_view &host)
try try
{ {
const m::event::fetch event const m::event::fetch event{event_id};
assert(event.source);
context
{ {
event_id "joinstrap", 128_KiB,
context::POST | context::DETACH,
[host(std::string(host)), event(std::string(event.source))]
{
bootstrap(m::event{event}, host);
}
};
}
catch(const std::exception &e)
{
log::error
{
m::log, "join bootstrap for %s to %s :%s",
string_view{event_id},
string(host),
e.what()
};
}
void
IRCD_MODULE_EXPORT
ircd::m::room::bootstrap(const m::event &event,
const string_view &host)
try
{
const m::event::id &event_id
{
at<"event_id"_>(event)
}; };
const m::room::id &room_id const m::room::id &room_id
@ -347,7 +366,7 @@ catch(const std::exception &e)
log::error log::error
{ {
m::log, "join bootstrap for %s to %s :%s", m::log, "join bootstrap for %s to %s :%s",
string_view{event_id}, string_view{at<"event_id"_>(event)},
string(host), string(host),
e.what() e.what()
}; };

View file

@ -9835,6 +9835,33 @@ console_cmd__room__stats(opt &out, const string_view &line)
return true; return true;
} }
bool
console_cmd__room__restrap(opt &out, const string_view &line)
{
const params param{line, " ",
{
"event_id", "host"
}};
const m::event::id &event_id
{
param.at("event_id")
};
const net::hostport &host_
{
param.at("host")
};
const string_view &host
{
param.at("host")
};
m::room::bootstrap(event_id, host);
return true;
}
// //
// user // user
// //