mirror of
https://github.com/matrix-construct/construct
synced 2024-11-19 08:21:09 +01:00
ircd:Ⓜ️:vm: Options to generate event_id, origin, origin_server_ts.
This commit is contained in:
parent
e8c10977a1
commit
7ae6ad47ea
2 changed files with 33 additions and 8 deletions
|
@ -86,6 +86,15 @@ struct ircd::m::vm::opts
|
||||||
// Sign and include signatures object
|
// Sign and include signatures object
|
||||||
bool sign {true};
|
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};
|
||||||
|
|
||||||
/// Make writes to database
|
/// Make writes to database
|
||||||
bool write {true};
|
bool write {true};
|
||||||
|
|
||||||
|
|
32
ircd/m/vm.cc
32
ircd/m/vm.cc
|
@ -36,10 +36,20 @@ ircd::m::vm::commit(json::iov &event,
|
||||||
const json::iov &contents,
|
const json::iov &contents,
|
||||||
const opts &opts)
|
const opts &opts)
|
||||||
{
|
{
|
||||||
const json::iov::push set[]
|
const json::iov::add_if _origin
|
||||||
{
|
{
|
||||||
{ event, { "origin_server_ts", ircd::time<milliseconds>() }},
|
event, opts.origin,
|
||||||
{ event, { "origin", my_host() }},
|
{
|
||||||
|
"origin", my_host()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const json::iov::add_if _origin_server_ts
|
||||||
|
{
|
||||||
|
event, opts.origin_server_ts,
|
||||||
|
{
|
||||||
|
"origin_server_ts", ircd::time<milliseconds>()
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const json::strung content
|
const json::strung content
|
||||||
|
@ -50,20 +60,26 @@ ircd::m::vm::commit(json::iov &event,
|
||||||
// event_id
|
// event_id
|
||||||
|
|
||||||
sha256::buf event_id_hash;
|
sha256::buf event_id_hash;
|
||||||
|
if(opts.event_id)
|
||||||
{
|
{
|
||||||
thread_local char preimage_buf[64_KiB];
|
thread_local char preimage_buf[64_KiB];
|
||||||
event_id_hash = sha256{stringify(mutable_buffer{preimage_buf}, event)};
|
event_id_hash = sha256
|
||||||
|
{
|
||||||
|
stringify(mutable_buffer{preimage_buf}, event)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
event::id::buf eid_buf;
|
event::id::buf eid_buf;
|
||||||
const auto event_id
|
const string_view event_id
|
||||||
{
|
{
|
||||||
m::event_id(event, eid_buf, event_id_hash)
|
opts.event_id?
|
||||||
|
m::event_id(event, eid_buf, event_id_hash):
|
||||||
|
string_view{}
|
||||||
};
|
};
|
||||||
|
|
||||||
const json::iov::push _event_id
|
const json::iov::add_if _event_id
|
||||||
{
|
{
|
||||||
event, { "event_id", event_id }
|
event, opts.event_id, { "event_id", event_id }
|
||||||
};
|
};
|
||||||
|
|
||||||
// hashes
|
// hashes
|
||||||
|
|
Loading…
Reference in a new issue