mirror of
https://github.com/matrix-construct/construct
synced 2024-11-26 00:32:35 +01:00
ircd:Ⓜ️:vm: Add wrapping to accepted event notify; further merge EDU and PDU core path.
This commit is contained in:
parent
8091bdd007
commit
9749d7c609
2 changed files with 77 additions and 27 deletions
|
@ -19,6 +19,7 @@ namespace ircd::m::vm
|
|||
struct error; // custom exception
|
||||
struct opts;
|
||||
struct eval;
|
||||
struct accepted;
|
||||
|
||||
using fault_t = std::underlying_type<fault>::type;
|
||||
using closure = std::function<void (const event &)>;
|
||||
|
@ -26,7 +27,7 @@ namespace ircd::m::vm
|
|||
|
||||
extern struct log::log log;
|
||||
extern uint64_t current_sequence;
|
||||
extern ctx::shared_view<const event> accept;
|
||||
extern ctx::shared_view<accepted> accept;
|
||||
extern const opts default_opts;
|
||||
|
||||
event::id::buf commit(const m::event &, const opts & = default_opts);
|
||||
|
@ -146,6 +147,19 @@ struct ircd::m::vm::opts
|
|||
bool infolog_accept {false};
|
||||
};
|
||||
|
||||
struct ircd::m::vm::accepted
|
||||
:m::event
|
||||
{
|
||||
ctx::ctx *context;
|
||||
const vm::opts *opts;
|
||||
const event::conforms *report;
|
||||
std::string strung;
|
||||
|
||||
accepted(const m::event &event,
|
||||
const vm::opts *const &opts,
|
||||
const event::conforms *const &report);
|
||||
};
|
||||
|
||||
struct ircd::m::vm::error
|
||||
:m::error
|
||||
{
|
||||
|
|
88
ircd/m/vm.cc
88
ircd/m/vm.cc
|
@ -221,10 +221,37 @@ try
|
|||
};
|
||||
|
||||
// A conforming (with lots of masks) event without an event_id is an EDU.
|
||||
if(!json::get<"event_id"_>(event))
|
||||
return _eval_edu(*this, event);
|
||||
const fault ret
|
||||
{
|
||||
json::get<"event_id"_>(event)?
|
||||
_eval_pdu(*this, event):
|
||||
_eval_edu(*this, event)
|
||||
};
|
||||
|
||||
return _eval_pdu(*this, event);
|
||||
if(ret != fault::ACCEPT)
|
||||
return ret;
|
||||
|
||||
vm::accepted accepted
|
||||
{
|
||||
event, opts, &report
|
||||
};
|
||||
|
||||
if(opts->notify)
|
||||
{
|
||||
notify_hook(event);
|
||||
vm::accept.expose(accepted);
|
||||
}
|
||||
|
||||
if(opts->effects)
|
||||
_tmp_effects(event);
|
||||
|
||||
if(opts->debuglog_accept)
|
||||
log.debug("%s", pretty_oneline(event));
|
||||
|
||||
if(opts->infolog_accept)
|
||||
log.info("%s", pretty_oneline(event));
|
||||
|
||||
return ret;
|
||||
}
|
||||
catch(const error &e)
|
||||
{
|
||||
|
@ -376,30 +403,16 @@ ircd::m::vm::_eval_pdu(eval &eval,
|
|||
if(opts.write)
|
||||
write(eval);
|
||||
|
||||
if(opts.notify)
|
||||
{
|
||||
notify_hook(event);
|
||||
vm::accept.expose(event);
|
||||
}
|
||||
|
||||
if(opts.effects)
|
||||
_tmp_effects(event);
|
||||
|
||||
if(opts.debuglog_accept)
|
||||
log.debug("%s", pretty_oneline(event));
|
||||
|
||||
if(opts.infolog_accept)
|
||||
log.info("%s", pretty_oneline(event));
|
||||
|
||||
return fault::ACCEPT;
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::vm::write(eval &eval)
|
||||
{
|
||||
log.debug("Committing %zu cells in %zu bytes to events database...",
|
||||
eval.txn.size(),
|
||||
eval.txn.bytes());
|
||||
if(eval.opts->debuglog_accept)
|
||||
log.debug("Committing %zu cells in %zu bytes to events database...",
|
||||
eval.txn.size(),
|
||||
eval.txn.bytes());
|
||||
|
||||
eval.txn();
|
||||
vm::current_sequence++;
|
||||
|
@ -428,8 +441,6 @@ ircd::m::vm::reflect(const enum fault &code)
|
|||
void
|
||||
ircd::m::vm::_tmp_effects(const m::event &event)
|
||||
{
|
||||
const m::room::id room_id{at<"room_id"_>(event)};
|
||||
const m::user::id sender{at<"sender"_>(event)};
|
||||
const auto &type{at<"type"_>(event)};
|
||||
|
||||
//TODO: X
|
||||
|
@ -448,15 +459,40 @@ ircd::m::vm::_tmp_effects(const m::event &event)
|
|||
*/
|
||||
|
||||
//TODO: X
|
||||
if(type == "m.room.member" && my_host(sender.host()))
|
||||
if(type == "m.room.member")
|
||||
{
|
||||
const m::room::id room_id{at<"room_id"_>(event)};
|
||||
const m::user::id sender{at<"sender"_>(event)};
|
||||
|
||||
//TODO: ABA / TXN
|
||||
if(!exists(sender))
|
||||
create(sender);
|
||||
|
||||
//TODO: ABA / TXN
|
||||
m::user::room user_room{sender};
|
||||
send(user_room, sender, "ircd.member", room_id, at<"content"_>(event));
|
||||
}
|
||||
|
||||
//TODO: X
|
||||
if(type == "m.room.join_rules" && my_host(sender.host()))
|
||||
if(type == "m.room.join_rules")
|
||||
{
|
||||
send(room::id{"!public:zemos.net"}, sender, "ircd.room", room_id, {});
|
||||
const m::room::id room_id{at<"room_id"_>(event)};
|
||||
const m::user::id sender{at<"sender"_>(event)};
|
||||
if(my_host(sender.host()))
|
||||
send(room::id{"!public:zemos.net"}, sender, "ircd.room", room_id, {});
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// accepted
|
||||
//
|
||||
|
||||
ircd::m::vm::accepted::accepted(const m::event &event,
|
||||
const vm::opts *const &opts,
|
||||
const event::conforms *const &report)
|
||||
:m::event{event}
|
||||
,context{ctx::current}
|
||||
,opts{opts}
|
||||
,report{report}
|
||||
{
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue