diff --git a/modules/console.cc b/modules/console.cc index 6ae9309e8..f28670dcd 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -4574,41 +4574,21 @@ console_cmd__event__fetch(opt &out, const string_view &line) m::room_id(param.at("room_id")) }; - const unique_buffer buf + const net::hostport hostport { - 64_KiB + room_id.host() }; using prototype = json::object (const m::room::id &, const m::event::id &, - const mutable_buffer &); + const net::hostport &); static mods::import acquire { - "vm_fetch", "acquire" + "vm_fetch", "state_fetch" }; - const m::event event - { - acquire(room_id, event_id, buf) - }; - - 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.head_must_exist = false; - vmopts.history = false; - vmopts.notify = false; - vmopts.verify = false; - m::vm::eval eval - { - vmopts - }; - - eval(event); - - out << event << std::endl; + acquire(room_id, event_id, hostport); return true; } diff --git a/modules/vm.cc b/modules/vm.cc index 69a352b4c..1b46a016d 100644 --- a/modules/vm.cc +++ b/modules/vm.cc @@ -10,7 +10,6 @@ namespace ircd::m::vm { - extern hook::site commit_hook; ///< Called when this server issues event extern hook::site fetch_hook; ///< Called to resolve dependencies extern hook::site eval_hook; ///< Called when evaluating event diff --git a/modules/vm_fetch.cc b/modules/vm_fetch.cc index 0f9cb5f20..c03dec26d 100644 --- a/modules/vm_fetch.cc +++ b/modules/vm_fetch.cc @@ -130,77 +130,9 @@ m::vm::fetch::enter(const event &event, // API interface // -json::object -m::vm::fetch::acquire(const m::room::id &room_id, - const m::event::id &event_id, - const mutable_buffer &buf) -{ - auto &request - { - _fetch(room_id, event_id) - }; - - request.dock.wait([&request] - { - return request.finished; - }); - - const unwind _remove_{[&event_id] - { - remove(event_id); - }}; - - if(request.eptr) - std::rethrow_exception(request.eptr); - - const json::object &event - { - request - }; - - return json::object - { - data(buf), copy(buf, event) - }; -} - -bool -m::vm::fetch::prefetch(const m::room::id &room_id, - const m::event::id &event_id) -{ - _fetch(room_id, event_id); - return true; -} - -bool -ircd::m::vm::fetch::remove(const m::event::id &event_id) -{ - const auto it - { - fetching.find(event_id) - }; - - if(it == end(fetching)) - return false; - - const request &r{*it}; - if(!r.dock.empty()) - return false; - - for(auto it(begin(fetched)); it != end(fetched); ++it) - if(*it == &r) - { - fetched.erase(it); - break; - } - - fetching.erase(it); - return true; -} - m::vm::fetch::request & -m::vm::fetch::_fetch(const m::room::id &room_id, - const m::event::id &event_id) +m::vm::fetch::fetch(const m::room::id &room_id, + const m::event::id &event_id) { auto it { @@ -232,9 +164,6 @@ m::vm::fetch::dock; decltype(m::vm::fetch::fetching) m::vm::fetch::fetching; -decltype(m::vm::fetch::fetched) -m::vm::fetch::fetched; - /// The fetch context is an internal worker which drives the fetch process /// and then indicates completion to anybody waiting on a fetch. This involves /// handling errors/timeouts from a fetch attempt and retrying with another @@ -381,6 +310,10 @@ ircd::m::vm::fetch::request::select_random_origin() const auto proffer{[this] (const string_view &origin) { + // Don't want to request from myself. + if(my_host(origin)) + return false; + // Don't want to use a peer we already tried and failed with. if(attempted.count(origin)) return false; @@ -456,7 +389,6 @@ void ircd::m::vm::fetch::request::finish() { finished = ircd::time(); - fetched.emplace_back(this); dock.notify_all(); } diff --git a/modules/vm_fetch.int.h b/modules/vm_fetch.int.h index bdd6781af..a4c45ef42 100644 --- a/modules/vm_fetch.int.h +++ b/modules/vm_fetch.int.h @@ -26,7 +26,6 @@ namespace ircd::m::vm::fetch extern ctx::dock dock; extern std::set fetching; - extern std::deque fetched; extern hookfn hook; extern ctx::context context; @@ -35,13 +34,8 @@ namespace ircd::m::vm::fetch static bool handle(); static void worker(); - // interface stack - static request &_fetch(const m::room::id &, const m::event::id &); - static bool remove(const m::event::id &); - extern "C" bool prefetch(const m::room::id &, const m::event::id &); - extern "C" json::object acquire(const m::room::id &, const m::event::id &, const mutable_buffer &); + static request &fetch(const m::room::id &, const m::event::id &); - // phase stack static void enter(const event &, vm::eval &); }