2018-02-14 21:23:20 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
#include "rooms.h"
|
|
|
|
|
2018-02-23 00:52:43 +01:00
|
|
|
using namespace ircd::m;
|
2018-02-14 21:23:20 +01:00
|
|
|
using namespace ircd;
|
|
|
|
|
2018-03-27 12:00:09 +02:00
|
|
|
static event::id::buf
|
2019-06-07 10:57:55 +02:00
|
|
|
bootstrap(std::string host,
|
2018-03-27 12:00:09 +02:00
|
|
|
const m::room::id &room_id,
|
|
|
|
const m::user::id &user_id);
|
|
|
|
|
2018-02-14 21:23:20 +01:00
|
|
|
resource::response
|
|
|
|
post__join(client &client,
|
|
|
|
const resource::request &request,
|
2018-02-23 00:52:43 +01:00
|
|
|
const room::id &room_id)
|
2018-02-14 21:23:20 +01:00
|
|
|
{
|
2018-02-22 10:35:00 +01:00
|
|
|
const string_view &third_party_signed
|
|
|
|
{
|
|
|
|
unquote(request["third_party_signed"])
|
|
|
|
};
|
|
|
|
|
2018-06-12 09:29:00 +02:00
|
|
|
const string_view &server_name
|
|
|
|
{
|
|
|
|
unquote(request["server_name"])
|
|
|
|
};
|
|
|
|
|
2019-04-22 22:21:05 +02:00
|
|
|
const m::room room
|
|
|
|
{
|
|
|
|
room_id
|
|
|
|
};
|
|
|
|
|
|
|
|
m::join(room, request.user_id);
|
2018-02-14 21:23:20 +01:00
|
|
|
|
|
|
|
return resource::response
|
|
|
|
{
|
|
|
|
client, json::members
|
|
|
|
{
|
|
|
|
{ "room_id", room_id }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2018-02-23 00:52:43 +01:00
|
|
|
|
|
|
|
event::id::buf
|
2019-04-22 22:21:05 +02:00
|
|
|
IRCD_MODULE_EXPORT
|
|
|
|
ircd::m::join(const room &room,
|
|
|
|
const id::user &user_id)
|
2018-02-23 00:52:43 +01:00
|
|
|
{
|
2018-03-09 01:32:31 +01:00
|
|
|
if(!exists(room))
|
2018-06-12 09:29:00 +02:00
|
|
|
{
|
|
|
|
const auto &room_id(room.room_id);
|
2019-06-07 13:47:17 +02:00
|
|
|
return bootstrap(room_id, user_id, room_id.host()); //TODO: host
|
2018-06-12 09:29:00 +02:00
|
|
|
}
|
2018-03-09 01:32:31 +01:00
|
|
|
|
2018-02-23 00:52:43 +01:00
|
|
|
json::iov event;
|
|
|
|
json::iov content;
|
|
|
|
const json::iov::push push[]
|
|
|
|
{
|
|
|
|
{ event, { "type", "m.room.member" }},
|
|
|
|
{ event, { "sender", user_id }},
|
|
|
|
{ event, { "state_key", user_id }},
|
|
|
|
{ content, { "membership", "join" }},
|
|
|
|
};
|
|
|
|
|
2019-02-21 19:45:37 +01:00
|
|
|
const m::user user{user_id};
|
|
|
|
const m::user::profile profile{user};
|
2018-03-23 00:28:43 +01:00
|
|
|
|
|
|
|
char displayname_buf[256];
|
|
|
|
const string_view displayname
|
|
|
|
{
|
2019-02-21 19:45:37 +01:00
|
|
|
profile.get(displayname_buf, "displayname")
|
2018-03-23 00:28:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
char avatar_url_buf[256];
|
|
|
|
const string_view avatar_url
|
|
|
|
{
|
2019-02-21 19:45:37 +01:00
|
|
|
profile.get(avatar_url_buf, "avatar_url")
|
2018-03-23 00:28:43 +01:00
|
|
|
};
|
|
|
|
|
2018-06-05 20:19:40 +02:00
|
|
|
const json::iov::add _displayname
|
2018-03-23 00:28:43 +01:00
|
|
|
{
|
2018-06-05 20:19:40 +02:00
|
|
|
content, !empty(displayname),
|
|
|
|
{
|
|
|
|
"displayname", [&displayname]() -> json::value
|
|
|
|
{
|
|
|
|
return displayname;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::iov::add _avatar_url
|
|
|
|
{
|
|
|
|
content, !empty(avatar_url),
|
|
|
|
{
|
|
|
|
"avatar_url", [&avatar_url]() -> json::value
|
|
|
|
{
|
|
|
|
return avatar_url;
|
|
|
|
}
|
|
|
|
}
|
2018-03-23 00:28:43 +01:00
|
|
|
};
|
|
|
|
|
2018-02-23 00:52:43 +01:00
|
|
|
return commit(room, event, content);
|
|
|
|
}
|
2018-03-27 12:00:09 +02:00
|
|
|
|
|
|
|
event::id::buf
|
2019-04-22 22:21:05 +02:00
|
|
|
IRCD_MODULE_EXPORT
|
|
|
|
ircd::m::join(const m::room::alias &room_alias,
|
|
|
|
const m::user::id &user_id)
|
2018-03-27 12:00:09 +02:00
|
|
|
{
|
|
|
|
const room::id::buf room_id
|
|
|
|
{
|
|
|
|
m::room_id(room_alias)
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!exists(room_id))
|
2019-06-07 13:47:17 +02:00
|
|
|
return bootstrap(room_id, user_id, room_alias.host());
|
2018-03-27 12:00:09 +02:00
|
|
|
|
2019-04-22 22:21:05 +02:00
|
|
|
const m::room room
|
|
|
|
{
|
|
|
|
room_id
|
|
|
|
};
|
|
|
|
|
|
|
|
return m::join(room, user_id);
|
2018-03-27 12:00:09 +02:00
|
|
|
}
|
|
|
|
|
2019-06-06 00:57:56 +02:00
|
|
|
//
|
|
|
|
// bootstrap
|
|
|
|
//
|
|
|
|
|
|
|
|
static event::id::buf
|
2019-06-07 10:57:55 +02:00
|
|
|
bootstrap_make_join(const string_view &host,
|
2019-06-06 00:57:56 +02:00
|
|
|
const m::room::id &,
|
|
|
|
const m::user::id &);
|
|
|
|
|
|
|
|
static std::tuple<json::object, unique_buffer<mutable_buffer>>
|
2019-06-07 10:57:55 +02:00
|
|
|
bootstrap_send_join(const string_view &host,
|
2019-06-06 00:57:56 +02:00
|
|
|
const m::room::id &,
|
2019-06-07 10:57:55 +02:00
|
|
|
const m::event::id &,
|
|
|
|
const json::object &event);
|
2019-06-06 00:57:56 +02:00
|
|
|
|
|
|
|
static void
|
2019-06-07 10:57:55 +02:00
|
|
|
bootstrap_eval_lazy_chain(const json::array &auth_chain);
|
|
|
|
|
|
|
|
static void
|
|
|
|
bootstrap_eval_auth_chain(const json::array &auth_chain);
|
2019-06-06 00:57:56 +02:00
|
|
|
|
|
|
|
static void
|
|
|
|
bootstrap_eval_state(const json::array &state);
|
|
|
|
|
|
|
|
static void
|
2019-06-07 10:57:55 +02:00
|
|
|
bootstrap_backfill(const string_view &host,
|
2019-06-06 00:57:56 +02:00
|
|
|
const m::room::id &,
|
|
|
|
const m::event::id &);
|
|
|
|
|
2018-09-05 08:19:26 +02:00
|
|
|
conf::item<seconds>
|
|
|
|
make_join_timeout
|
|
|
|
{
|
|
|
|
{ "name", "ircd.client.rooms.join.make_join.timeout" },
|
|
|
|
{ "default", 15L },
|
|
|
|
};
|
|
|
|
|
|
|
|
conf::item<seconds>
|
|
|
|
send_join_timeout
|
|
|
|
{
|
2019-06-06 00:57:56 +02:00
|
|
|
{ "name", "ircd.client.rooms.join.send_join.timeout" },
|
2018-09-05 08:19:26 +02:00
|
|
|
{ "default", 45L /* spinappse */ },
|
|
|
|
};
|
|
|
|
|
2019-06-06 00:57:56 +02:00
|
|
|
conf::item<seconds>
|
|
|
|
backfill_timeout
|
|
|
|
{
|
|
|
|
{ "name", "ircd.client.rooms.join.backfill.timeout" },
|
|
|
|
{ "default", 15L },
|
|
|
|
};
|
|
|
|
|
2019-06-06 10:31:01 +02:00
|
|
|
conf::item<size_t>
|
|
|
|
backfill_limit
|
|
|
|
{
|
|
|
|
{ "name", "ircd.client.rooms.join.backfill.limit" },
|
|
|
|
{ "default", 64L },
|
|
|
|
{ "description",
|
|
|
|
|
|
|
|
R"(
|
|
|
|
The number of events to request on initial backfill. Specapse may limit
|
|
|
|
this to 50, but it also may not. Either way, a good choice is enough to
|
|
|
|
fill a client's timeline quickly with a little headroom.
|
|
|
|
)"}
|
|
|
|
};
|
|
|
|
|
2019-06-06 10:27:13 +02:00
|
|
|
conf::item<bool>
|
|
|
|
backfill_first
|
|
|
|
{
|
|
|
|
{ "name", "ircd.client.rooms.join.backfill.first" },
|
|
|
|
{ "default", true },
|
|
|
|
{ "description",
|
|
|
|
|
|
|
|
R"(
|
|
|
|
During the room join bootstrap process, this controls whether backfilling
|
|
|
|
recent timeline events occurs before processing the room state. If true,
|
|
|
|
user experience may be improved because their client's timeline is
|
|
|
|
immediately populated with recent messages. Otherwise, the backfill will be
|
|
|
|
delayed until after all state events have been processed first. Setting
|
|
|
|
this to false is safer, as some clients may be confused by timeline events
|
|
|
|
which are missing related state events. Note that fundamental state events
|
|
|
|
for the room are still processed first regardless of this setting. Also
|
|
|
|
known as the Hackfill optimization.
|
|
|
|
)"}
|
|
|
|
};
|
|
|
|
|
2019-06-06 13:10:56 +02:00
|
|
|
conf::item<bool>
|
2019-06-07 02:42:29 +02:00
|
|
|
lazychain_enable
|
2019-06-06 13:10:56 +02:00
|
|
|
{
|
2019-06-07 02:42:29 +02:00
|
|
|
{ "name", "ircd.client.rooms.join.lazychain.enable" },
|
|
|
|
{ "default", true },
|
2019-06-06 13:10:56 +02:00
|
|
|
{ "description",
|
|
|
|
|
|
|
|
R"(
|
|
|
|
During the room join bootstrap process, this controls whether the
|
|
|
|
auth_chain in the response is only selectively processed. This is a
|
|
|
|
safe optimization that allows the bootstrap to progress to the next
|
|
|
|
phase. The skipped events are eventually processed during the state
|
|
|
|
evaluation phase.
|
|
|
|
)"}
|
|
|
|
};
|
|
|
|
|
2019-06-06 00:57:56 +02:00
|
|
|
event::id::buf
|
2019-06-07 13:47:17 +02:00
|
|
|
IRCD_MODULE_EXPORT
|
|
|
|
ircd::m::room::bootstrap(const m::room::id &room_id,
|
|
|
|
const m::user::id &user_id,
|
|
|
|
const string_view &host)
|
2018-03-27 12:00:09 +02:00
|
|
|
{
|
2019-06-06 00:57:56 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
m::log, "join bootstrap starting in %s for %s to '%s'",
|
|
|
|
string_view{room_id},
|
|
|
|
string_view{user_id},
|
2019-06-07 10:57:55 +02:00
|
|
|
host
|
2019-06-06 00:57:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const auto event_id
|
|
|
|
{
|
|
|
|
bootstrap_make_join(host, room_id, user_id)
|
|
|
|
};
|
|
|
|
|
2019-06-07 13:47:17 +02:00
|
|
|
bootstrap(event_id, host); // asynchronous; returns quickly
|
|
|
|
|
|
|
|
return event_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IRCD_MODULE_EXPORT
|
|
|
|
ircd::m::room::bootstrap(const m::event::id &event_id,
|
|
|
|
const string_view &host)
|
|
|
|
try
|
|
|
|
{
|
|
|
|
const m::event::fetch event{event_id};
|
|
|
|
assert(event.source);
|
2019-06-07 10:57:55 +02:00
|
|
|
context
|
|
|
|
{
|
|
|
|
"joinstrap", 128_KiB,
|
|
|
|
context::POST | context::DETACH,
|
2019-06-07 13:47:17 +02:00
|
|
|
[host(std::string(host)), event(std::string(event.source))]
|
2019-06-07 10:57:55 +02:00
|
|
|
{
|
2019-06-07 13:47:17 +02:00
|
|
|
bootstrap(m::event{event}, host);
|
2019-06-07 10:57:55 +02:00
|
|
|
}
|
|
|
|
};
|
2019-06-07 13:47:17 +02:00
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
m::log, "join bootstrap for %s to %s :%s",
|
|
|
|
string_view{event_id},
|
|
|
|
string(host),
|
|
|
|
e.what()
|
|
|
|
};
|
2019-06-07 10:57:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-06-07 13:47:17 +02:00
|
|
|
IRCD_MODULE_EXPORT
|
|
|
|
ircd::m::room::bootstrap(const m::event &event,
|
|
|
|
const string_view &host)
|
2019-06-07 10:57:55 +02:00
|
|
|
try
|
|
|
|
{
|
2019-06-07 13:47:17 +02:00
|
|
|
const m::event::id &event_id
|
2019-06-07 10:57:55 +02:00
|
|
|
{
|
2019-06-07 13:47:17 +02:00
|
|
|
at<"event_id"_>(event)
|
2019-06-07 10:57:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const m::room::id &room_id
|
|
|
|
{
|
|
|
|
at<"room_id"_>(event)
|
|
|
|
};
|
|
|
|
|
|
|
|
const m::user::id &user_id
|
|
|
|
{
|
|
|
|
at<"sender"_>(event)
|
|
|
|
};
|
|
|
|
|
2019-06-06 10:41:11 +02:00
|
|
|
log::info
|
2019-06-06 00:57:56 +02:00
|
|
|
{
|
|
|
|
m::log, "join bootstrap sending in %s for %s at %s to '%s'",
|
|
|
|
string_view{room_id},
|
|
|
|
string_view{user_id},
|
|
|
|
string_view{event_id},
|
2019-06-07 10:57:55 +02:00
|
|
|
host
|
2019-06-06 00:57:56 +02:00
|
|
|
};
|
|
|
|
|
2019-06-07 10:57:55 +02:00
|
|
|
assert(event.source);
|
2019-06-06 00:57:56 +02:00
|
|
|
const auto &[response, buf]
|
|
|
|
{
|
2019-06-07 10:57:55 +02:00
|
|
|
bootstrap_send_join(host, room_id, event_id, event.source)
|
2019-06-06 00:57:56 +02:00
|
|
|
};
|
|
|
|
|
2019-06-06 10:41:11 +02:00
|
|
|
log::info
|
2019-06-06 00:57:56 +02:00
|
|
|
{
|
2019-06-07 07:39:05 +02:00
|
|
|
m::log, "join bootstrap joined to %s for %s at %s to '%s'",
|
2019-06-06 00:57:56 +02:00
|
|
|
string_view{room_id},
|
|
|
|
string_view{user_id},
|
|
|
|
string_view{event_id},
|
2019-06-07 10:57:55 +02:00
|
|
|
host
|
2019-06-06 00:57:56 +02:00
|
|
|
};
|
|
|
|
|
2019-06-07 10:57:55 +02:00
|
|
|
const json::array &auth_chain
|
|
|
|
{
|
|
|
|
response["auth_chain"]
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::array &state
|
|
|
|
{
|
|
|
|
response["state"]
|
|
|
|
};
|
|
|
|
|
|
|
|
if(lazychain_enable)
|
|
|
|
bootstrap_eval_lazy_chain(auth_chain);
|
|
|
|
else
|
|
|
|
bootstrap_eval_auth_chain(auth_chain);
|
2019-06-06 10:27:13 +02:00
|
|
|
|
|
|
|
if(backfill_first)
|
|
|
|
{
|
|
|
|
bootstrap_backfill(host, room_id, event_id);
|
2019-06-07 10:57:55 +02:00
|
|
|
bootstrap_eval_state(state);
|
2019-06-06 10:27:13 +02:00
|
|
|
} else {
|
2019-06-07 10:57:55 +02:00
|
|
|
bootstrap_eval_state(state);
|
2019-06-06 10:27:13 +02:00
|
|
|
bootstrap_backfill(host, room_id, event_id);
|
|
|
|
}
|
2019-06-06 00:57:56 +02:00
|
|
|
|
2019-06-06 10:41:11 +02:00
|
|
|
log::info
|
2019-06-06 00:57:56 +02:00
|
|
|
{
|
|
|
|
m::log, "join bootstrap joined to %s for %s at %s complete",
|
|
|
|
string_view{room_id},
|
|
|
|
string_view{user_id},
|
|
|
|
string_view{event_id},
|
|
|
|
};
|
2019-06-07 10:57:55 +02:00
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
m::log, "join bootstrap for %s to %s :%s",
|
2019-06-07 13:47:17 +02:00
|
|
|
string_view{at<"event_id"_>(event)},
|
2019-06-07 10:57:55 +02:00
|
|
|
string(host),
|
|
|
|
e.what()
|
|
|
|
};
|
2019-06-06 00:57:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-06-07 10:57:55 +02:00
|
|
|
bootstrap_backfill(const string_view &host,
|
2019-06-06 00:57:56 +02:00
|
|
|
const m::room::id &room_id,
|
|
|
|
const m::event::id &event_id)
|
|
|
|
try
|
|
|
|
{
|
|
|
|
const unique_buffer<mutable_buffer> buf
|
|
|
|
{
|
|
|
|
16_KiB // headers in and out
|
|
|
|
};
|
|
|
|
|
|
|
|
m::v1::backfill::opts opts{host};
|
|
|
|
opts.dynamic = true;
|
|
|
|
opts.event_id = event_id;
|
2019-06-06 10:31:01 +02:00
|
|
|
opts.limit = size_t(backfill_limit);
|
2019-06-06 00:57:56 +02:00
|
|
|
m::v1::backfill request
|
|
|
|
{
|
|
|
|
room_id, buf, std::move(opts)
|
|
|
|
};
|
|
|
|
|
|
|
|
request.wait(seconds(backfill_timeout));
|
|
|
|
|
|
|
|
const auto code
|
|
|
|
{
|
|
|
|
request.get()
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::object &response
|
|
|
|
{
|
|
|
|
request.in.content
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::array &pdus
|
|
|
|
{
|
|
|
|
response["pdus"]
|
|
|
|
};
|
|
|
|
|
2019-06-07 10:57:55 +02:00
|
|
|
m::vm::opts vmopts;
|
|
|
|
vmopts.fetch_state_check = false;
|
|
|
|
vmopts.fetch_prev_check = false;
|
|
|
|
vmopts.infolog_accept = false;
|
|
|
|
m::vm::eval
|
2019-06-06 00:57:56 +02:00
|
|
|
{
|
2019-06-07 10:57:55 +02:00
|
|
|
pdus, vmopts
|
|
|
|
};
|
2019-06-06 00:57:56 +02:00
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
m::log, "Bootstrap %s backfill @ %s from %s :%s",
|
|
|
|
string_view{room_id},
|
|
|
|
string_view{event_id},
|
|
|
|
string(host),
|
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bootstrap_eval_state(const json::array &state)
|
|
|
|
{
|
|
|
|
m::vm::opts opts;
|
|
|
|
opts.fetch_prev_check = false;
|
|
|
|
opts.fetch_state_check = false;
|
2019-06-06 13:10:56 +02:00
|
|
|
opts.infolog_accept = false;
|
2019-06-06 00:57:56 +02:00
|
|
|
m::vm::eval
|
|
|
|
{
|
|
|
|
state, opts
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bootstrap_eval_auth_chain(const json::array &auth_chain)
|
|
|
|
{
|
|
|
|
m::vm::opts opts;
|
|
|
|
opts.infolog_accept = true;
|
|
|
|
opts.fetch = false;
|
2019-06-07 10:57:55 +02:00
|
|
|
m::vm::eval
|
2019-06-06 00:57:56 +02:00
|
|
|
{
|
2019-06-07 10:57:55 +02:00
|
|
|
auth_chain, opts
|
|
|
|
};
|
|
|
|
}
|
2019-06-06 13:10:56 +02:00
|
|
|
|
2019-06-07 10:57:55 +02:00
|
|
|
void
|
|
|
|
bootstrap_eval_lazy_chain(const json::array &auth_chain)
|
|
|
|
{
|
|
|
|
m::vm::opts opts;
|
|
|
|
opts.infolog_accept = true;
|
|
|
|
opts.fetch = false;
|
2019-06-06 13:10:56 +02:00
|
|
|
|
2019-06-07 03:24:14 +02:00
|
|
|
// Parse and sort the auth_chain first so we don't have to keep scanning
|
|
|
|
// the JSON to do the various operations that follow.
|
|
|
|
std::vector<m::event> events(begin(auth_chain), end(auth_chain));
|
|
|
|
std::sort(begin(events), end(events));
|
|
|
|
|
|
|
|
// When we selectively evaluate the auth_chain below we may need to feed
|
|
|
|
// the vm certain member events first to avoid complications; this
|
|
|
|
// subroutine will find them.
|
|
|
|
const auto find_member{[&events]
|
|
|
|
(const m::user::id &user_id)
|
|
|
|
{
|
|
|
|
const auto it(std::find_if(begin(events), end(events), [&user_id]
|
|
|
|
(const m::event &event)
|
|
|
|
{
|
|
|
|
return json::get<"type"_>(event) == "m.room.member" &&
|
|
|
|
json::get<"state_key"_>(event) == user_id;
|
|
|
|
}));
|
|
|
|
|
|
|
|
if(unlikely(it == end(events)))
|
|
|
|
throw m::NOT_FOUND
|
|
|
|
{
|
|
|
|
"No m.room.member event for %s found in auth chain.",
|
|
|
|
string_view{user_id}
|
|
|
|
};
|
|
|
|
|
|
|
|
return *it;
|
|
|
|
}};
|
|
|
|
|
|
|
|
for(const auto &event : events)
|
2019-06-06 13:10:56 +02:00
|
|
|
{
|
|
|
|
// Skip all events which aren't power events. We don't need them
|
|
|
|
// here yet. They can wait until state evaluation later.
|
2019-06-07 03:24:14 +02:00
|
|
|
if(!m::event::auth::is_power_event(event))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Find the member event for the sender of this power event so the
|
|
|
|
// system is aware of their identity first; this isn't done for the
|
|
|
|
// create event because the vm expects that first regardless.
|
|
|
|
if(json::get<"type"_>(event) != "m.room.create")
|
|
|
|
{
|
|
|
|
const auto &member_event
|
|
|
|
{
|
|
|
|
find_member(at<"sender"_>(event))
|
|
|
|
};
|
|
|
|
|
|
|
|
m::vm::eval
|
|
|
|
{
|
|
|
|
member_event, opts
|
|
|
|
};
|
|
|
|
}
|
2019-06-06 13:10:56 +02:00
|
|
|
|
|
|
|
m::vm::eval
|
|
|
|
{
|
|
|
|
event, opts
|
|
|
|
};
|
|
|
|
}
|
2019-06-06 00:57:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::tuple<json::object, unique_buffer<mutable_buffer>>
|
2019-06-07 10:57:55 +02:00
|
|
|
bootstrap_send_join(const string_view &host,
|
2019-06-06 00:57:56 +02:00
|
|
|
const m::room::id &room_id,
|
2019-06-07 10:57:55 +02:00
|
|
|
const m::event::id &event_id,
|
|
|
|
const json::object &event)
|
2019-06-06 00:57:56 +02:00
|
|
|
try
|
|
|
|
{
|
2018-03-27 12:00:09 +02:00
|
|
|
const unique_buffer<mutable_buffer> buf
|
|
|
|
{
|
2019-06-06 00:57:56 +02:00
|
|
|
16_KiB // headers in and out
|
|
|
|
};
|
|
|
|
|
|
|
|
m::v1::send_join::opts opts{host};
|
|
|
|
opts.dynamic = true;
|
|
|
|
m::v1::send_join send_join
|
|
|
|
{
|
2019-06-07 10:57:55 +02:00
|
|
|
room_id, event_id, event, buf, std::move(opts)
|
2019-06-06 00:57:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
send_join.wait(seconds(send_join_timeout));
|
|
|
|
|
|
|
|
const auto send_join_code
|
|
|
|
{
|
|
|
|
send_join.get()
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::array &send_join_response
|
|
|
|
{
|
|
|
|
send_join
|
|
|
|
};
|
|
|
|
|
|
|
|
const uint more_send_join_code
|
|
|
|
{
|
|
|
|
send_join_response.at<uint>(0)
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::object &send_join_response_data
|
|
|
|
{
|
|
|
|
send_join_response[1]
|
2018-03-27 12:00:09 +02:00
|
|
|
};
|
|
|
|
|
2019-06-06 00:57:56 +02:00
|
|
|
assert(!!send_join.in.dynamic);
|
|
|
|
return
|
|
|
|
{
|
|
|
|
send_join_response_data,
|
|
|
|
std::move(send_join.in.dynamic)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
2019-02-25 22:02:03 +01:00
|
|
|
{
|
2019-06-06 00:57:56 +02:00
|
|
|
m::log, "Bootstrap %s @ %s send_join to %s :%s",
|
|
|
|
string_view{room_id},
|
|
|
|
string_view{event_id},
|
|
|
|
string(host),
|
|
|
|
e.what(),
|
2019-02-25 22:02:03 +01:00
|
|
|
};
|
|
|
|
|
2019-06-06 00:57:56 +02:00
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
event::id::buf
|
2019-06-07 10:57:55 +02:00
|
|
|
bootstrap_make_join(const string_view &host,
|
2019-06-06 00:57:56 +02:00
|
|
|
const m::room::id &room_id,
|
|
|
|
const m::user::id &user_id)
|
|
|
|
try
|
|
|
|
{
|
|
|
|
const unique_buffer<mutable_buffer> buf
|
|
|
|
{
|
|
|
|
16_KiB // headers in and out
|
|
|
|
};
|
|
|
|
|
|
|
|
m::v1::make_join::opts opts{host};
|
2018-03-27 12:00:09 +02:00
|
|
|
m::v1::make_join request
|
|
|
|
{
|
2019-06-06 00:57:56 +02:00
|
|
|
room_id, user_id, buf, std::move(opts)
|
2018-03-27 12:00:09 +02:00
|
|
|
};
|
|
|
|
|
2018-09-05 08:19:26 +02:00
|
|
|
request.wait(seconds(make_join_timeout));
|
2018-03-27 12:00:09 +02:00
|
|
|
const auto code
|
|
|
|
{
|
|
|
|
request.get()
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::object &response
|
|
|
|
{
|
|
|
|
request.in.content
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::object &proto
|
|
|
|
{
|
|
|
|
response.at("event")
|
|
|
|
};
|
|
|
|
|
2019-06-06 00:57:56 +02:00
|
|
|
const json::array &auth_events
|
2018-03-27 12:00:09 +02:00
|
|
|
{
|
2019-06-06 00:57:56 +02:00
|
|
|
proto.get("auth_events")
|
2018-03-27 12:00:09 +02:00
|
|
|
};
|
|
|
|
|
2019-06-06 00:57:56 +02:00
|
|
|
const json::array &prev_events
|
2018-03-27 12:00:09 +02:00
|
|
|
{
|
2019-06-06 00:57:56 +02:00
|
|
|
proto.get("prev_events")
|
2018-03-27 12:00:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
json::iov event;
|
|
|
|
json::iov content;
|
|
|
|
const json::iov::push push[]
|
|
|
|
{
|
|
|
|
{ event, { "type", "m.room.member" }},
|
|
|
|
{ event, { "sender", user_id }},
|
|
|
|
{ event, { "state_key", user_id }},
|
|
|
|
{ content, { "membership", "join" }},
|
|
|
|
{ event, { "prev_events", prev_events }},
|
|
|
|
{ event, { "auth_events", auth_events }},
|
|
|
|
{ event, { "prev_state", "[]" }},
|
|
|
|
{ event, { "depth", proto.get<long>("depth") }},
|
|
|
|
{ event, { "room_id", room_id }},
|
|
|
|
};
|
|
|
|
|
2019-02-21 19:45:37 +01:00
|
|
|
const m::user user{user_id};
|
|
|
|
const m::user::profile profile{user};
|
2018-03-27 12:00:09 +02:00
|
|
|
|
|
|
|
char displayname_buf[256];
|
|
|
|
const string_view displayname
|
|
|
|
{
|
2019-02-21 19:45:37 +01:00
|
|
|
profile.get(displayname_buf, "displayname")
|
2018-03-27 12:00:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
char avatar_url_buf[256];
|
|
|
|
const string_view avatar_url
|
|
|
|
{
|
2019-02-21 19:45:37 +01:00
|
|
|
profile.get(avatar_url_buf, "avatar_url")
|
2018-03-27 12:00:09 +02:00
|
|
|
};
|
|
|
|
|
2018-06-05 20:19:40 +02:00
|
|
|
const json::iov::add _displayname
|
2018-03-27 12:00:09 +02:00
|
|
|
{
|
2018-06-05 20:19:40 +02:00
|
|
|
content, !empty(displayname),
|
|
|
|
{
|
|
|
|
"displayname", [&displayname]() -> json::value
|
|
|
|
{
|
|
|
|
return displayname;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::iov::add _avatar_url
|
|
|
|
{
|
|
|
|
content, !empty(avatar_url),
|
|
|
|
{
|
|
|
|
"avatar_url", [&avatar_url]() -> json::value
|
|
|
|
{
|
|
|
|
return avatar_url;
|
|
|
|
}
|
|
|
|
}
|
2018-03-27 12:00:09 +02:00
|
|
|
};
|
|
|
|
|
2019-06-07 10:57:55 +02:00
|
|
|
m::vm::copts vmopts;
|
|
|
|
vmopts.infolog_accept = true;
|
|
|
|
vmopts.fetch_auth_check = false;
|
|
|
|
vmopts.fetch_state_check = false;
|
|
|
|
vmopts.fetch_prev_check = false;
|
|
|
|
vmopts.eval = false;
|
|
|
|
const m::event::id::buf event_id
|
2019-06-05 07:41:59 +02:00
|
|
|
{
|
2019-06-07 10:57:55 +02:00
|
|
|
m::vm::eval
|
2019-06-05 07:41:59 +02:00
|
|
|
{
|
2019-06-07 10:57:55 +02:00
|
|
|
event, content, vmopts
|
|
|
|
}
|
|
|
|
};
|
2019-06-05 07:41:59 +02:00
|
|
|
|
2019-06-07 10:57:55 +02:00
|
|
|
return event_id;
|
2019-06-06 00:57:56 +02:00
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
2019-06-05 07:41:59 +02:00
|
|
|
{
|
2019-06-06 00:57:56 +02:00
|
|
|
m::log, "Bootstrap %s for %s make_join to %s :%s",
|
|
|
|
string_view{room_id},
|
|
|
|
string_view{user_id},
|
|
|
|
string(host),
|
|
|
|
e.what(),
|
|
|
|
};
|
2019-06-05 07:41:59 +02:00
|
|
|
|
2019-06-06 00:57:56 +02:00
|
|
|
throw;
|
2018-03-27 12:00:09 +02:00
|
|
|
}
|