2020-12-10 10:00:45 +01:00
|
|
|
// The Construct
|
2018-02-04 03:22:01 +01:00
|
|
|
//
|
2020-12-10 10:00:45 +01:00
|
|
|
// Copyright (C) The Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2020 Jason Volk <jason@zemos.net>
|
2018-02-04 03:22:01 +01:00
|
|
|
//
|
|
|
|
// 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-09-26 06:42:07 +02:00
|
|
|
|
|
|
|
#pragma once
|
2020-12-10 10:00:45 +01:00
|
|
|
#define HAVE_IRCD_M_VM_OPTS_H
|
2017-09-26 06:42:07 +02:00
|
|
|
|
2017-10-25 18:47:03 +02:00
|
|
|
namespace ircd::m::vm
|
2017-09-26 06:42:07 +02:00
|
|
|
{
|
2018-02-28 07:53:44 +01:00
|
|
|
struct opts;
|
2018-05-07 01:04:51 +02:00
|
|
|
struct copts;
|
2017-09-26 06:42:07 +02:00
|
|
|
|
2019-03-21 23:58:18 +01:00
|
|
|
extern const opts default_opts;
|
|
|
|
extern const copts default_copts;
|
2017-11-16 02:48:25 +01:00
|
|
|
}
|
|
|
|
|
2018-02-28 07:53:44 +01:00
|
|
|
/// Evaluation Options
|
|
|
|
struct ircd::m::vm::opts
|
|
|
|
{
|
2019-04-22 21:25:50 +02:00
|
|
|
/// The remote server name which is conducting this eval.
|
|
|
|
string_view node_id;
|
|
|
|
|
|
|
|
/// The mxid of the user which is conducting this eval.
|
|
|
|
string_view user_id;
|
|
|
|
|
2020-01-07 01:22:30 +01:00
|
|
|
/// The txnid from the node conducting the eval.
|
|
|
|
string_view txn_id;
|
|
|
|
|
2020-05-12 04:37:55 +02:00
|
|
|
/// Enabled phases of evaluation.
|
|
|
|
std::bitset<num_of<vm::phase>()> phase {-1UL};
|
2019-03-09 21:08:05 +01:00
|
|
|
|
2023-02-18 21:50:11 +01:00
|
|
|
/// False to bypass all auth phases.
|
|
|
|
bool auth {true};
|
2019-05-12 00:30:40 +02:00
|
|
|
|
2023-02-18 21:50:11 +01:00
|
|
|
/// False to bypass all fetch phases.
|
|
|
|
bool fetch {true};
|
|
|
|
|
|
|
|
/// Broadcast to local clients (/sync stream). False only effectively
|
|
|
|
/// prevents longpoll sync from triggering. The client may still receive
|
|
|
|
/// the event by numerous other means, or may not due to other conditions.
|
2018-05-28 04:56:04 +02:00
|
|
|
bool notify_clients {true};
|
|
|
|
|
2023-02-18 21:50:11 +01:00
|
|
|
/// Broadcast to federation servers (/federation/send/). Only certain
|
|
|
|
/// events are broadcast based on other conditions; setting this to false
|
|
|
|
/// prevents all broadcasts.
|
2018-05-28 04:56:04 +02:00
|
|
|
bool notify_servers {true};
|
2018-02-28 07:53:44 +01:00
|
|
|
|
2023-02-18 22:01:56 +01:00
|
|
|
/// Override normal conditions for broadcasts to federation servers. This
|
|
|
|
/// may result in broadcasting events originating from other servers, etc.
|
|
|
|
/// The notify_servers option must still be true.
|
|
|
|
bool amplify {false};
|
|
|
|
|
2018-03-13 03:34:54 +01:00
|
|
|
/// False to allow a dirty conforms report (not recommended).
|
|
|
|
bool conforming {true};
|
|
|
|
|
|
|
|
/// Mask of conformity failures to allow without considering dirty.
|
2018-02-28 07:53:44 +01:00
|
|
|
event::conforms non_conform;
|
|
|
|
|
2018-03-13 03:34:54 +01:00
|
|
|
/// If the event was already checked before the eval, set this to true
|
|
|
|
/// and include the report (see below).
|
|
|
|
bool conformed {false};
|
|
|
|
|
|
|
|
/// When conformed=true, this report will be included instead of generating
|
|
|
|
/// one during the eval. This is useful if a conformity check was already
|
|
|
|
/// done before eval.
|
|
|
|
event::conforms report;
|
|
|
|
|
2019-07-10 11:14:38 +02:00
|
|
|
/// Supply the room version; overrides/avoids any internal query.
|
|
|
|
string_view room_version;
|
|
|
|
|
2020-12-01 10:50:37 +01:00
|
|
|
/// When true, the event is expected to have its content; hash mismatch
|
|
|
|
/// is not permitted. When false, hash mismatch is permitted. When -1,
|
|
|
|
/// by default the origin server is allowed to redact the content.
|
|
|
|
int8_t require_content {-1};
|
|
|
|
|
2018-03-09 00:55:54 +01:00
|
|
|
/// Toggles whether event may be considered a "present event" and may
|
|
|
|
/// update the optimized present state table of the room if it is proper.
|
|
|
|
bool present {true};
|
|
|
|
|
2019-09-14 00:26:44 +02:00
|
|
|
/// Evaluate in EDU mode. Input must not have event_id and none will be
|
|
|
|
/// generated for it.
|
|
|
|
bool edu {false};
|
|
|
|
|
2018-02-28 07:53:44 +01:00
|
|
|
/// Bypass check for event having already been evaluated so it can be
|
|
|
|
/// replayed through the system (not recommended).
|
|
|
|
bool replays {false};
|
|
|
|
|
2020-03-17 19:21:27 +01:00
|
|
|
/// Bypass check for another evaluation of the same event_id already
|
|
|
|
/// occurring. If this is false (not recommended) two duplicate events
|
|
|
|
/// being evaluated may race through the core.
|
|
|
|
bool unique {true};
|
|
|
|
|
2020-08-31 22:32:22 +02:00
|
|
|
/// When true, events in array inputs are evaluated as they are provided
|
|
|
|
/// without any reordering before eval.
|
|
|
|
bool ordered {false};
|
|
|
|
|
2019-01-24 20:32:57 +01:00
|
|
|
/// If the input event has a reference to already-strung json we can use
|
|
|
|
/// that directly when writing to the DB. When this is false we will
|
|
|
|
/// re-stringify the event internally either from a referenced source or
|
|
|
|
/// the tuple if no source is referenced. This should only be set to true
|
|
|
|
/// if the evaluator already performed this and the json source is good.
|
|
|
|
bool json_source {false};
|
|
|
|
|
2020-02-21 00:39:06 +01:00
|
|
|
/// Whether to gather all unknown keys from an input vector of events and
|
|
|
|
/// perform a parallel/mass fetch before proceeding with the evals.
|
|
|
|
bool mfetch_keys {true};
|
|
|
|
|
2020-12-19 08:10:03 +01:00
|
|
|
/// Whether to launch prefetches for all event_id's (found at standard
|
|
|
|
/// locations) from the input vector, in addition to some other related
|
|
|
|
/// local db prefetches. Disabled by default because it operates prior
|
|
|
|
/// to verification and access phases; can be enabled explicitly.
|
|
|
|
bool mprefetch_refs {false};
|
|
|
|
|
2019-04-30 22:57:12 +02:00
|
|
|
/// Throws fault::EVENT if *all* of the prev_events do not exist locally.
|
|
|
|
/// This is used to enforce that at least one path is traversable. This
|
|
|
|
/// test is conducted after waiting if fetch_prev and fetch_prev_wait.
|
2019-05-20 00:22:49 +02:00
|
|
|
bool fetch_prev_any {false};
|
2019-04-30 22:57:12 +02:00
|
|
|
|
2019-04-22 21:27:43 +02:00
|
|
|
/// Throws fault::EVENT if *any* of the prev_events do not exist locally.
|
2019-04-30 22:57:12 +02:00
|
|
|
/// This is used to enforce that all references have been acquired; other
|
|
|
|
/// corollary conditions are similar to fetch_prev_any.
|
2019-04-22 21:27:43 +02:00
|
|
|
bool fetch_prev_all {false};
|
2019-03-27 21:45:21 +01:00
|
|
|
|
2020-04-17 23:01:58 +02:00
|
|
|
/// The number of iterations of the wait cycle which checks for missing
|
|
|
|
/// prev_events will iterate before issuing remote fetches for them.
|
|
|
|
/// The default is 0 which bypasses the functionality, and is recommended
|
|
|
|
/// when the evaluator is confident missing prev_events won't arrive
|
|
|
|
/// elsehow. Setting to -1 enables it with an auto/conf value.
|
|
|
|
size_t fetch_prev_wait_count {0};
|
|
|
|
|
|
|
|
/// Base time to wait for missing prev_events to arrive at the server by
|
|
|
|
/// some other means before issuing remote fetches for them. The waiting
|
|
|
|
/// occurs in a loop where prev_events satisfaction is checked at each
|
|
|
|
/// iteration. This value is multiplied by the number of iterations for
|
|
|
|
/// multiplicative backoff. The default of -1 is auto / conf.
|
|
|
|
milliseconds fetch_prev_wait_time {-1};
|
|
|
|
|
2019-09-05 22:17:04 +02:00
|
|
|
/// The limit on the number of events to backfill if any of the prev_events
|
|
|
|
/// are missing. -1 is auto / conf.
|
|
|
|
size_t fetch_prev_limit = -1;
|
|
|
|
|
2020-11-20 22:46:37 +01:00
|
|
|
/// Considers any missing prev_event as an indication of possible missing
|
|
|
|
/// state from a history we don't have; allowing a state acquisition. This
|
|
|
|
/// is not practical to apply by default as internal decisions are better.
|
|
|
|
bool fetch_state_any {false};
|
|
|
|
|
|
|
|
/// This option affects the behavior for a case where we are missing the
|
|
|
|
/// (depth - 1) prev_events reference, thus other resolved references
|
|
|
|
/// are not adjacent. Yet at the claimed depth there is no apparent gap
|
|
|
|
/// in the timeline. If true, we assume possible missing state in this
|
|
|
|
/// case, but by default that is far too unrealistic in practice.
|
|
|
|
bool fetch_state_shallow {false};
|
|
|
|
|
2018-04-16 23:24:56 +02:00
|
|
|
/// Evaluators can set this value to optimize the creation of the database
|
|
|
|
/// transaction where the event will be stored. This value should be set
|
|
|
|
/// to the amount of space the event consumes; the JSON-serialized size is
|
2018-04-17 02:28:26 +02:00
|
|
|
/// a good value here. Default of -1 will automatically use serialized().
|
|
|
|
size_t reserve_bytes = -1;
|
2018-04-16 23:24:56 +02:00
|
|
|
|
|
|
|
/// This value is added to reserve_bytes to account for indexing overhead
|
|
|
|
/// in the database transaction allocation. Most evaluators have little
|
|
|
|
/// reason to ever adjust this.
|
2018-06-04 00:18:53 +02:00
|
|
|
size_t reserve_index {1024};
|
2018-04-16 23:24:56 +02:00
|
|
|
|
2023-02-18 21:50:11 +01:00
|
|
|
/// Custom dbs::opts to use during write.
|
|
|
|
dbs::opts wopts;
|
|
|
|
|
2020-09-08 01:55:47 +02:00
|
|
|
/// Coarse limit for array evals. The counter is incremented for every
|
|
|
|
/// event; both accepted and faulted.
|
|
|
|
size_t limit = -1;
|
|
|
|
|
2018-02-28 07:53:44 +01:00
|
|
|
/// Mask of faults that are not thrown as exceptions out of eval(). If
|
|
|
|
/// masked, the fault is returned from eval(). By default, the EXISTS
|
2019-04-08 05:57:43 +02:00
|
|
|
/// fault is masked which means existing events won't kill eval loops.
|
2020-12-15 20:06:48 +01:00
|
|
|
/// ACCEPT is ignored in the mask.
|
2018-02-28 07:53:44 +01:00
|
|
|
fault_t nothrows
|
|
|
|
{
|
2019-04-08 05:57:43 +02:00
|
|
|
EXISTS
|
2018-02-28 07:53:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Mask of faults that are logged to the error facility in vm::log.
|
2020-12-15 20:06:48 +01:00
|
|
|
/// ACCEPT is ignored in the mask.
|
2018-02-28 07:53:44 +01:00
|
|
|
fault_t errorlog
|
|
|
|
{
|
2019-04-08 05:57:43 +02:00
|
|
|
~(EXISTS)
|
2018-02-28 07:53:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Mask of faults that are logged to the warning facility in vm::log
|
2020-12-15 20:06:48 +01:00
|
|
|
/// ACCEPT is ignored in the mask.
|
2018-02-28 07:53:44 +01:00
|
|
|
fault_t warnlog
|
|
|
|
{
|
|
|
|
EXISTS
|
|
|
|
};
|
|
|
|
|
2020-12-15 20:06:48 +01:00
|
|
|
/// Mask of faults that are transcribed to the json::stack output.
|
|
|
|
fault_t outlog
|
|
|
|
{
|
|
|
|
~(EXISTS | ACCEPT)
|
|
|
|
};
|
|
|
|
|
2018-02-28 07:53:44 +01:00
|
|
|
/// Whether to log a debug message on successful eval.
|
|
|
|
bool debuglog_accept {false};
|
|
|
|
|
|
|
|
/// Whether to log an info message on successful eval.
|
|
|
|
bool infolog_accept {false};
|
2020-02-28 21:12:51 +01:00
|
|
|
|
2020-12-15 20:06:48 +01:00
|
|
|
/// Point this at a json::stack to transcribe output.
|
|
|
|
json::stack::object *out {nullptr};
|
2018-02-28 07:53:44 +01:00
|
|
|
};
|
|
|
|
|
2018-04-06 08:07:55 +02:00
|
|
|
/// Extension structure to vm::opts which includes additional options for
|
|
|
|
/// commissioning events originating from this server which are then passed
|
2019-03-21 23:58:18 +01:00
|
|
|
/// through eval (this process is also known as issuing).
|
2018-05-07 01:04:51 +02:00
|
|
|
struct ircd::m::vm::copts
|
2018-04-06 08:07:55 +02:00
|
|
|
:opts
|
|
|
|
{
|
2018-09-06 04:32:14 +02:00
|
|
|
/// A matrix-spec opaque token from a client identifying this eval.
|
|
|
|
string_view client_txnid;
|
|
|
|
|
2022-07-12 03:36:41 +02:00
|
|
|
/// MSC3316 appservice timestamp massage; passed to `origin_server_ts`.
|
|
|
|
milliseconds ts {milliseconds::min()};
|
|
|
|
|
2019-08-17 09:44:14 +02:00
|
|
|
/// 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",
|
|
|
|
}
|
|
|
|
};
|
2018-05-12 11:27:39 +02:00
|
|
|
|
2019-08-17 09:44:14 +02:00
|
|
|
/// Call the issue hook or bypass
|
|
|
|
bool issue {true};
|
2018-05-12 11:27:39 +02:00
|
|
|
|
2018-04-06 08:07:55 +02:00
|
|
|
/// 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};
|
|
|
|
};
|