0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-27 22:38:21 +02:00

ircd:Ⓜ️:request: Consolidate request content buffers; remove complex tls.

This commit is contained in:
Jason Volk 2021-02-10 00:49:25 -08:00
parent f7293581ec
commit efca102ef3
2 changed files with 42 additions and 38 deletions

View file

@ -33,8 +33,7 @@ struct ircd::m::request
struct x_matrix; struct x_matrix;
static const size_t headers_max; static const size_t headers_max;
static conf::item<size_t> generate_content_max; static conf::item<size_t> content_max;
static conf::item<size_t> verify_content_max;
static bool verify(const ed25519::pk &, const ed25519::sig &, const json::object &); static bool verify(const ed25519::pk &, const ed25519::sig &, const json::object &);
bool verify(const ed25519::pk &, const ed25519::sig &) const; bool verify(const ed25519::pk &, const ed25519::sig &) const;

View file

@ -8,6 +8,24 @@
// copyright notice and this permission notice is present in all copies. The // copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file. // full license for this software is available in the LICENSE file.
namespace ircd::m
{
static unique_mutable_buffer request_content_buf;
}
decltype(ircd::m::request::headers_max)
ircd::m::request::headers_max
{
32UL
};
decltype(ircd::m::request::content_max)
ircd::m::request::content_max
{
{ "name", "ircd.m.request.content.max" },
{ "default", long(4_MiB) },
};
ircd::m::request::request(const string_view &method, ircd::m::request::request(const string_view &method,
const string_view &uri, const string_view &uri,
const mutable_buffer &body_buf, const mutable_buffer &body_buf,
@ -76,12 +94,6 @@ ircd::m::request::request(const string_view &origin,
}; };
} }
decltype(ircd::m::request::headers_max)
ircd::m::request::headers_max
{
32UL
};
ircd::string_view ircd::string_view
ircd::m::request::operator()(const mutable_buffer &out, ircd::m::request::operator()(const mutable_buffer &out,
const vector_view<const http::header> &addl_headers) const vector_view<const http::header> &addl_headers)
@ -155,32 +167,25 @@ const
return sb.completed(); return sb.completed();
} }
decltype(ircd::m::request::generate_content_max)
ircd::m::request::generate_content_max
{
{ "name", "ircd.m.request.generate.content_max" },
{ "default", long(4_MiB) },
};
namespace ircd::m
{
static unique_mutable_buffer request_generate_content_buf;
}
ircd::string_view ircd::string_view
ircd::m::request::generate(const mutable_buffer &out, ircd::m::request::generate(const mutable_buffer &out,
const ed25519::sk &sk, const ed25519::sk &sk,
const string_view &pkid) const string_view &pkid)
const const
{ {
const ctx::critical_assertion _ca; const ctx::critical_assertion ca;
auto &buf{request_generate_content_buf}; if(unlikely(buffer::size(request_content_buf) != size_t(content_max)))
if(unlikely(buffer::size(buf) != size_t(generate_content_max))) request_content_buf = unique_mutable_buffer
buf = unique_mutable_buffer
{ {
size_t(generate_content_max), info::page_size size_t(content_max), info::page_size
}; };
assert(!empty(request_content_buf));
const mutable_buffer buf
{
request_content_buf
};
const auto serial_size const auto serial_size
{ {
json::serialized(*this) json::serialized(*this)
@ -257,18 +262,24 @@ const
return verified; return verified;
} }
decltype(ircd::m::request::verify_content_max)
ircd::m::request::verify_content_max
{
{ "name", "ircd.m.request.verify.content_max" },
{ "default", long(4_MiB) },
};
bool bool
ircd::m::request::verify(const ed25519::pk &pk, ircd::m::request::verify(const ed25519::pk &pk,
const ed25519::sig &sig) const ed25519::sig &sig)
const const
{ {
const ctx::critical_assertion ca;
if(unlikely(buffer::size(request_content_buf) != size_t(content_max)))
request_content_buf = unique_mutable_buffer
{
size_t(content_max), info::page_size
};
assert(!empty(request_content_buf));
const mutable_buffer buf
{
request_content_buf
};
// Matrix spec sez that an empty content object {} is excluded entirely // Matrix spec sez that an empty content object {} is excluded entirely
// from the verification. Our JSON only excludes members if they evaluate // from the verification. Our JSON only excludes members if they evaluate
// to undefined i.e json::object{}/string_view{} but not json::object{"{}"} // to undefined i.e json::object{}/string_view{} but not json::object{"{}"}
@ -278,12 +289,6 @@ const
if(empty(json::get<"content"_>(*this))) if(empty(json::get<"content"_>(*this)))
json::get<"content"_>(_this) = json::object{}; json::get<"content"_>(_this) = json::object{};
const ctx::critical_assertion ca;
thread_local unique_buffer<mutable_buffer> buf
{
size_t(verify_content_max)
};
const size_t request_size const size_t request_size
{ {
json::serialized(_this) json::serialized(_this)