From f6314a420193a6e9a01f1892e5da97af29a34d03 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 22 Apr 2019 12:32:54 -0700 Subject: [PATCH] modules/s_fetch: Minor reorg; pass room arg to fetch::synchronize(). --- include/ircd/m/fetch.h | 2 +- ircd/m.cc | 6 ++-- modules/console.cc | 49 ++++++++++++++++++++++++------ modules/s_fetch.cc | 69 +++++++++++++++++++++++------------------- 4 files changed, 82 insertions(+), 44 deletions(-) diff --git a/include/ircd/m/fetch.h b/include/ircd/m/fetch.h index 6c3bd4bdb..cb2f1aafd 100644 --- a/include/ircd/m/fetch.h +++ b/include/ircd/m/fetch.h @@ -27,7 +27,7 @@ namespace ircd::m::fetch bool cancel(request &); bool start(const m::room::id &, const m::event::id &); bool prefetch(const m::room::id &, const m::event::id &); - bool synchronize(const m::room::id &); + bool synchronize(const m::room &); // Composed operations void auth_chain(const room &, const net::hostport &); diff --git a/ircd/m.cc b/ircd/m.cc index a7ad0b89a..903567b22 100644 --- a/ircd/m.cc +++ b/ircd/m.cc @@ -469,16 +469,16 @@ ircd::m::fetch::auth_chain(const room &r, } bool -ircd::m::fetch::synchronize(const m::room::id &room_id) +ircd::m::fetch::synchronize(const m::room &room) { - using prototype = bool (const m::room::id &); + using prototype = bool (const m::room &); static mods::import call { "s_fetch", "ircd::m::fetch::synchronize" }; - return call(room_id); + return call(room); } bool diff --git a/modules/console.cc b/modules/console.cc index edd752403..a10fbc67c 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -12528,19 +12528,50 @@ console_cmd__fetch(opt &out, const string_view &line) m::room_id(param.at("room_id")) }; - if(!param["event_id"]) - { - m::fetch::synchronize(room_id); - out << "done" << std::endl; - return true; - } - const m::event::id event_id { param.at("event_id") }; - m::fetch::start(room_id, event_id); - out << "in work..." << std::endl; + if(!m::fetch::start(room_id, event_id)) + { + out << "failed to start." << std::endl; + return true; + } + + out << "starting..." << std::endl; + return true; +} + +bool +console_cmd__fetch__sync(opt &out, const string_view &line) +{ + const params param{line, " ", + { + "room_id", "event_id" + }}; + + const auto room_id + { + m::room_id(param.at("room_id")) + }; + + const string_view &event_id + { + param["event_id"] + }; + + const m::room room + { + room_id, event_id + }; + + if(!m::fetch::synchronize(room)) + { + out << "failed to start." << std::endl; + return true; + } + + out << "done." << std::endl; return true; } diff --git a/modules/s_fetch.cc b/modules/s_fetch.cc index baca08518..7ed35344f 100644 --- a/modules/s_fetch.cc +++ b/modules/s_fetch.cc @@ -64,6 +64,29 @@ ircd::m::fetch::requests; decltype(ircd::m::fetch::dock) ircd::m::fetch::dock; +// +// init +// + +void +ircd::m::fetch::init() +{ +} + +void +ircd::m::fetch::fini() +{ + request_context.terminate(); + eval_context.terminate(); + request_context.join(); + eval_context.join(); + requests.clear(); + complete.clear(); + + assert(requests.empty()); + assert(complete.empty()); +} + /////////////////////////////////////////////////////////////////////////////// // // m/fetch.h @@ -76,6 +99,20 @@ namespace ircd::m::fetch static void handle_state_ids(const m::room &, const m::feds::result &); } +bool +IRCD_MODULE_EXPORT +ircd::m::fetch::synchronize(const m::room &room) +{ + m::feds::opts opts; + opts.op = m::feds::op::head; + opts.room_id = room.room_id; + opts.event_id = room.event_id; + opts.nothrow_closure = true; + opts.closure_errors = false; + + return true; +} + void IRCD_MODULE_EXPORT ircd::m::fetch::state_ids(const room &room) @@ -136,6 +173,7 @@ ircd::m::fetch::_heads(const m::feds::opts &opts_) { auto opts(opts_); opts.op = m::feds::op::head; + std::map heads; m::feds::acquire(opts, [&heads] (const auto &result) @@ -251,13 +289,6 @@ ircd::m::fetch::auth_chain(const room &room, }; } -bool -IRCD_MODULE_EXPORT -ircd::m::fetch::synchronize(const m::room::id &room_id) -{ - return true; -} - bool IRCD_MODULE_EXPORT ircd::m::fetch::prefetch(const m::room::id &room_id, @@ -308,30 +339,6 @@ ircd::m::fetch::for_each(const std::function &closure) // s_fetch.h // -// -// init -// - -void -ircd::m::fetch::init() -{ - -} - -void -ircd::m::fetch::fini() -{ - request_context.terminate(); - eval_context.terminate(); - request_context.join(); - eval_context.join(); - requests.clear(); - complete.clear(); - - assert(requests.empty()); - assert(complete.empty()); -} - // // fetch_phase //