diff --git a/modules/client/rooms/join.cc b/modules/client/rooms/join.cc index a139cff15..ede140b06 100644 --- a/modules/client/rooms/join.cc +++ b/modules/client/rooms/join.cc @@ -147,6 +147,9 @@ bootstrap_send_join(const string_view &host, const m::event::id &, const json::object &event); +static void +bootstrap_fetch_keys(const json::array &events); + static void bootstrap_eval_lazy_chain(const json::array &auth_chain); @@ -487,6 +490,8 @@ void bootstrap_eval_auth_chain(const json::array &auth_chain) try { + bootstrap_fetch_keys(auth_chain); + m::vm::opts opts; opts.infolog_accept = true; opts.fetch = false; @@ -571,6 +576,50 @@ bootstrap_eval_lazy_chain(const json::array &auth_chain) } } +void +bootstrap_fetch_keys(const json::array &events) +try +{ + std::vector queries; + queries.reserve(events.size()); + + for(const json::object &event : events) + for(const auto &[server_name, signatures] : json::object(event["signatures"])) + for(const auto &[key_id, signature] : json::object(signatures)) + queries.emplace_back(unquote(event.at("origin")), key_id); + + std::sort(begin(queries), end(queries)); + queries.erase(std::unique(begin(queries), end(queries)), end(queries)); + + log::info + { + join_log, "Fetching %zu keys for %zu events...", + queries.size(), + events.size(), + }; + + const size_t fetched + { + m::keys::fetch(queries) + }; + + log::info + { + join_log, "Fetched %zu of %zu keys for %zu events", + fetched, + queries.size(), + events.size(), + }; +} +catch(const std::exception &e) +{ + log::error + { + join_log, "Error when fetching keys for %zu events :%s", + events.size(), + }; +} + std::tuple> bootstrap_send_join(const string_view &host, const m::room::id &room_id, diff --git a/modules/m_keys.cc b/modules/m_keys.cc index d8e4b4302..aea3b2728 100644 --- a/modules/m_keys.cc +++ b/modules/m_keys.cc @@ -413,7 +413,7 @@ ircd::m::keys::get(const queries &queries, if(cached) continue; - if(server_name == my_host()) + if(my_host(server_name)) { log::derror {