From 287b5d63740a7e4190ab655e499132b497420463 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 22 Mar 2018 23:17:33 -0700 Subject: [PATCH] modules/console: fed state command mimics fed backfill w/ eval. --- modules/console.cc | 52 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/modules/console.cc b/modules/console.cc index 31221c805..0dcb06af7 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -1746,14 +1746,22 @@ console_cmd__fed__state(const string_view &line) const net::hostport remote { - token(line, ' ', 1) + token(line, ' ', 1, room_id.host()) }; - const string_view &event_id + string_view event_id { - token_count(line, ' ') >= 3? token(line, ' ', 2) : string_view{} + token(line, ' ', 2, {}) }; + string_view op + { + token(line, ' ', 3, {}) + }; + + if(!op && event_id == "eval") + std::swap(op, event_id); + // Used for out.head, out.content, in.head, but in.content is dynamic thread_local char buf[8_KiB]; m::v1::state::opts opts; @@ -1774,7 +1782,43 @@ console_cmd__fed__state(const string_view &line) request }; - out << string_view{response} << std::endl; + const json::array &auth_chain + { + response["auth_chain"] + }; + + const json::array &pdus + { + response["pdus"] + }; + + if(op != "eval") + { + for(const json::object &event : auth_chain) + out << pretty_oneline(m::event{event}) << std::endl; + + for(const json::object &event : pdus) + out << pretty_oneline(m::event{event}) << std::endl; + + return true; + } + + m::vm::opts vmopts; + vmopts.non_conform.set(m::event::conforms::MISSING_PREV_STATE); + vmopts.non_conform.set(m::event::conforms::MISSING_MEMBERSHIP); + vmopts.prev_check_exists = false; + vmopts.notify = false; + m::vm::eval eval + { + vmopts + }; + + for(const json::object &event : auth_chain) + eval(event); + + for(const json::object &event : pdus) + eval(event); + return true; }