From bc1e54aa1292d271941418957dc51c3023190164 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 19 Jun 2020 22:22:54 -0700 Subject: [PATCH] ircd::m::event: Minor rename; additional diagnostic arguments. --- include/ircd/m/event/event.h | 2 +- matrix/event.cc | 13 +++++++------ modules/console.cc | 23 +++++++++++++++++++++++ 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/include/ircd/m/event/event.h b/include/ircd/m/event/event.h index 307a4adae..618a679f2 100644 --- a/include/ircd/m/event/event.h +++ b/include/ircd/m/event/event.h @@ -121,7 +121,7 @@ struct ircd::m::event static conf::item max_size; static bool my(const idx &); - static json::object referential(const mutable_buffer &, const json::object &); + static json::object preimage(const mutable_buffer &, const json::object &); static void essential(json::iov &event, const json::iov &content, const closure_iov_mutable &); static bool verify(const json::object &, const ed25519::pk &, const ed25519::sig &sig); static ed25519::sig sign(const string_view &, const ed25519::sk &); diff --git a/matrix/event.cc b/matrix/event.cc index a362963a0..a4f55ef5d 100644 --- a/matrix/event.cc +++ b/matrix/event.cc @@ -182,14 +182,14 @@ ircd::sha256::buf ircd::m::event::hash(const json::object &event_) { thread_local char buf[event::MAX_SIZE]; - const json::object event + const json::object preimage { - referential(buf, event_) + event::preimage(buf, event_) }; return sha256 { - event + preimage }; } @@ -915,8 +915,8 @@ catch(const json::not_found &e) } ircd::json::object -ircd::m::event::referential(const mutable_buffer &buf, - const json::object &event) +ircd::m::event::preimage(const mutable_buffer &buf_, + const json::object &event) try { static const size_t iov_max{json::iov::max_size}; @@ -936,9 +936,10 @@ try member.at(i++) = m; } + mutable_buffer buf{buf_}; const string_view ret { - json::stringify(mutable_buffer(buf), member.data(), member.data() + i) + json::stringify(buf, member.data(), member.data() + i) }; return ret; diff --git a/modules/console.cc b/modules/console.cc index 366d46452..f3b3a117c 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -14296,6 +14296,29 @@ console_cmd__fed__event(opt &out, const string_view &line) return true; } + if(has(op, "essential")) + { + const unique_mutable_buffer buf + { + m::event::MAX_SIZE + }; + + out << m::essential(response, buf) << std::endl; + return true; + } + + if(has(op, "preimage")) + { + const unique_mutable_buffer buf + { + m::event::MAX_SIZE + }; + + const string_view preimage(m::event::preimage(buf, response)); + out << preimage << std::endl; + return true; + } + m::event::id::buf _event_id; const m::event event {