mirror of
https://github.com/matrix-construct/construct
synced 2024-11-16 15:00:51 +01:00
ircd:Ⓜ️:v1: Split key request into server/query requests.
This commit is contained in:
parent
9821d7f333
commit
7e66e79715
2 changed files with 81 additions and 26 deletions
|
@ -11,15 +11,33 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#define HAVE_IRCD_M_V1_KEY_H
|
#define HAVE_IRCD_M_V1_KEY_H
|
||||||
|
|
||||||
namespace ircd::m::v1
|
namespace ircd::m::v1::key
|
||||||
{
|
|
||||||
struct key;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ircd::m::v1::key
|
|
||||||
:server::request
|
|
||||||
{
|
{
|
||||||
struct opts;
|
struct opts;
|
||||||
|
struct keys;
|
||||||
|
struct query;
|
||||||
|
using server_key = std::pair<string_view, string_view>; // server_name, key_id
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ircd::m::v1::key::keys
|
||||||
|
:server::request
|
||||||
|
{
|
||||||
|
using opts = key::opts;
|
||||||
|
|
||||||
|
explicit operator json::object() const
|
||||||
|
{
|
||||||
|
const json::object object{in.content};
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
keys(const string_view &server_name, const mutable_buffer &, opts);
|
||||||
|
keys() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ircd::m::v1::key::query
|
||||||
|
:server::request
|
||||||
|
{
|
||||||
|
using opts = key::opts;
|
||||||
|
|
||||||
explicit operator json::array() const
|
explicit operator json::array() const
|
||||||
{
|
{
|
||||||
|
@ -28,10 +46,8 @@ struct ircd::m::v1::key
|
||||||
return server_keys;
|
return server_keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
using server_key = std::pair<string_view, string_view>; // server_name, key_id
|
query(const vector_view<const server_key> &, const mutable_buffer &, opts);
|
||||||
|
query() = default;
|
||||||
key(const vector_view<const server_key> &, const mutable_buffer &, opts);
|
|
||||||
key() = default;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ircd::m::v1::key::opts
|
struct ircd::m::v1::key::opts
|
||||||
|
|
61
ircd/m/v1.cc
61
ircd/m/v1.cc
|
@ -932,6 +932,49 @@ ircd::m::v1::query::query(const string_view &type,
|
||||||
// v1/key.h
|
// v1/key.h
|
||||||
//
|
//
|
||||||
|
|
||||||
|
ircd::m::v1::key::keys::keys(const string_view &server_name,
|
||||||
|
const mutable_buffer &buf,
|
||||||
|
opts opts)
|
||||||
|
:server::request{[&]
|
||||||
|
{
|
||||||
|
if(!opts.remote)
|
||||||
|
opts.remote = net::hostport{server_name};
|
||||||
|
|
||||||
|
if(!defined(json::get<"origin"_>(opts.request)))
|
||||||
|
json::get<"origin"_>(opts.request) = my_host();
|
||||||
|
|
||||||
|
if(!defined(json::get<"destination"_>(opts.request)))
|
||||||
|
json::get<"destination"_>(opts.request) = host(opts.remote);
|
||||||
|
|
||||||
|
if(defined(json::get<"content"_>(opts.request)))
|
||||||
|
opts.out.content = json::get<"content"_>(opts.request);
|
||||||
|
|
||||||
|
if(!defined(json::get<"content"_>(opts.request)))
|
||||||
|
json::get<"content"_>(opts.request) = json::object{opts.out.content};
|
||||||
|
|
||||||
|
if(!defined(json::get<"uri"_>(opts.request)))
|
||||||
|
json::get<"uri"_>(opts.request) = "/_matrix/key/v2/server/";
|
||||||
|
|
||||||
|
json::get<"method"_>(opts.request) = "GET";
|
||||||
|
|
||||||
|
opts.out.head = opts.request(buf);
|
||||||
|
|
||||||
|
if(!size(opts.in))
|
||||||
|
{
|
||||||
|
opts.in.head = buf + size(opts.out.head);
|
||||||
|
opts.in.content = opts.dynamic?
|
||||||
|
mutable_buffer{}: // server::request will allocate new mem
|
||||||
|
opts.in.head; // server::request will auto partition
|
||||||
|
}
|
||||||
|
|
||||||
|
return server::request
|
||||||
|
{
|
||||||
|
opts.remote, std::move(opts.out), std::move(opts.in), opts.sopts
|
||||||
|
};
|
||||||
|
}()}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
namespace ircd::m::v1
|
namespace ircd::m::v1
|
||||||
{
|
{
|
||||||
static const_buffer
|
static const_buffer
|
||||||
|
@ -939,7 +982,7 @@ namespace ircd::m::v1
|
||||||
const mutable_buffer &);
|
const mutable_buffer &);
|
||||||
}
|
}
|
||||||
|
|
||||||
ircd::m::v1::key::key(const vector_view<const server_key> &keys,
|
ircd::m::v1::key::query::query(const vector_view<const server_key> &keys,
|
||||||
const mutable_buffer &buf_,
|
const mutable_buffer &buf_,
|
||||||
opts opts)
|
opts opts)
|
||||||
:server::request{[&]
|
:server::request{[&]
|
||||||
|
@ -1001,23 +1044,19 @@ ircd::m::v1::_make_server_keys(const vector_view<const key::server_key> &keys,
|
||||||
{
|
{
|
||||||
json::stack::object top{out};
|
json::stack::object top{out};
|
||||||
json::stack::member server_keys{top, "server_keys"};
|
json::stack::member server_keys{top, "server_keys"};
|
||||||
|
json::stack::object keys_object{server_keys};
|
||||||
for(const auto &sk : keys)
|
for(const auto &sk : keys)
|
||||||
{
|
{
|
||||||
json::stack::object object{server_keys};
|
json::stack::member server_name{keys_object, sk.first};
|
||||||
json::stack::member server_name{object, sk.first};
|
json::stack::object server_object{server_name};
|
||||||
{
|
json::stack::member key_name{server_object, sk.second};
|
||||||
json::stack::object object{server_name};
|
json::stack::object key_object{key_name};
|
||||||
json::stack::member key_name{object, sk.second};
|
|
||||||
{
|
|
||||||
json::stack::object object{key_name};
|
|
||||||
json::stack::member mvut
|
json::stack::member mvut
|
||||||
{
|
{
|
||||||
object, "minimum_valid_until_ts", json::value{0L}
|
key_object, "minimum_valid_until_ts", json::value{0L}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return out.completed();
|
return out.completed();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue