mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 16:22:35 +01:00
ircd:Ⓜ️:vm: Distill vm::opts::commit extension from vm::opts.
This commit is contained in:
parent
74b7dddb9a
commit
d3e6b20f14
9 changed files with 55 additions and 35 deletions
|
@ -57,6 +57,7 @@ namespace ircd
|
|||
#include "event.h"
|
||||
#include "dbs.h"
|
||||
#include "state.h"
|
||||
#include "vm.h"
|
||||
#include "room.h"
|
||||
#include "user.h"
|
||||
#include "node.h"
|
||||
|
@ -67,7 +68,6 @@ namespace ircd
|
|||
#include "filter.h"
|
||||
#include "request.h"
|
||||
#include "v1/v1.h"
|
||||
#include "vm.h"
|
||||
#include "keys.h"
|
||||
#include "edu.h"
|
||||
#include "presence.h"
|
||||
|
|
|
@ -104,7 +104,7 @@ struct ircd::m::room
|
|||
|
||||
id room_id;
|
||||
event::id event_id;
|
||||
const vm::opts *opts {nullptr};
|
||||
const vm::opts::commit *opts {nullptr};
|
||||
|
||||
operator const id &() const;
|
||||
|
||||
|
@ -122,13 +122,13 @@ struct ircd::m::room
|
|||
bool membership(const m::id::user &, const string_view &membership = "join") const;
|
||||
string_view membership(const mutable_buffer &out, const m::id::user &) const;
|
||||
|
||||
room(const id &room_id, const string_view &event_id, const vm::opts *const &opts = nullptr)
|
||||
room(const id &room_id, const string_view &event_id, const vm::opts::commit *const &opts = nullptr)
|
||||
:room_id{room_id}
|
||||
,event_id{event_id? event::id{event_id} : event::id{}}
|
||||
,opts{opts}
|
||||
{}
|
||||
|
||||
room(const id &room_id, const vm::opts *const &opts = nullptr)
|
||||
room(const id &room_id, const vm::opts::commit *const &opts = nullptr)
|
||||
:room_id{room_id}
|
||||
,opts{opts}
|
||||
{}
|
||||
|
|
|
@ -29,9 +29,6 @@ namespace ircd::m::vm
|
|||
extern uint64_t current_sequence;
|
||||
extern ctx::shared_view<accepted> accept;
|
||||
extern const opts default_opts;
|
||||
|
||||
fault commit(const m::event &, const opts & = default_opts);
|
||||
event::id::buf commit(json::iov &event, const json::iov &content, const opts & = default_opts);
|
||||
}
|
||||
|
||||
/// Event Evaluation Device
|
||||
|
@ -80,20 +77,8 @@ enum ircd::m::vm::fault
|
|||
/// Evaluation Options
|
||||
struct ircd::m::vm::opts
|
||||
{
|
||||
// Hash and include hashes object.
|
||||
bool hash {true};
|
||||
|
||||
// Sign and include signatures object
|
||||
bool sign {true};
|
||||
|
||||
// Generate and include event_id
|
||||
bool event_id {true};
|
||||
|
||||
// Include our origin
|
||||
bool origin {true};
|
||||
|
||||
// Include origin_server_ts
|
||||
bool origin_server_ts {true};
|
||||
// Extended opts specific to creating events originating from this server.
|
||||
struct commit;
|
||||
|
||||
/// Make writes to database
|
||||
bool write {true};
|
||||
|
@ -161,12 +146,6 @@ struct ircd::m::vm::opts
|
|||
EXISTS
|
||||
};
|
||||
|
||||
/// Whether to log a debug message before commit
|
||||
bool debuglog_precommit {false};
|
||||
|
||||
/// Whether to log an info message after commit accepted
|
||||
bool infolog_postcommit {false};
|
||||
|
||||
/// Whether to log a debug message on successful eval.
|
||||
bool debuglog_accept {false};
|
||||
|
||||
|
@ -174,6 +153,42 @@ struct ircd::m::vm::opts
|
|||
bool infolog_accept {false};
|
||||
};
|
||||
|
||||
namespace ircd::m::vm
|
||||
{
|
||||
extern const opts::commit default_commit_opts;
|
||||
|
||||
fault commit(const m::event &, const opts::commit & = default_commit_opts);
|
||||
event::id::buf commit(json::iov &event, const json::iov &content, const opts::commit & = default_commit_opts);
|
||||
}
|
||||
|
||||
/// Extension structure to vm::opts which includes additional options for
|
||||
/// commissioning events originating from this server which are then passed
|
||||
/// through eval (this process is committing).
|
||||
struct ircd::m::vm::opts::commit
|
||||
:opts
|
||||
{
|
||||
// Hash and include hashes object.
|
||||
bool hash {true};
|
||||
|
||||
// Sign and include signatures object
|
||||
bool sign {true};
|
||||
|
||||
// Generate and include event_id
|
||||
bool event_id {true};
|
||||
|
||||
// Include our origin
|
||||
bool origin {true};
|
||||
|
||||
// Include origin_server_ts
|
||||
bool origin_server_ts {true};
|
||||
|
||||
/// Whether to log a debug message before commit
|
||||
bool debuglog_precommit {false};
|
||||
|
||||
/// Whether to log an info message after commit accepted
|
||||
bool infolog_postcommit {false};
|
||||
};
|
||||
|
||||
struct ircd::m::vm::accepted
|
||||
:m::event
|
||||
{
|
||||
|
|
10
ircd/m/vm.cc
10
ircd/m/vm.cc
|
@ -28,13 +28,17 @@ decltype(ircd::m::vm::default_opts)
|
|||
ircd::m::vm::default_opts
|
||||
{};
|
||||
|
||||
decltype(ircd::m::vm::default_commit_opts)
|
||||
ircd::m::vm::default_commit_opts
|
||||
{};
|
||||
|
||||
/// This function takes an event object vector and adds our origin and event_id
|
||||
/// and hashes and signature and attempts to inject the event into the core.
|
||||
///
|
||||
ircd::m::event::id::buf
|
||||
ircd::m::vm::commit(json::iov &event,
|
||||
const json::iov &contents,
|
||||
const opts &opts)
|
||||
const opts::commit &opts)
|
||||
{
|
||||
const json::iov::add_if _origin
|
||||
{
|
||||
|
@ -157,7 +161,7 @@ ircd::m::vm::commit_hook
|
|||
///
|
||||
ircd::m::vm::fault
|
||||
ircd::m::vm::commit(const event &event,
|
||||
const opts &opts)
|
||||
const opts::commit &opts)
|
||||
{
|
||||
if(opts.debuglog_precommit)
|
||||
log.debug("injecting event(mark: %ld) %s",
|
||||
|
@ -167,7 +171,7 @@ ircd::m::vm::commit(const event &event,
|
|||
check_size(event);
|
||||
commit_hook(event);
|
||||
|
||||
vm::opts opts_{opts};
|
||||
auto opts_{opts};
|
||||
opts_.verify = false;
|
||||
|
||||
// Some functionality on this server may create an event on behalf
|
||||
|
|
|
@ -190,7 +190,7 @@ bootstrap(const m::room::alias &room_alias,
|
|||
{ content, !empty(avatar_url), { "avatar_url", avatar_url }},
|
||||
};
|
||||
|
||||
m::vm::opts opts;
|
||||
m::vm::opts::commit opts;
|
||||
opts.non_conform.set(m::event::conforms::MISSING_MEMBERSHIP);
|
||||
opts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
|
||||
opts.prev_check_exists = false;
|
||||
|
|
|
@ -85,7 +85,7 @@ commit__m_receipt_m_read(const m::room::id &room_id,
|
|||
}}}
|
||||
};
|
||||
|
||||
m::vm::opts opts;
|
||||
m::vm::opts::commit opts;
|
||||
opts.hash = false;
|
||||
opts.sign = false;
|
||||
opts.event_id = false;
|
||||
|
|
|
@ -246,9 +246,9 @@ commit__iov_iov(const room &room,
|
|||
{ event, { "prev_events", prev_events } },
|
||||
};
|
||||
|
||||
const vm::opts &vmopts
|
||||
const auto &vmopts
|
||||
{
|
||||
room.opts? *room.opts : vm::default_opts
|
||||
room.opts? *room.opts : vm::default_commit_opts
|
||||
};
|
||||
|
||||
return m::vm::commit(event, contents, vmopts);
|
||||
|
|
|
@ -159,7 +159,7 @@ commit__m_typing(const m::typing &edu)
|
|||
{ content, { "typing", json::get<"typing"_>(edu) } },
|
||||
};
|
||||
|
||||
m::vm::opts opts;
|
||||
m::vm::opts::commit opts;
|
||||
opts.hash = false;
|
||||
opts.sign = false;
|
||||
opts.event_id = false;
|
||||
|
|
|
@ -87,6 +87,7 @@ get__thumbnail(client &client,
|
|||
file_room_id(server, file)
|
||||
};
|
||||
|
||||
m::vm::opts::commit vmopts;
|
||||
const m::room room
|
||||
{
|
||||
room_id
|
||||
|
|
Loading…
Reference in a new issue