2018-02-04 03:22:01 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
2017-11-16 02:37:09 +01:00
|
|
|
|
2018-05-07 06:15:25 +02:00
|
|
|
namespace ircd::m::vm
|
2017-11-16 02:37:09 +01:00
|
|
|
{
|
2019-04-30 23:08:00 +02:00
|
|
|
template<class... args> static fault handle_error(const opts &, const fault &, const string_view &fmt, args&&... a);
|
2019-07-06 06:33:58 +02:00
|
|
|
template<class T> static void call_hook(hook::site<T> &, eval &, const event &, T&& data);
|
2019-04-30 23:08:00 +02:00
|
|
|
static size_t calc_txn_reserve(const opts &, const event &);
|
2019-03-21 22:13:45 +01:00
|
|
|
static void write_commit(eval &);
|
|
|
|
static void write_append(eval &, const event &);
|
|
|
|
static void write_prepare(eval &, const event &);
|
2019-03-21 23:00:58 +01:00
|
|
|
static fault execute_edu(eval &, const event &);
|
|
|
|
static fault execute_pdu(eval &, const event &);
|
2020-03-20 20:44:23 +01:00
|
|
|
static fault execute_du(eval &, const event &);
|
2019-07-17 21:15:17 +02:00
|
|
|
static fault inject3(eval &, json::iov &, const json::iov &);
|
|
|
|
static fault inject1(eval &, json::iov &, const json::iov &);
|
2018-05-07 06:15:25 +02:00
|
|
|
static void fini();
|
2019-05-26 10:48:27 +02:00
|
|
|
static void init();
|
2019-03-01 01:53:03 +01:00
|
|
|
|
2019-03-09 22:12:58 +01:00
|
|
|
extern hook::site<eval &> issue_hook; ///< Called when this server is issuing event
|
|
|
|
extern hook::site<eval &> conform_hook; ///< Called for static evaluations of event
|
2019-05-27 05:57:55 +02:00
|
|
|
extern hook::site<eval &> access_hook; ///< Called for access control checking
|
2019-03-09 21:08:05 +01:00
|
|
|
extern hook::site<eval &> fetch_hook; ///< Called to resolve dependencies
|
2019-03-09 22:12:58 +01:00
|
|
|
extern hook::site<eval &> eval_hook; ///< Called for final event evaluation
|
2019-03-09 21:08:05 +01:00
|
|
|
extern hook::site<eval &> post_hook; ///< Called to apply effects pre-notify
|
|
|
|
extern hook::site<eval &> notify_hook; ///< Called to broadcast successful eval
|
|
|
|
extern hook::site<eval &> effect_hook; ///< Called to apply effects post-notify
|
2019-03-01 01:53:03 +01:00
|
|
|
|
2019-03-16 20:38:14 +01:00
|
|
|
extern conf::item<bool> log_commit_debug;
|
2019-03-01 01:53:03 +01:00
|
|
|
extern conf::item<bool> log_accept_debug;
|
|
|
|
extern conf::item<bool> log_accept_info;
|
2018-04-16 23:21:54 +02:00
|
|
|
}
|
|
|
|
|
2019-03-16 20:38:14 +01:00
|
|
|
decltype(ircd::m::vm::log_commit_debug)
|
|
|
|
ircd::m::vm::log_commit_debug
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.vm.log.commit.debug" },
|
|
|
|
{ "default", true },
|
|
|
|
};
|
|
|
|
|
2019-03-01 01:53:03 +01:00
|
|
|
decltype(ircd::m::vm::log_accept_debug)
|
|
|
|
ircd::m::vm::log_accept_debug
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.vm.log.accept.debug" },
|
2019-10-03 18:26:18 +02:00
|
|
|
{ "default", true },
|
2019-03-01 01:53:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::vm::log_accept_info)
|
|
|
|
ircd::m::vm::log_accept_info
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.vm.log.accept.info" },
|
|
|
|
{ "default", false },
|
|
|
|
};
|
|
|
|
|
2019-03-09 21:13:21 +01:00
|
|
|
decltype(ircd::m::vm::issue_hook)
|
|
|
|
ircd::m::vm::issue_hook
|
2018-05-07 01:04:51 +02:00
|
|
|
{
|
2019-03-09 21:13:21 +01:00
|
|
|
{ "name", "vm.issue" }
|
2018-05-07 01:04:51 +02:00
|
|
|
};
|
|
|
|
|
2019-03-09 22:12:58 +01:00
|
|
|
decltype(ircd::m::vm::conform_hook)
|
|
|
|
ircd::m::vm::conform_hook
|
|
|
|
{
|
|
|
|
{ "name", "vm.conform" }
|
|
|
|
};
|
|
|
|
|
2019-05-27 05:57:55 +02:00
|
|
|
decltype(ircd::m::vm::access_hook)
|
|
|
|
ircd::m::vm::access_hook
|
|
|
|
{
|
|
|
|
{ "name", "vm.access" }
|
|
|
|
};
|
|
|
|
|
2018-09-06 10:21:37 +02:00
|
|
|
decltype(ircd::m::vm::fetch_hook)
|
|
|
|
ircd::m::vm::fetch_hook
|
|
|
|
{
|
|
|
|
{ "name", "vm.fetch" }
|
|
|
|
};
|
|
|
|
|
2018-05-07 01:04:51 +02:00
|
|
|
decltype(ircd::m::vm::eval_hook)
|
|
|
|
ircd::m::vm::eval_hook
|
|
|
|
{
|
|
|
|
{ "name", "vm.eval" }
|
|
|
|
};
|
|
|
|
|
2019-03-09 21:08:05 +01:00
|
|
|
decltype(ircd::m::vm::post_hook)
|
|
|
|
ircd::m::vm::post_hook
|
|
|
|
{
|
|
|
|
{ "name", "vm.post" }
|
|
|
|
};
|
|
|
|
|
2018-05-07 01:04:51 +02:00
|
|
|
decltype(ircd::m::vm::notify_hook)
|
|
|
|
ircd::m::vm::notify_hook
|
|
|
|
{
|
2019-07-20 05:12:05 +02:00
|
|
|
{ "name", "vm.notify" },
|
|
|
|
{ "exceptions", false },
|
2018-05-07 01:04:51 +02:00
|
|
|
};
|
|
|
|
|
2018-10-07 07:17:46 +02:00
|
|
|
decltype(ircd::m::vm::effect_hook)
|
|
|
|
ircd::m::vm::effect_hook
|
|
|
|
{
|
2019-07-20 05:12:05 +02:00
|
|
|
{ "name", "vm.effect" },
|
|
|
|
{ "exceptions", false },
|
2018-10-07 07:17:46 +02:00
|
|
|
};
|
|
|
|
|
2018-05-07 02:07:18 +02:00
|
|
|
//
|
2019-10-03 19:51:29 +02:00
|
|
|
// execute
|
2018-05-07 06:15:25 +02:00
|
|
|
//
|
2018-05-07 01:04:51 +02:00
|
|
|
|
2019-10-03 19:51:29 +02:00
|
|
|
ircd::m::vm::fault
|
2019-03-21 23:00:58 +01:00
|
|
|
ircd::m::vm::execute(eval &eval,
|
|
|
|
const event &event)
|
2020-03-26 18:24:35 +01:00
|
|
|
try
|
2017-11-30 20:01:14 +01:00
|
|
|
{
|
2019-09-09 21:53:34 +02:00
|
|
|
// This assertion is tripped if the end of your context's stack is
|
|
|
|
// danger close; try increasing your stack size.
|
|
|
|
const ctx::stack_usage_assertion sua;
|
|
|
|
|
2019-03-21 23:58:18 +01:00
|
|
|
// m::vm bookkeeping that someone entered this function
|
2019-09-09 21:53:34 +02:00
|
|
|
const scope_count executing
|
|
|
|
{
|
|
|
|
eval::executing
|
|
|
|
};
|
|
|
|
|
|
|
|
const scope_notify notify
|
|
|
|
{
|
|
|
|
vm::dock
|
|
|
|
};
|
2019-03-21 23:58:18 +01:00
|
|
|
|
2020-03-20 20:44:23 +01:00
|
|
|
assert(eval.opts);
|
|
|
|
const auto &opts
|
2019-09-14 00:27:02 +02:00
|
|
|
{
|
2020-03-20 20:44:23 +01:00
|
|
|
*eval.opts
|
2019-09-14 00:27:02 +02:00
|
|
|
};
|
|
|
|
|
2019-07-17 21:15:17 +02:00
|
|
|
// Set a member to the room_id for convenient access, without stepping on
|
|
|
|
// any room_id reference that exists there for whatever reason.
|
2019-07-10 11:14:38 +02:00
|
|
|
const scope_restore eval_room_id
|
|
|
|
{
|
|
|
|
eval.room_id,
|
|
|
|
eval.room_id?
|
|
|
|
eval.room_id:
|
2019-08-24 06:12:16 +02:00
|
|
|
valid(id::ROOM, json::get<"room_id"_>(event))?
|
|
|
|
string_view(json::get<"room_id"_>(event)):
|
|
|
|
eval.room_id,
|
2019-07-10 11:14:38 +02:00
|
|
|
};
|
|
|
|
|
2019-07-17 21:15:17 +02:00
|
|
|
// Procure the room version.
|
2019-07-25 23:02:25 +02:00
|
|
|
char room_version_buf[room::VERSION_MAX_SIZE];
|
2019-07-10 11:14:38 +02:00
|
|
|
const scope_restore eval_room_version
|
|
|
|
{
|
|
|
|
eval.room_version,
|
2019-07-17 21:15:17 +02:00
|
|
|
|
|
|
|
// The room version was supplied by the user in the options structure
|
|
|
|
// because they know better.
|
2019-07-10 11:14:38 +02:00
|
|
|
eval.opts->room_version?
|
|
|
|
eval.opts->room_version:
|
2019-07-17 21:15:17 +02:00
|
|
|
|
|
|
|
// The room version was already computed; probably by vm::inject().
|
|
|
|
eval.room_version?
|
|
|
|
eval.room_version:
|
|
|
|
|
|
|
|
// There's no room version because there's no room!
|
|
|
|
!eval.room_id?
|
|
|
|
string_view{}:
|
|
|
|
|
|
|
|
// Make a query for the room version into the stack buffer.
|
|
|
|
m::version(room_version_buf, room{eval.room_id}, std::nothrow)
|
2019-07-10 11:14:38 +02:00
|
|
|
};
|
|
|
|
|
2020-03-22 20:18:43 +01:00
|
|
|
// Query for whether the room apropos is an internal room.
|
|
|
|
const scope_restore room_internal
|
|
|
|
{
|
|
|
|
eval.room_internal,
|
|
|
|
eval.room_id?
|
|
|
|
m::internal(eval.room_id):
|
|
|
|
false
|
|
|
|
};
|
|
|
|
|
2020-03-20 20:44:23 +01:00
|
|
|
// We have to set the event_id in the event instance if it didn't come
|
|
|
|
// with the event JSON.
|
|
|
|
if(!opts.edu && !event.event_id)
|
|
|
|
const_cast<m::event &>(event).event_id = eval.room_version == "3"?
|
|
|
|
event::id{event::id::v3{eval.event_id, event}}:
|
|
|
|
event::id{event::id::v4{eval.event_id, event}};
|
|
|
|
|
|
|
|
// If we set the event_id in the event instance we have to unset
|
|
|
|
// it so other contexts don't see an invalid reference.
|
|
|
|
const unwind restore_event_id{[&event]
|
|
|
|
{
|
|
|
|
const_cast<m::event &>(event).event_id = json::get<"event_id"_>(event)?
|
|
|
|
event.event_id:
|
|
|
|
m::event::id{};
|
|
|
|
}};
|
|
|
|
|
|
|
|
// If the event is already being evaluated, wait here until the other
|
|
|
|
// evaluation is finished. If the other was successful, the exists()
|
|
|
|
// check will skip this, otherwise we have to try again here because
|
|
|
|
// this evaluator might be using different options/credentials.
|
|
|
|
if(likely(opts.unique) && event.event_id)
|
|
|
|
sequence::dock.wait([&event]
|
|
|
|
{
|
|
|
|
return eval::count(event.event_id) <= 1;
|
|
|
|
});
|
|
|
|
|
|
|
|
// We can elide a lot of grief here by not proceeding further and simply
|
|
|
|
// returning fault::EXISTS after an existence check. If we had to wait for
|
|
|
|
// a duplicate eval this check will indicate its success.
|
|
|
|
if(likely(!opts.replays && opts.nothrows & fault::EXISTS) && event.event_id)
|
|
|
|
if(m::exists(event.event_id))
|
|
|
|
return fault::EXISTS;
|
|
|
|
|
|
|
|
// Set a member pointer to the event currently being evaluated. This
|
|
|
|
// allows other parallel evals to have deep access to this eval. It also
|
|
|
|
// will be used to count this event as currently being evaluated.
|
|
|
|
assert(!eval.event_);
|
|
|
|
const scope_restore eval_event
|
|
|
|
{
|
|
|
|
eval.event_, &event
|
|
|
|
};
|
|
|
|
|
|
|
|
// Ensure the member pointer/buffer to the eval's event_id is set in case
|
|
|
|
// anything needs this to be in sync with event.event_id. This may be also
|
|
|
|
// be used to onsider this event as currently being evaluated.
|
|
|
|
const scope_restore<event::id> eval_event_id
|
|
|
|
{
|
|
|
|
eval.event_id,
|
|
|
|
event.event_id?
|
|
|
|
event.event_id:
|
|
|
|
eval.event_id
|
|
|
|
};
|
|
|
|
|
2020-03-26 01:11:39 +01:00
|
|
|
return execute_du(eval, event);
|
|
|
|
}
|
2020-03-26 18:24:35 +01:00
|
|
|
catch(const vm::error &e)
|
|
|
|
{
|
|
|
|
throw; // propagate from execute_du
|
|
|
|
}
|
|
|
|
catch(const m::error &e)
|
|
|
|
{
|
|
|
|
const json::object &content
|
|
|
|
{
|
|
|
|
e.content
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(eval.opts);
|
|
|
|
return handle_error
|
|
|
|
(
|
|
|
|
*eval.opts, fault::GENERAL,
|
|
|
|
"eval %s %s :%s :%s :%s",
|
|
|
|
event.event_id?
|
|
|
|
string_view{event.event_id}:
|
|
|
|
"<unknown>"_sv,
|
|
|
|
json::get<"room_id"_>(event)?
|
|
|
|
string_view{json::get<"room_id"_>(event)}:
|
|
|
|
"<unknown>"_sv,
|
|
|
|
e.what(),
|
|
|
|
json::string{content["errcode"]},
|
|
|
|
json::string{content["error"]}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
catch(const ctx::interrupted &e)
|
|
|
|
{
|
|
|
|
assert(eval.opts);
|
|
|
|
return handle_error
|
|
|
|
(
|
|
|
|
*eval.opts, fault::INTERRUPT,
|
|
|
|
"eval %s %s :%s",
|
|
|
|
event.event_id?
|
|
|
|
string_view{event.event_id}:
|
|
|
|
"<unknown>"_sv,
|
|
|
|
json::get<"room_id"_>(event)?
|
|
|
|
string_view{json::get<"room_id"_>(event)}:
|
|
|
|
"<unknown>"_sv,
|
|
|
|
e.what()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
assert(eval.opts);
|
|
|
|
return handle_error
|
|
|
|
(
|
|
|
|
*eval.opts, fault::GENERAL,
|
|
|
|
"eval %s %s (General Protection) :%s",
|
|
|
|
event.event_id?
|
|
|
|
string_view{event.event_id}:
|
|
|
|
"<unknown>"_sv,
|
|
|
|
json::get<"room_id"_>(event)?
|
|
|
|
string_view{json::get<"room_id"_>(event)}:
|
|
|
|
"<unknown>"_sv,
|
|
|
|
e.what()
|
|
|
|
);
|
|
|
|
}
|
2020-03-26 01:11:39 +01:00
|
|
|
|
|
|
|
ircd::m::vm::fault
|
|
|
|
ircd::m::vm::execute_du(eval &eval,
|
|
|
|
const event &event)
|
|
|
|
try
|
|
|
|
{
|
|
|
|
assert(eval.id);
|
|
|
|
assert(eval.ctx);
|
|
|
|
assert(eval.opts);
|
2020-03-20 20:44:23 +01:00
|
|
|
assert(eval.opts->edu || event.event_id);
|
|
|
|
assert(eval.opts->edu || eval.event_id);
|
|
|
|
assert(eval.event_id == event.event_id);
|
|
|
|
assert(eval.event_);
|
2020-03-26 01:11:39 +01:00
|
|
|
const auto &opts
|
|
|
|
{
|
|
|
|
*eval.opts
|
|
|
|
};
|
2020-03-20 20:44:23 +01:00
|
|
|
|
2019-07-17 21:15:17 +02:00
|
|
|
// The issue hook is only called when this server is injecting a newly
|
|
|
|
// created event.
|
2019-03-09 22:12:58 +01:00
|
|
|
if(eval.copts && eval.copts->issue)
|
2019-07-06 06:33:58 +02:00
|
|
|
call_hook(issue_hook, eval, event, eval);
|
2019-03-09 22:12:58 +01:00
|
|
|
|
2019-07-17 21:15:17 +02:00
|
|
|
// Branch on whether the event is an EDU or a PDU
|
2018-03-13 03:07:41 +01:00
|
|
|
const fault ret
|
|
|
|
{
|
2019-07-06 06:09:07 +02:00
|
|
|
event.event_id?
|
2019-03-21 23:00:58 +01:00
|
|
|
execute_pdu(eval, event):
|
|
|
|
execute_edu(eval, event)
|
2018-03-13 03:07:41 +01:00
|
|
|
};
|
|
|
|
|
2019-07-17 21:15:17 +02:00
|
|
|
// ret can be a fault code if the user masked the exception from being
|
|
|
|
// thrown. If there's an error code here nothing further is done.
|
2018-03-13 03:07:41 +01:00
|
|
|
if(ret != fault::ACCEPT)
|
|
|
|
return ret;
|
2018-03-07 20:02:23 +01:00
|
|
|
|
2019-10-03 19:51:29 +02:00
|
|
|
if(opts.debuglog_accept || bool(log_accept_debug))
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "%s", pretty_oneline(event)
|
|
|
|
};
|
|
|
|
|
2019-07-17 21:15:17 +02:00
|
|
|
// The event was executed; now we broadcast the good news. This will
|
|
|
|
// include notifying client `/sync` and the federation sender.
|
2019-09-11 20:27:42 +02:00
|
|
|
if(likely(opts.notify))
|
2019-07-06 06:33:58 +02:00
|
|
|
call_hook(notify_hook, eval, event, eval);
|
2018-03-13 03:07:41 +01:00
|
|
|
|
2019-07-17 21:15:17 +02:00
|
|
|
// The "effects" of the event are created by listeners on the effect hook.
|
|
|
|
// These can include the creation of even more events, such as creating a
|
|
|
|
// PDU out of an EDU, etc. Unlike the post_hook in execute_pdu(), the
|
|
|
|
// notify for the event at issue here has already been made.
|
2019-09-11 20:27:42 +02:00
|
|
|
if(likely(opts.effects))
|
2019-07-06 06:33:58 +02:00
|
|
|
call_hook(effect_hook, eval, event, eval);
|
2018-03-13 03:07:41 +01:00
|
|
|
|
2019-09-11 20:27:42 +02:00
|
|
|
if(opts.infolog_accept || bool(log_accept_info))
|
|
|
|
log::info
|
2018-08-16 09:46:46 +02:00
|
|
|
{
|
|
|
|
log, "%s", pretty_oneline(event)
|
|
|
|
};
|
2018-03-13 03:07:41 +01:00
|
|
|
|
|
|
|
return ret;
|
2018-03-07 20:02:23 +01:00
|
|
|
}
|
2020-03-04 04:31:21 +01:00
|
|
|
catch(const vm::error &e) // VM FAULT CODE
|
2018-03-07 20:02:23 +01:00
|
|
|
{
|
2020-03-04 04:31:21 +01:00
|
|
|
const json::object &content{e.content};
|
|
|
|
const json::string &error
|
|
|
|
{
|
|
|
|
content["error"]
|
|
|
|
};
|
|
|
|
|
2020-03-26 18:24:35 +01:00
|
|
|
return handle_error
|
|
|
|
(
|
|
|
|
*eval.opts, e.code,
|
|
|
|
"execute %s %s :%s",
|
2020-03-04 04:31:21 +01:00
|
|
|
event.event_id?
|
|
|
|
string_view{event.event_id}:
|
2020-03-26 18:24:35 +01:00
|
|
|
"<edu>"_sv,
|
2020-03-04 04:31:21 +01:00
|
|
|
eval.room_id?
|
|
|
|
eval.room_id:
|
|
|
|
"<edu>"_sv,
|
|
|
|
error
|
2018-12-10 22:03:15 +01:00
|
|
|
);
|
2018-03-07 20:02:23 +01:00
|
|
|
}
|
2018-05-15 07:24:03 +02:00
|
|
|
catch(const m::error &e) // GENERAL MATRIX ERROR
|
2018-04-13 08:06:02 +02:00
|
|
|
{
|
2020-03-04 04:31:21 +01:00
|
|
|
const json::object &content{e.content};
|
|
|
|
const json::string error[]
|
|
|
|
{
|
|
|
|
content["errcode"],
|
|
|
|
content["error"]
|
|
|
|
};
|
|
|
|
|
2020-03-26 18:24:35 +01:00
|
|
|
return handle_error
|
|
|
|
(
|
|
|
|
*eval.opts, fault::GENERAL,
|
|
|
|
"execute %s %s :%s :%s :%s",
|
2020-03-04 04:31:21 +01:00
|
|
|
event.event_id?
|
|
|
|
string_view{event.event_id}:
|
2020-03-26 18:24:35 +01:00
|
|
|
"<edu>"_sv,
|
2020-03-04 04:31:21 +01:00
|
|
|
eval.room_id?
|
|
|
|
eval.room_id:
|
|
|
|
"<edu>"_sv,
|
2018-12-10 22:03:15 +01:00
|
|
|
e.what(),
|
2020-03-04 04:31:21 +01:00
|
|
|
error[0],
|
|
|
|
error[1]
|
2018-12-10 22:03:15 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
catch(const ctx::interrupted &e) // INTERRUPTION
|
|
|
|
{
|
2020-03-26 18:24:35 +01:00
|
|
|
return handle_error
|
|
|
|
(
|
|
|
|
*eval.opts, fault::INTERRUPT,
|
|
|
|
"execute %s %s :%s",
|
2020-03-04 04:31:21 +01:00
|
|
|
event.event_id?
|
|
|
|
string_view{event.event_id}:
|
2020-03-26 18:24:35 +01:00
|
|
|
"<edu>"_sv,
|
2020-03-04 04:31:21 +01:00
|
|
|
eval.room_id?
|
|
|
|
eval.room_id:
|
|
|
|
"<edu>"_sv,
|
2018-12-10 22:03:15 +01:00
|
|
|
e.what()
|
|
|
|
);
|
2018-04-13 08:06:02 +02:00
|
|
|
}
|
2018-05-15 07:24:03 +02:00
|
|
|
catch(const std::exception &e) // ALL OTHER ERRORS
|
2018-03-07 20:02:23 +01:00
|
|
|
{
|
2020-03-26 18:24:35 +01:00
|
|
|
return handle_error
|
|
|
|
(
|
|
|
|
*eval.opts, fault::GENERAL,
|
|
|
|
"execute %s %s (General Protection) :%s",
|
2020-03-04 04:31:21 +01:00
|
|
|
event.event_id?
|
|
|
|
string_view{event.event_id}:
|
2020-03-26 18:24:35 +01:00
|
|
|
"<edu>"_sv,
|
2020-03-04 04:31:21 +01:00
|
|
|
eval.room_id?
|
|
|
|
eval.room_id:
|
|
|
|
"<edu>"_sv,
|
2018-12-10 22:03:15 +01:00
|
|
|
e.what()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-10-03 19:51:29 +02:00
|
|
|
ircd::m::vm::fault
|
2019-03-21 23:00:58 +01:00
|
|
|
ircd::m::vm::execute_edu(eval &eval,
|
2019-07-06 06:33:58 +02:00
|
|
|
const event &event)
|
2018-03-07 20:02:23 +01:00
|
|
|
{
|
2019-09-15 01:29:27 +02:00
|
|
|
if(likely(eval.opts->eval))
|
2019-07-06 06:33:58 +02:00
|
|
|
call_hook(eval_hook, eval, event, eval);
|
2018-10-11 10:18:21 +02:00
|
|
|
|
2019-09-15 01:29:27 +02:00
|
|
|
if(likely(eval.opts->post))
|
2019-07-06 06:33:58 +02:00
|
|
|
call_hook(post_hook, eval, event, eval);
|
2019-04-07 03:18:17 +02:00
|
|
|
|
2018-03-07 20:02:23 +01:00
|
|
|
return fault::ACCEPT;
|
|
|
|
}
|
|
|
|
|
2019-10-03 19:51:29 +02:00
|
|
|
ircd::m::vm::fault
|
2019-03-21 23:00:58 +01:00
|
|
|
ircd::m::vm::execute_pdu(eval &eval,
|
2019-03-29 00:00:54 +01:00
|
|
|
const event &event)
|
2018-03-07 20:02:23 +01:00
|
|
|
{
|
2019-03-21 23:58:18 +01:00
|
|
|
const scope_count pending
|
|
|
|
{
|
|
|
|
sequence::pending
|
|
|
|
};
|
|
|
|
|
2019-03-30 23:18:22 +01:00
|
|
|
const scope_restore remove_txn
|
|
|
|
{
|
|
|
|
eval.txn, std::shared_ptr<db::txn>{}
|
|
|
|
};
|
|
|
|
|
2019-09-09 21:16:48 +02:00
|
|
|
const scope_notify sequence_dock
|
|
|
|
{
|
|
|
|
sequence::dock, scope_notify::all
|
|
|
|
};
|
|
|
|
|
2018-03-07 20:02:23 +01:00
|
|
|
assert(eval.opts);
|
|
|
|
const auto &opts
|
|
|
|
{
|
|
|
|
*eval.opts
|
|
|
|
};
|
|
|
|
|
2018-02-28 07:53:44 +01:00
|
|
|
const m::event::id &event_id
|
2017-11-16 02:37:09 +01:00
|
|
|
{
|
2019-07-06 06:09:07 +02:00
|
|
|
event.event_id
|
2017-11-16 02:37:09 +01:00
|
|
|
};
|
|
|
|
|
2018-02-28 07:53:44 +01:00
|
|
|
const m::room::id &room_id
|
2017-11-16 02:37:09 +01:00
|
|
|
{
|
2018-02-28 07:53:44 +01:00
|
|
|
at<"room_id"_>(event)
|
2018-02-08 22:23:01 +01:00
|
|
|
};
|
2017-11-16 02:37:09 +01:00
|
|
|
|
2018-09-05 08:28:01 +02:00
|
|
|
const string_view &type
|
|
|
|
{
|
|
|
|
at<"type"_>(event)
|
|
|
|
};
|
|
|
|
|
2019-09-17 01:28:55 +02:00
|
|
|
const bool authenticate
|
|
|
|
{
|
2020-03-22 01:23:08 +01:00
|
|
|
opts.auth && !eval.room_internal
|
2019-09-17 01:28:55 +02:00
|
|
|
};
|
|
|
|
|
2019-09-13 22:35:30 +02:00
|
|
|
// The conform hook runs static checks on an event's formatting and
|
|
|
|
// composure; these checks only require the event data itself.
|
|
|
|
if(likely(opts.conform))
|
|
|
|
{
|
|
|
|
const ctx::critical_assertion ca;
|
|
|
|
call_hook(conform_hook, eval, event, eval);
|
|
|
|
}
|
|
|
|
|
2020-03-22 01:23:08 +01:00
|
|
|
if(unlikely(eval.room_internal && !my(event)))
|
2019-09-24 23:28:03 +02:00
|
|
|
throw error
|
|
|
|
{
|
|
|
|
fault::GENERAL, "Internal room event denied from external source."
|
|
|
|
};
|
|
|
|
|
2020-03-13 19:42:49 +01:00
|
|
|
// Wait for any pending duplicate evals before proceeding.
|
|
|
|
assert(eval::count(event_id));
|
2020-03-17 19:21:27 +01:00
|
|
|
if(likely(opts.unique))
|
|
|
|
sequence::dock.wait([&event_id]
|
|
|
|
{
|
|
|
|
return eval::count(event_id) <= 1;
|
|
|
|
});
|
2020-03-13 19:42:49 +01:00
|
|
|
|
2020-03-17 19:21:27 +01:00
|
|
|
if(likely(opts.unique) && unlikely(eval::count(event_id) > 1))
|
2019-09-11 22:08:59 +02:00
|
|
|
throw error
|
|
|
|
{
|
|
|
|
fault::EXISTS, "Event is already being evaluated."
|
|
|
|
};
|
|
|
|
|
2019-09-11 20:27:42 +02:00
|
|
|
if(likely(!opts.replays) && m::exists(event_id))
|
2018-02-28 07:53:44 +01:00
|
|
|
throw error
|
2018-02-09 08:21:15 +01:00
|
|
|
{
|
2018-02-28 07:53:44 +01:00
|
|
|
fault::EXISTS, "Event has already been evaluated."
|
2018-02-09 08:21:15 +01:00
|
|
|
};
|
|
|
|
|
2019-09-11 20:27:42 +02:00
|
|
|
if(likely(opts.access))
|
2019-07-06 06:33:58 +02:00
|
|
|
call_hook(access_hook, eval, event, eval);
|
2019-05-27 05:36:26 +02:00
|
|
|
|
2019-09-11 20:27:42 +02:00
|
|
|
if(likely(opts.verify) && !verify(event))
|
2019-04-28 05:01:27 +02:00
|
|
|
throw m::BAD_SIGNATURE
|
|
|
|
{
|
|
|
|
"Signature verification failed"
|
|
|
|
};
|
2018-03-22 09:31:17 +01:00
|
|
|
|
2018-10-31 19:37:40 +01:00
|
|
|
// Fetch dependencies
|
2019-09-11 20:27:42 +02:00
|
|
|
if(likely(opts.fetch))
|
2019-07-06 06:33:58 +02:00
|
|
|
call_hook(fetch_hook, eval, event, eval);
|
2018-04-17 02:28:26 +02:00
|
|
|
|
2019-08-17 15:37:43 +02:00
|
|
|
// Evaluation by auth system; throws
|
2019-09-17 01:28:55 +02:00
|
|
|
if(likely(authenticate))
|
|
|
|
room::auth::check_static(event);
|
2019-08-17 15:37:43 +02:00
|
|
|
|
2019-03-21 22:13:45 +01:00
|
|
|
// Obtain sequence number here.
|
|
|
|
const auto *const &top(eval::seqmax());
|
|
|
|
eval.sequence_shared[0] = 0;
|
|
|
|
eval.sequence_shared[1] = 0;
|
2019-06-02 02:03:17 +02:00
|
|
|
eval.sequence = 0;
|
2019-03-21 22:13:45 +01:00
|
|
|
eval.sequence =
|
2019-03-19 19:45:01 +01:00
|
|
|
{
|
2019-03-21 22:13:45 +01:00
|
|
|
top?
|
2019-03-19 19:45:01 +01:00
|
|
|
std::max(sequence::get(*top) + 1, sequence::committed + 1):
|
2019-03-21 22:13:45 +01:00
|
|
|
sequence::committed + 1
|
|
|
|
};
|
2019-03-19 19:45:01 +01:00
|
|
|
|
2019-09-17 01:42:22 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "%s | event sequenced", loghead(eval)
|
|
|
|
};
|
|
|
|
|
2019-09-17 01:28:55 +02:00
|
|
|
// Wait until this is the lowest sequence number
|
|
|
|
sequence::dock.wait([&eval]
|
|
|
|
{
|
|
|
|
return eval::seqnext(sequence::uncommitted) == &eval;
|
|
|
|
});
|
|
|
|
|
|
|
|
if(likely(authenticate))
|
|
|
|
room::auth::check_relative(event);
|
|
|
|
|
2019-03-21 22:13:45 +01:00
|
|
|
log::debug
|
|
|
|
{
|
2019-09-17 01:42:22 +02:00
|
|
|
log, "%s | event committing", loghead(eval)
|
2019-03-21 22:13:45 +01:00
|
|
|
};
|
2019-03-19 19:45:01 +01:00
|
|
|
|
2019-03-21 22:13:45 +01:00
|
|
|
assert(eval.sequence != 0);
|
|
|
|
assert(sequence::uncommitted <= sequence::get(eval));
|
|
|
|
assert(sequence::committed < sequence::get(eval));
|
|
|
|
assert(sequence::retired < sequence::get(eval));
|
|
|
|
assert(eval::sequnique(sequence::get(eval)));
|
|
|
|
sequence::uncommitted = sequence::get(eval);
|
2018-09-05 08:28:01 +02:00
|
|
|
|
2019-03-21 22:13:45 +01:00
|
|
|
// Wait until this is the lowest sequence number
|
|
|
|
sequence::dock.wait([&eval]
|
2019-03-19 19:45:01 +01:00
|
|
|
{
|
2019-03-21 22:13:45 +01:00
|
|
|
return eval::seqnext(sequence::committed) == &eval;
|
|
|
|
});
|
2019-03-19 19:45:01 +01:00
|
|
|
|
2019-09-17 01:28:55 +02:00
|
|
|
// Reevaluation of auth against the present state of the room.
|
|
|
|
if(likely(authenticate))
|
|
|
|
room::auth::check_present(event);
|
|
|
|
|
|
|
|
// Evaluation by module hooks
|
|
|
|
if(likely(opts.eval))
|
|
|
|
call_hook(eval_hook, eval, event, eval);
|
|
|
|
|
2019-03-21 22:13:45 +01:00
|
|
|
log::debug
|
|
|
|
{
|
2019-09-17 01:42:22 +02:00
|
|
|
log, "%s | event committed", loghead(eval)
|
2019-03-21 22:13:45 +01:00
|
|
|
};
|
2019-03-19 19:45:01 +01:00
|
|
|
|
2019-03-21 22:13:45 +01:00
|
|
|
assert(sequence::committed < sequence::get(eval));
|
|
|
|
assert(sequence::retired < sequence::get(eval));
|
|
|
|
sequence::committed = sequence::get(eval);
|
2019-09-17 01:28:55 +02:00
|
|
|
|
2019-09-11 20:27:42 +02:00
|
|
|
if(likely(opts.write))
|
2019-03-21 22:13:45 +01:00
|
|
|
write_prepare(eval, event);
|
2019-03-19 19:45:01 +01:00
|
|
|
|
2019-09-11 20:27:42 +02:00
|
|
|
if(likely(opts.write))
|
2019-03-21 22:13:45 +01:00
|
|
|
write_append(eval, event);
|
2019-03-20 02:02:35 +01:00
|
|
|
|
2019-03-21 22:13:45 +01:00
|
|
|
// Generate post-eval/pre-notify effects. This function may conduct
|
|
|
|
// an entire eval of several more events recursively before returning.
|
2019-09-11 20:27:42 +02:00
|
|
|
if(likely(opts.post))
|
2019-07-06 06:33:58 +02:00
|
|
|
call_hook(post_hook, eval, event, eval);
|
2018-12-31 02:02:19 +01:00
|
|
|
|
2019-03-21 22:13:45 +01:00
|
|
|
// Commit the transaction to database iff this eval is at the stack base.
|
2019-09-11 20:27:42 +02:00
|
|
|
if(likely(opts.write) && !eval.sequence_shared[0])
|
2019-03-21 22:13:45 +01:00
|
|
|
write_commit(eval);
|
2019-03-20 02:02:35 +01:00
|
|
|
|
2019-03-21 22:13:45 +01:00
|
|
|
// Wait for sequencing only if this is the stack base, otherwise we'll
|
|
|
|
// never return back to that stack base.
|
2019-09-11 20:27:42 +02:00
|
|
|
if(likely(!eval.sequence_shared[0]))
|
2019-03-20 02:02:35 +01:00
|
|
|
{
|
2019-03-19 19:45:01 +01:00
|
|
|
sequence::dock.wait([&eval]
|
|
|
|
{
|
|
|
|
return eval::seqnext(sequence::retired) == &eval;
|
|
|
|
});
|
|
|
|
|
|
|
|
log::debug
|
|
|
|
{
|
2019-03-21 22:13:45 +01:00
|
|
|
log, "%s | retire %lu:%lu",
|
|
|
|
loghead(eval),
|
2019-03-19 19:45:01 +01:00
|
|
|
sequence::get(eval),
|
2019-03-21 22:13:45 +01:00
|
|
|
eval.sequence_shared[1],
|
2019-03-19 19:45:01 +01:00
|
|
|
};
|
|
|
|
|
2019-03-21 22:13:45 +01:00
|
|
|
assert(sequence::retired < sequence::get(eval));
|
|
|
|
sequence::retired = std::max(eval.sequence_shared[1], sequence::get(eval));
|
2019-03-20 02:02:35 +01:00
|
|
|
}
|
2019-03-19 19:45:01 +01:00
|
|
|
|
2018-12-31 02:02:19 +01:00
|
|
|
return fault::ACCEPT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-03-21 22:13:45 +01:00
|
|
|
ircd::m::vm::write_prepare(eval &eval,
|
|
|
|
const event &event)
|
2018-12-31 02:02:19 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
assert(eval.opts);
|
2019-03-21 22:13:45 +01:00
|
|
|
const auto &opts{*eval.opts};
|
|
|
|
|
2019-03-29 00:22:19 +01:00
|
|
|
// Share a transaction with any other unretired evals on this stack. This
|
2019-03-21 22:13:45 +01:00
|
|
|
// should mean the bottom-most/lowest-sequence eval on this ctx.
|
|
|
|
const auto get_other_txn{[&eval]
|
|
|
|
(auto &other)
|
2018-12-31 02:02:19 +01:00
|
|
|
{
|
2019-03-29 00:22:19 +01:00
|
|
|
if(&other == &eval)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if(!other.txn)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if(sequence::get(other) <= sequence::retired)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
other.sequence_shared[1] = std::max(other.sequence_shared[1], sequence::get(eval));
|
|
|
|
eval.sequence_shared[0] = sequence::get(other);
|
|
|
|
eval.txn = other.txn;
|
|
|
|
return false;
|
2019-03-21 22:13:45 +01:00
|
|
|
}};
|
|
|
|
|
|
|
|
// If we broke from the iteration then this eval is sharing a transaction
|
|
|
|
// from another eval on this stack.
|
|
|
|
if(!eval.for_each(eval.ctx, get_other_txn))
|
|
|
|
return;
|
2018-09-05 08:28:01 +02:00
|
|
|
|
2019-03-21 22:13:45 +01:00
|
|
|
eval.txn = std::make_shared<db::txn>
|
|
|
|
(
|
2018-04-17 02:28:26 +02:00
|
|
|
*dbs::events, db::txn::opts
|
|
|
|
{
|
2019-04-30 23:08:00 +02:00
|
|
|
calc_txn_reserve(opts, event), // reserve_bytes
|
|
|
|
0, // max_bytes (no max)
|
2018-04-17 02:28:26 +02:00
|
|
|
}
|
2019-03-21 22:13:45 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::m::vm::write_append(eval &eval,
|
|
|
|
const event &event)
|
2018-04-17 02:28:26 +02:00
|
|
|
|
2019-03-21 22:13:45 +01:00
|
|
|
{
|
|
|
|
assert(eval.opts);
|
2020-03-04 04:53:14 +01:00
|
|
|
const auto &opts
|
|
|
|
{
|
|
|
|
*eval.opts
|
|
|
|
};
|
|
|
|
|
2019-03-21 22:13:45 +01:00
|
|
|
assert(eval.txn);
|
2020-03-04 04:53:14 +01:00
|
|
|
auto &txn
|
|
|
|
{
|
|
|
|
*eval.txn
|
|
|
|
};
|
2019-03-21 22:13:45 +01:00
|
|
|
|
2019-05-12 00:30:40 +02:00
|
|
|
m::dbs::write_opts wopts(opts.wopts);
|
2019-08-24 01:56:58 +02:00
|
|
|
wopts.event_idx = eval.sequence;
|
|
|
|
wopts.json_source = opts.json_source;
|
|
|
|
wopts.appendix.set(dbs::appendix::ROOM_STATE_SPACE, opts.history);
|
2020-03-04 04:53:14 +01:00
|
|
|
|
2020-03-04 21:48:37 +01:00
|
|
|
// Don't update or resolve the room head with this shit.
|
|
|
|
const bool dummy_event(json::get<"type"_>(event) == "org.matrix.dummy_event");
|
|
|
|
wopts.appendix.set(dbs::appendix::ROOM_HEAD, opts.room_head && !dummy_event);
|
2020-04-03 02:16:54 +02:00
|
|
|
wopts.appendix.set(dbs::appendix::ROOM_HEAD_RESOLVE, opts.room_head_resolve);
|
2020-03-04 21:48:37 +01:00
|
|
|
|
2019-08-24 01:56:58 +02:00
|
|
|
if(opts.present && json::get<"state_key"_>(event))
|
|
|
|
{
|
|
|
|
const room room
|
|
|
|
{
|
|
|
|
at<"room_id"_>(event)
|
|
|
|
};
|
|
|
|
|
|
|
|
const room::state state
|
|
|
|
{
|
|
|
|
room
|
|
|
|
};
|
|
|
|
|
|
|
|
//XXX
|
|
|
|
const auto pres_idx
|
|
|
|
{
|
|
|
|
state.get(std::nothrow, at<"type"_>(event), at<"state_key"_>(event))
|
|
|
|
};
|
|
|
|
|
|
|
|
//XXX
|
|
|
|
int64_t pres_depth(0);
|
|
|
|
const auto fresher
|
|
|
|
{
|
|
|
|
!pres_idx ||
|
|
|
|
m::get<int64_t>(pres_idx, "depth", pres_depth) < json::get<"depth"_>(event)
|
|
|
|
};
|
|
|
|
|
|
|
|
if(fresher)
|
|
|
|
{
|
|
|
|
//XXX
|
|
|
|
const auto &[pass, fail]
|
|
|
|
{
|
2020-03-22 01:23:08 +01:00
|
|
|
opts.auth && !eval.room_internal?
|
2019-08-24 01:56:58 +02:00
|
|
|
room::auth::check(event, room):
|
|
|
|
room::auth::passfail{true, {}}
|
|
|
|
};
|
|
|
|
|
|
|
|
if(fail)
|
|
|
|
log::dwarning
|
|
|
|
{
|
|
|
|
log, "%s | fails auth for present state of %s :%s",
|
|
|
|
loghead(eval),
|
|
|
|
string_view{room.room_id},
|
|
|
|
what(fail),
|
|
|
|
};
|
|
|
|
|
|
|
|
wopts.appendix.set(dbs::appendix::ROOM_STATE, pass);
|
|
|
|
wopts.appendix.set(dbs::appendix::ROOM_JOINED, pass);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-21 22:13:45 +01:00
|
|
|
dbs::write(*eval.txn, event, wopts);
|
2019-08-24 01:56:58 +02:00
|
|
|
|
|
|
|
log::debug
|
|
|
|
{
|
2019-09-17 01:42:22 +02:00
|
|
|
log, "%s | write buffered",
|
2019-08-24 01:56:58 +02:00
|
|
|
loghead(eval),
|
|
|
|
};
|
2017-11-16 02:37:09 +01:00
|
|
|
}
|
2017-11-30 20:01:14 +01:00
|
|
|
|
2018-02-28 07:53:44 +01:00
|
|
|
void
|
2019-03-21 22:13:45 +01:00
|
|
|
ircd::m::vm::write_commit(eval &eval)
|
2018-02-28 07:53:44 +01:00
|
|
|
{
|
2018-06-12 07:43:19 +02:00
|
|
|
assert(eval.txn);
|
2019-03-21 22:13:45 +01:00
|
|
|
assert(eval.txn.use_count() == 1);
|
|
|
|
assert(eval.sequence_shared[0] == 0);
|
2019-09-09 03:11:45 +02:00
|
|
|
auto &txn
|
|
|
|
{
|
|
|
|
*eval.txn
|
|
|
|
};
|
2018-12-31 02:02:19 +01:00
|
|
|
|
2019-03-16 20:38:14 +01:00
|
|
|
#ifdef RB_DEBUG
|
2019-03-19 19:45:01 +01:00
|
|
|
const auto db_seq_before(db::sequence(*m::dbs::events));
|
2019-03-16 20:38:14 +01:00
|
|
|
#endif
|
|
|
|
|
2018-12-31 02:02:19 +01:00
|
|
|
txn();
|
2019-03-16 20:38:14 +01:00
|
|
|
|
|
|
|
#ifdef RB_DEBUG
|
2019-03-19 19:45:01 +01:00
|
|
|
const auto db_seq_after(db::sequence(*m::dbs::events));
|
2019-03-16 20:38:14 +01:00
|
|
|
|
2019-03-21 22:13:45 +01:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "%s | wrote %lu:%lu | db seq %lu:%lu %zu cells in %zu bytes to events database ...",
|
|
|
|
loghead(eval),
|
|
|
|
sequence::get(eval),
|
|
|
|
eval.sequence_shared[1],
|
|
|
|
db_seq_before,
|
|
|
|
db_seq_after,
|
|
|
|
txn.size(),
|
|
|
|
txn.bytes()
|
|
|
|
};
|
2019-03-26 04:17:49 +01:00
|
|
|
#endif
|
2017-11-16 02:37:09 +01:00
|
|
|
}
|
2019-04-30 23:08:00 +02:00
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::m::vm::calc_txn_reserve(const opts &opts,
|
|
|
|
const event &event)
|
|
|
|
{
|
|
|
|
const size_t reserve_event
|
|
|
|
{
|
|
|
|
opts.reserve_bytes == size_t(-1)?
|
|
|
|
size_t(json::serialized(event) * 1.66):
|
|
|
|
opts.reserve_bytes
|
|
|
|
};
|
|
|
|
|
|
|
|
return reserve_event + opts.reserve_index;
|
|
|
|
}
|
|
|
|
|
2019-07-06 06:33:58 +02:00
|
|
|
template<class T>
|
|
|
|
void
|
|
|
|
ircd::m::vm::call_hook(hook::site<T> &hook,
|
|
|
|
eval &eval,
|
|
|
|
const event &event,
|
|
|
|
T&& data)
|
|
|
|
try
|
|
|
|
{
|
2019-12-12 05:53:52 +01:00
|
|
|
#if 0
|
2019-09-17 01:42:22 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "%s | phase:%s enter",
|
|
|
|
loghead(eval),
|
2020-03-03 04:36:49 +01:00
|
|
|
hook.name(),
|
2019-09-17 01:42:22 +02:00
|
|
|
};
|
2019-12-12 05:53:52 +01:00
|
|
|
#endif
|
2019-09-17 01:42:22 +02:00
|
|
|
|
2020-03-03 04:37:38 +01:00
|
|
|
assert(!eval.phase);
|
|
|
|
const scope_restore hook_phase
|
|
|
|
{
|
|
|
|
eval.phase, std::addressof(hook)
|
|
|
|
};
|
|
|
|
|
2019-07-06 06:33:58 +02:00
|
|
|
hook(event, std::forward<T>(data));
|
2019-09-17 01:42:22 +02:00
|
|
|
|
2019-12-12 05:53:52 +01:00
|
|
|
#if 0
|
2019-09-17 01:42:22 +02:00
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "%s | phase:%s leave",
|
|
|
|
loghead(eval),
|
2020-03-03 04:36:49 +01:00
|
|
|
hook.name(),
|
2019-09-17 01:42:22 +02:00
|
|
|
};
|
2019-12-12 05:53:52 +01:00
|
|
|
#endif
|
2019-07-06 06:33:58 +02:00
|
|
|
}
|
2019-07-16 01:41:04 +02:00
|
|
|
catch(const m::error &e)
|
|
|
|
{
|
|
|
|
log::derror
|
|
|
|
{
|
2019-09-17 01:42:22 +02:00
|
|
|
log, "%s | phase:%s :%s :%s :%s",
|
2019-07-16 01:41:04 +02:00
|
|
|
loghead(eval),
|
2020-03-04 04:15:02 +01:00
|
|
|
hook.name(),
|
2019-07-16 01:41:04 +02:00
|
|
|
e.what(),
|
|
|
|
e.errcode(),
|
|
|
|
e.errstr(),
|
|
|
|
};
|
|
|
|
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
catch(const http::error &e)
|
|
|
|
{
|
|
|
|
log::derror
|
|
|
|
{
|
2019-09-17 01:42:22 +02:00
|
|
|
log, "%s | phase:%s :%s :%s",
|
2019-07-16 01:41:04 +02:00
|
|
|
loghead(eval),
|
2020-03-04 04:15:02 +01:00
|
|
|
hook.name(),
|
2019-07-16 01:41:04 +02:00
|
|
|
e.what(),
|
|
|
|
e.content,
|
|
|
|
};
|
|
|
|
|
|
|
|
throw;
|
|
|
|
}
|
2019-07-06 06:33:58 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::derror
|
|
|
|
{
|
2019-09-17 01:42:22 +02:00
|
|
|
log, "%s | phase:%s :%s",
|
2019-07-06 06:33:58 +02:00
|
|
|
loghead(eval),
|
2020-03-04 04:15:02 +01:00
|
|
|
hook.name(),
|
2019-07-06 06:33:58 +02:00
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
2019-04-30 23:08:00 +02:00
|
|
|
template<class... args>
|
|
|
|
ircd::m::vm::fault
|
|
|
|
ircd::m::vm::handle_error(const vm::opts &opts,
|
|
|
|
const vm::fault &code,
|
|
|
|
const string_view &fmt,
|
|
|
|
args&&... a)
|
|
|
|
{
|
|
|
|
if(opts.errorlog & code)
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, fmt, std::forward<args>(a)...
|
|
|
|
};
|
2019-05-13 21:31:34 +02:00
|
|
|
else if(~opts.warnlog & code)
|
|
|
|
log::derror
|
|
|
|
{
|
|
|
|
log, fmt, std::forward<args>(a)...
|
|
|
|
};
|
2019-04-30 23:08:00 +02:00
|
|
|
|
|
|
|
if(opts.warnlog & code)
|
|
|
|
log::warning
|
|
|
|
{
|
|
|
|
log, fmt, std::forward<args>(a)...
|
|
|
|
};
|
|
|
|
|
|
|
|
if(~opts.nothrows & code)
|
|
|
|
throw error
|
|
|
|
{
|
|
|
|
code, fmt, std::forward<args>(a)...
|
|
|
|
};
|
|
|
|
|
|
|
|
return code;
|
|
|
|
}
|