0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2025-02-18 09:40:12 +01:00

ircd:Ⓜ️:vm: Use bitmask of properties to generate in vm::copts.

This commit is contained in:
Jason Volk 2019-08-17 00:44:14 -07:00
parent 1c0f947211
commit c760eb0a12
5 changed files with 40 additions and 60 deletions

View file

@ -325,41 +325,34 @@ struct ircd::m::vm::copts
/// A matrix-spec opaque token from a client identifying this eval.
string_view client_txnid;
/// Hash and include hashes object.
bool add_hash {true};
/// This bitmask covers all of the top-level properties of m::event
/// which will be generated internally during injection unless they
/// already exist. Clearing any of these bits will prevent the internal
/// generation of these properties (i.e. for EDU's).
event::keys::selection prop_mask
{
event::keys::include
{
"auth_events",
"depth",
"event_id",
"hashes",
"origin",
"origin_server_ts",
"prev_events",
"prev_state",
"signatures",
}
};
/// Sign and include signatures object
bool add_sig {true};
/// Generate and include event_id
bool add_event_id {true};
/// Include our origin
bool add_origin {true};
/// Include origin_server_ts
bool add_origin_server_ts {true};
/// Add prev_events
bool add_prev_events {true};
/// Add depth
bool add_depth {true};
/// Add prev_state
bool add_prev_state {true};
/// Add auth_events
bool add_auth_events {true};
/// Call the issue hook or bypass
bool issue {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};
/// Call the issue hook or bypass
bool issue {true};
};
struct ircd::m::vm::error

View file

@ -158,11 +158,7 @@ try
};
m::vm::copts opts;
opts.add_hash = false;
opts.add_sig = false;
opts.add_event_id = false;
opts.add_origin = true;
opts.add_origin_server_ts = false;
opts.prop_mask.reset();
opts.conforming = false;
opts.notify_clients = false;
m::vm::eval

View file

@ -557,15 +557,10 @@ try
}}}
};
m::vm::copts opts;
// EDU options
opts.add_hash = false;
opts.add_sig = false;
opts.add_event_id = false;
opts.add_origin = true;
opts.add_origin_server_ts = false;
m::vm::copts opts;
opts.conforming = false;
opts.prop_mask.reset();
// Don't need to notify clients, the /sync system understood the
// `ircd.read` directly. The federation sender is what we're hitting here.

View file

@ -100,11 +100,7 @@ commit(const m::typing &edu)
};
m::vm::copts opts;
opts.add_hash = false;
opts.add_sig = false;
opts.add_event_id = false;
opts.add_origin = true;
opts.add_origin_server_ts = false;
opts.prop_mask.reset();
opts.conforming = false;
// Because the matrix spec should use the same format for client

View file

@ -342,7 +342,7 @@ ircd::m::vm::inject(eval &eval,
const bool add_prev_events
{
!is_room_create
&& opts.add_prev_events
&& opts.prop_mask.has("prev_events")
&& !event.has("prev_events")
};
@ -381,7 +381,7 @@ ircd::m::vm::inject(eval &eval,
assert(depth >= -1);
const json::iov::set depth_
{
event, opts.add_depth && !event.has("depth"),
event, opts.prop_mask.has("depth") && !event.has("depth"),
{
"depth", [&depth]
{
@ -401,7 +401,7 @@ ircd::m::vm::inject(eval &eval,
const bool add_auth_events
{
!is_room_create
&& opts.add_auth_events
&& opts.prop_mask.has("auth_events")
&& !event.has("auth_events")
};
@ -440,7 +440,7 @@ ircd::m::vm::inject(eval &eval,
// Add our network name.
const json::iov::add origin_
{
event, opts.add_origin,
event, opts.prop_mask.has("origin"),
{
"origin", []() -> json::value
{
@ -452,7 +452,7 @@ ircd::m::vm::inject(eval &eval,
// Add the current time.
const json::iov::add origin_server_ts_
{
event, opts.add_origin_server_ts,
event, opts.prop_mask.has("origin_server_ts"),
{
"origin_server_ts", []
{
@ -483,7 +483,7 @@ ircd::m::vm::inject1(eval &eval,
assert(eval.room_version);
const event::id &event_id
{
opts.add_event_id?
opts.prop_mask.has("event_id")?
make_id(m::event{event}, eval.room_version, eval.event_id):
event::id{}
};
@ -510,14 +510,14 @@ ircd::m::vm::inject1(eval &eval,
char hashes_buf[384];
const string_view hashes
{
opts.add_hash?
opts.prop_mask.has("hashes")?
m::event::hashes(hashes_buf, event, content):
string_view{}
};
const json::iov::add hashes_
{
event, opts.add_hash && !empty(hashes),
event, opts.prop_mask.has("hashes") && !empty(hashes),
{
"hashes", [&hashes]() -> json::value
{
@ -531,14 +531,14 @@ ircd::m::vm::inject1(eval &eval,
char sigs_buf[384];
const string_view sigs
{
opts.add_sig?
opts.prop_mask.has("signatures")?
m::event::signatures(sigs_buf, event, contents):
string_view{}
};
const json::iov::add sigs_
{
event, opts.add_sig,
event, opts.prop_mask.has("signatures"),
{
"signatures", [&sigs]() -> json::value
{
@ -588,7 +588,7 @@ ircd::m::vm::inject3(eval &eval,
char hashes_buf[384];
const string_view hashes
{
opts.add_hash?
opts.prop_mask.has("hashes")?
m::event::hashes(hashes_buf, event, content):
string_view{}
};
@ -596,7 +596,7 @@ ircd::m::vm::inject3(eval &eval,
// Add the content hash to the event iov.
const json::iov::add hashes_
{
event, opts.add_hash && !empty(hashes),
event, opts.prop_mask.has("hashes") && !empty(hashes),
{
"hashes", [&hashes]() -> json::value
{
@ -609,7 +609,7 @@ ircd::m::vm::inject3(eval &eval,
char sigs_buf[384];
const string_view sigs
{
opts.add_sig?
opts.prop_mask.has("signatures")?
m::event::signatures(sigs_buf, event, contents):
string_view{}
};
@ -617,7 +617,7 @@ ircd::m::vm::inject3(eval &eval,
// Add the signature to the event iov.
const json::iov::add sigs_
{
event, opts.add_sig,
event, opts.prop_mask.has("signatures"),
{
"signatures", [&sigs]() -> json::value
{
@ -636,7 +636,7 @@ ircd::m::vm::inject3(eval &eval,
// in the eval interface so it persists longer than this stack.
const event::id &event_id
{
opts.add_event_id?
opts.prop_mask.has("event_id")?
make_id(m::event{event}, eval.room_version, eval.event_id):
event::id{}
};