From 53ea7b865823d5889a2dc275ca6a1a2a6a4b442a Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 22 Jun 2019 19:13:40 -0700 Subject: [PATCH] ircd::m::feds: Add send operation to feds suite. modules/console: Update console for feds resend. --- include/ircd/m/feds.h | 1 + modules/console.cc | 52 ++++++++++++++++++++++++++++++++++--------- modules/s_feds.cc | 27 ++++++++++++++++++++++ 3 files changed, 69 insertions(+), 11 deletions(-) diff --git a/include/ircd/m/feds.h b/include/ircd/m/feds.h index ceb5bd946..33d2108ff 100644 --- a/include/ircd/m/feds.h +++ b/include/ircd/m/feds.h @@ -100,4 +100,5 @@ enum class ircd::m::feds::op backfill, version, keys, + send, }; diff --git a/modules/console.cc b/modules/console.cc index 97f85b13d..2934baf5b 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -11297,7 +11297,7 @@ console_cmd__feds__backfill(opt &out, const string_view &line) } bool -console_cmd__feds__resend(opt &out, const string_view &line) +console_cmd__feds__send(opt &out, const string_view &line) { const params param{line, " ", { @@ -11314,19 +11314,49 @@ console_cmd__feds__resend(opt &out, const string_view &line) event_id }; - m::vm::opts opts; - opts.replays = true; - opts.conforming = false; - opts.fetch = false; - opts.eval = false; - opts.write = false; - opts.effects = false; - opts.notify = true; - m::vm::eval + const json::value event_json { - m::event{event}, opts + event.source }; + const m::txn::array pduv + { + &event_json, 1 + }; + + const std::string content + { + m::txn::create(pduv) + }; + + char txnidbuf[64]; + const auto txnid + { + m::txn::create_id(txnidbuf, content) + }; + + m::feds::opts opts; + opts.op = m::feds::op::send; + opts.room_id = at<"room_id"_>(event); + opts.arg[0] = txnid; + opts.arg[1] = content; + m::feds::acquire(opts, [&out] + (const auto &result) + { + out << (result.eptr? '-' : '+') + << " " + << std::setw(40) << std::left << result.origin + << " "; + + if(result.eptr) + out << what(result.eptr); + else + out << string_view{result.object}; + + out << std::endl; + return true; + }); + return true; } diff --git a/modules/s_feds.cc b/modules/s_feds.cc index d640b219f..38aaf9dda 100644 --- a/modules/s_feds.cc +++ b/modules/s_feds.cc @@ -35,6 +35,7 @@ namespace ircd::m::feds static request_list backfill(const opts &, const closure &); static request_list version(const opts &, const closure &); static request_list keys(const opts &, const closure &); + static request_list send(const opts &, const closure &); bool execute(const vector_view &opts, const closure &closure); } @@ -135,6 +136,10 @@ ircd::m::feds::execute(const vector_view &optsv, list.splice(list.end(), keys(opts, closure)); continue; + case op::send: + list.splice(list.end(), send(opts, closure)); + continue; + case op::noop: continue; } @@ -147,6 +152,28 @@ ircd::m::feds::execute(const vector_view &optsv, return handler(list, timeout, closure); } +ircd::m::feds::request_list +ircd::m::feds::send(const opts &opts, + const closure &closure) +{ + const auto make_request{[&opts] + (auto &request, const auto &origin) + { + m::v1::send::opts v1opts; + v1opts.remote = string_view + { + strlcpy{request.origin, origin} + }; + + return m::v1::send + { + opts.arg[0], opts.arg[1], request.buf, std::move(v1opts) + }; + }}; + + return creator(opts, make_request); +} + ircd::m::feds::request_list ircd::m::feds::keys(const opts &opts, const closure &closure)