mirror of
https://github.com/matrix-construct/construct
synced 2024-11-01 03:18:54 +01:00
modules/key/query: Implement federation 3.3.2.2 POST method.
This commit is contained in:
parent
f93ad3d816
commit
fe63f9a3db
1 changed files with 70 additions and 0 deletions
|
@ -13,6 +13,9 @@ namespace ircd::m
|
||||||
static resource::response handle_key_query_get(client &, const resource::request &);
|
static resource::response handle_key_query_get(client &, const resource::request &);
|
||||||
extern resource::method key_query_get;
|
extern resource::method key_query_get;
|
||||||
|
|
||||||
|
static resource::response handle_key_query_post(client &, const resource::request &);
|
||||||
|
extern resource::method key_query_post;
|
||||||
|
|
||||||
extern resource key_query_resource;
|
extern resource key_query_resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +35,73 @@ ircd::m::key_query_resource
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
decltype(ircd::m::key_query_post)
|
||||||
|
ircd::m::key_query_post
|
||||||
|
{
|
||||||
|
key_query_resource, "POST", handle_key_query_post
|
||||||
|
};
|
||||||
|
|
||||||
|
ircd::m::resource::response
|
||||||
|
ircd::m::handle_key_query_post(client &client,
|
||||||
|
const m::resource::request &request)
|
||||||
|
{
|
||||||
|
const json::object &server_keys_request
|
||||||
|
{
|
||||||
|
request["server_keys"]
|
||||||
|
};
|
||||||
|
|
||||||
|
resource::response::chunked response
|
||||||
|
{
|
||||||
|
client, http::OK
|
||||||
|
};
|
||||||
|
|
||||||
|
json::stack out
|
||||||
|
{
|
||||||
|
response.buf, response.flusher()
|
||||||
|
};
|
||||||
|
|
||||||
|
json::stack::object top{out};
|
||||||
|
json::stack::array server_keys_out
|
||||||
|
{
|
||||||
|
top, "server_keys"
|
||||||
|
};
|
||||||
|
|
||||||
|
for(const auto &[server_name, requests] : server_keys_request)
|
||||||
|
{
|
||||||
|
if(empty(json::object(requests)))
|
||||||
|
{
|
||||||
|
keys::cache::for_each(server_name, [&server_keys_out]
|
||||||
|
(const m::keys &keys)
|
||||||
|
{
|
||||||
|
server_keys_out.append(keys.source);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(const auto &[key_id, criteria] : json::object(requests))
|
||||||
|
{
|
||||||
|
const time_t &minimum_valid_until_ts
|
||||||
|
{
|
||||||
|
json::object(criteria).get<time_t>("minimum_valid_until_ts", ircd::time<milliseconds>())
|
||||||
|
};
|
||||||
|
|
||||||
|
keys::cache::get(server_name, key_id, [&server_keys_out, &minimum_valid_until_ts]
|
||||||
|
(const m::keys &keys)
|
||||||
|
{
|
||||||
|
// Condition ignored to match synapse behavior.
|
||||||
|
if((false) && json::get<"valid_until_ts"_>(keys) < minimum_valid_until_ts)
|
||||||
|
return;
|
||||||
|
|
||||||
|
server_keys_out.append(keys.source);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
decltype(ircd::m::key_query_get)
|
decltype(ircd::m::key_query_get)
|
||||||
ircd::m::key_query_get
|
ircd::m::key_query_get
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue