0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-17 23:40:57 +01:00

ircd:Ⓜ️:keys: Add mass fetcher to interface.

This commit is contained in:
Jason Volk 2019-07-22 19:49:21 -07:00
parent 2dbef7763e
commit f1e3a9c53b
2 changed files with 84 additions and 0 deletions

View file

@ -60,6 +60,7 @@ struct ircd::m::keys
using closure = std::function<void (const json::object &)>; using closure = std::function<void (const json::object &)>;
using closure_bool = std::function<bool (const json::object &)>; using closure_bool = std::function<bool (const json::object &)>;
static bool get(const queries &, const closure_bool &);
static void get(const string_view &server_name, const closure &); static void get(const string_view &server_name, const closure &);
static void get(const string_view &server_name, const string_view &key_id, const closure &); static void get(const string_view &server_name, const string_view &key_id, const closure &);
static void query(const string_view &query_server, const queries &, const closure_bool &); static void query(const string_view &query_server, const queries &, const closure_bool &);

View file

@ -374,6 +374,89 @@ catch(const ctx::timeout &e)
}; };
} }
bool
IRCD_MODULE_EXPORT
ircd::m::keys::get(const queries &queries,
const closure_bool &closure)
{
bool ret{true};
std::vector<m::feds::opts> opts;
opts.reserve(queries.size());
for(const auto &[server_name, key_id] : queries)
{
const bool cached
{
cache::get(server_name, key_id, [&ret, &closure]
(const auto &object)
{
ret = closure(object);
})
};
if(!ret)
return ret;
if(cached)
continue;
if(server_name == my_host())
{
log::derror
{
m::log, "key '%s' for '%s' (that's myself) not found.",
key_id,
server_name,
};
continue;
}
log::debug
{
m::log, "Key '%s' for %s not cached; querying network...",
key_id,
server_name,
};
opts.emplace_back();
opts.back().op = feds::op::keys;
opts.back().arg[0] = server_name;
opts.back().arg[1] = key_id;
}
assert(opts.size() <= queries.size());
m::feds::acquire(opts, [&ret, &closure]
(const auto &result)
{
if(empty(result.object))
return true;
const m::keys keys
{
result.object
};
if(!verify(keys, std::nothrow))
{
log::derror
{
m::log, "Failed to verify key '%s' for '%s' from '%s'",
result.request->arg[0],
result.request->arg[1],
result.origin,
};
return true;
}
cache::set(result.object);
ret = closure(result.object);
return ret;
});
return ret;
}
// //
// m::keys::cache // m::keys::cache
// //