0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-25 23:14:13 +01:00

ircd:Ⓜ️:event: Remove prev_state from top level.

This commit is contained in:
Jason Volk 2019-07-08 23:23:39 -07:00
parent fc8048dc74
commit 719a965d9f
11 changed files with 1 additions and 147 deletions

View file

@ -69,7 +69,6 @@ enum ircd::m::event::conforms::code
MISSING_MEMBER_STATE_KEY, ///< for m.room.member, !empty(state_key)
INVALID_MEMBER_STATE_KEY, ///< for m.room.member, !user::id(state_key)
MISSING_PREV_EVENTS, ///< for non-m.room.create, empty prev_events
MISSING_PREV_STATE, ///< for state_key'ed, empty prev_state
MISSING_AUTH_EVENTS, ///< for non-m.room.create, empty auth_events
DEPTH_NEGATIVE, ///< depth < 0
DEPTH_ZERO, ///< for non-m.room.create, depth=0
@ -81,10 +80,8 @@ enum ircd::m::event::conforms::code
MISMATCH_ALIASES_STATE_KEY, ///< m.room.aliases has no state_key
SELF_REDACTS, ///< event redacts itself
SELF_PREV_EVENT, ///< event_id self-referenced in prev_events
SELF_PREV_STATE, ///< event_id self-referenced in prev_state
SELF_AUTH_EVENT, ///< event_id self-referenced in auth_events
DUP_PREV_EVENT, ///< duplicate references in prev_events
DUP_PREV_STATE, ///< duplicate references in prev_state
DUP_AUTH_EVENT, ///< duplicate references in auth_events
_NUM_

View file

@ -38,28 +38,22 @@ struct ircd::m::event::prev
:json::tuple
<
json::property<name::auth_events, json::array>,
json::property<name::prev_state, json::array>,
json::property<name::prev_events, json::array>
>
{
std::tuple<event::id, json::object> auth_events(const size_t &idx) const;
std::tuple<event::id, json::object> prev_states(const size_t &idx) const;
std::tuple<event::id, json::object> prev_events(const size_t &idx) const;
event::id auth_event(const size_t &idx) const;
event::id prev_state(const size_t &idx) const;
event::id prev_event(const size_t &idx) const;
bool auth_event_exists(const size_t &idx) const;
bool prev_state_exists(const size_t &idx) const;
bool prev_event_exists(const size_t &idx) const;
bool auth_events_has(const event::id &) const;
bool prev_states_has(const event::id &) const;
bool prev_events_has(const event::id &) const;
size_t auth_events_count() const;
size_t prev_states_count() const;
size_t prev_events_count() const;
using super_type::tuple;

View file

@ -156,9 +156,6 @@ ircd::m::pretty_oneline(std::ostream &s,
const auto &auth_events{json::get<"auth_events"_>(event)};
s << "A:" << auth_events.count() << " ";
const auto &prev_states{json::get<"prev_state"_>(event)};
s << "S:" << prev_states.count() << " ";
const auto &prev_events{json::get<"prev_events"_>(event)};
s << "E:" << prev_events.count() << " ";
@ -312,23 +309,6 @@ ircd::m::pretty(std::ostream &s,
s << std::endl;
}
for(size_t i(0); i < prev.prev_states_count(); ++i)
{
const auto &[event_id, ref_hash]
{
prev.prev_states(i)
};
s << std::setw(16) << std::right << "[prev_state]"
<< " :" << event_id;
for(const auto &[algorithm, digest] : ref_hash)
s << " " << unquote(algorithm)
<< ": " << unquote(digest);
s << std::endl;
}
for(size_t i(0); i < prev.prev_events_count(); ++i)
{
const auto &[event_id, ref_hash]
@ -359,12 +339,6 @@ ircd::m::pretty_oneline(std::ostream &s,
s << unquote(auth_event[0]) << " ";
s << "] ";
const auto &prev_states{json::get<"prev_state"_>(prev)};
s << "S[ ";
for(const json::array prev_state : prev_states)
s << unquote(prev_state[0]) << " ";
s << "] ";
const auto &prev_events{json::get<"prev_events"_>(prev)};
s << "E[ ";
for(const json::array prev_event : prev_events)
@ -636,7 +610,6 @@ ircd::m::event_conforms_reflects
"MISSING_MEMBER_STATE_KEY",
"INVALID_MEMBER_STATE_KEY",
"MISSING_PREV_EVENTS",
"MISSING_PREV_STATE",
"MISSING_AUTH_EVENTS",
"DEPTH_NEGATIVE",
"DEPTH_ZERO",
@ -648,10 +621,8 @@ ircd::m::event_conforms_reflects
"MISMATCH_ALIASES_STATE_KEY",
"SELF_REDACTS",
"SELF_PREV_EVENT",
"SELF_PREV_STATE",
"SELF_AUTH_EVENT",
"DUP_PREV_EVENT",
"DUP_PREV_STATE",
"DUP_AUTH_EVENT",
};
@ -774,13 +745,6 @@ ircd::m::event::conforms::conforms(const event &e)
if(empty(json::get<"prev_events"_>(e)))
set(MISSING_PREV_EVENTS);
/*
if(json::get<"type"_>(e) != "m.room.create")
if(!empty(json::get<"state_key"_>(e)))
if(empty(json::get<"prev_state"_>(e)))
set(MISSING_PREV_STATE);
*/
if(json::get<"type"_>(e) != "m.room.create")
if(empty(json::get<"auth_events"_>(e)))
set(MISSING_AUTH_EVENTS);
@ -804,15 +768,6 @@ ircd::m::event::conforms::conforms(const event &e)
++i;
}
i = 0;
for(const json::array &ps : json::get<"prev_state"_>(prev))
{
if(unquote(ps.at(0)) == json::get<"event_id"_>(e))
set(SELF_PREV_STATE);
++i;
}
i = 0;
for(const json::array &ps : json::get<"auth_events"_>(prev))
{
@ -836,19 +791,6 @@ ircd::m::event::conforms::conforms(const event &e)
set(DUP_AUTH_EVENT);
}
for(size_t i(0); i < prev.prev_states_count(); ++i)
{
const auto &[event_id, ref_hash]
{
prev.prev_states(i)
};
for(size_t j(0); j < prev.prev_states_count(); ++j)
if(i != j)
if(event_id == prev.prev_state(j))
set(DUP_PREV_STATE);
}
for(size_t i(0); i < prev.prev_events_count(); ++i)
{
const auto &[event_id, ref_hash]
@ -2913,14 +2855,7 @@ bool
ircd::m::event::prev::prev_event_exists(const size_t &idx)
const
{
return m::exists(prev_state(idx));
}
bool
ircd::m::event::prev::prev_state_exists(const size_t &idx)
const
{
return m::exists(prev_state(idx));
return m::exists(prev_event(idx));
}
bool
@ -2941,17 +2876,6 @@ const
return false;
}
bool
ircd::m::event::prev::prev_states_has(const event::id &event_id)
const
{
for(size_t i(0); i < prev_states_count(); ++i)
if(prev_state(i) == event_id)
return true;
return false;
}
bool
ircd::m::event::prev::auth_events_has(const event::id &event_id)
const
@ -2970,13 +2894,6 @@ const
return json::get<"prev_events"_>(*this).count();
}
size_t
ircd::m::event::prev::prev_states_count()
const
{
return json::get<"prev_state"_>(*this).count();
}
size_t
ircd::m::event::prev::auth_events_count()
const
@ -2991,13 +2908,6 @@ const
return std::get<0>(auth_events(idx));
}
ircd::m::event::id
ircd::m::event::prev::prev_state(const size_t &idx)
const
{
return std::get<0>(prev_states(idx));
}
ircd::m::event::id
ircd::m::event::prev::prev_event(const size_t &idx)
const
@ -3038,37 +2948,6 @@ const
}
}
std::tuple<ircd::m::event::id, ircd::json::object>
ircd::m::event::prev::prev_states(const size_t &idx)
const
{
const string_view &prev_
{
at<"prev_state"_>(*this).at(idx)
};
switch(json::type(prev_))
{
case json::ARRAY:
{
const json::array &prev(prev_);
const json::string &prev_id(prev.at(0));
return {prev_id, prev[1]};
}
case json::STRING:
{
const json::string &prev_id(prev_);
return {prev_id, string_view{}};
}
default: throw m::INVALID_MXID
{
"prev_state[%zu] is invalid", idx
};
}
}
std::tuple<ircd::m::event::id, ircd::json::object>
ircd::m::event::prev::prev_events(const size_t &idx)
const

View file

@ -570,9 +570,6 @@ ircd::m::commit(const room &room,
// this event in any replay later will require special casing.
opts.non_conform |= event::conforms::MISMATCH_ORIGIN_SENDER;
// Stupid protocol workaround
opts.non_conform |= event::conforms::MISSING_PREV_STATE;
// Don't need this here
opts.verify = false;

View file

@ -201,7 +201,6 @@ ircd::m::invite_foreign(const event &event)
};
m::vm::opts vmopts;
vmopts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
vmopts.infolog_accept = true;
m::vm::eval(revent, vmopts);

View file

@ -7304,7 +7304,6 @@ console_cmd__eval(opt &out, const string_view &line)
opts.errorlog = 0;
opts.warnlog = 0;
opts.nothrows = 0;
opts.non_conform |= m::event::conforms::MISSING_PREV_STATE;
tokens(args, ' ', [&opts](const auto &arg)
{
@ -7372,7 +7371,6 @@ console_cmd__eval__file(opt &out, const string_view &line)
};
m::vm::opts opts;
opts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
opts.notify = false;
opts.verify = false;
m::vm::eval eval
@ -11864,7 +11862,6 @@ console_cmd__fed__sync(opt &out, const string_view &line)
m::vm::opts vmopts;
vmopts.nothrows = -1;
vmopts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
vmopts.debuglog_accept = true;
vmopts.fetch_prev_check = false;
vmopts.fetch_state_check = false;
@ -11978,7 +11975,6 @@ console_cmd__fed__state(opt &out, const string_view &line)
m::vm::opts vmopts;
vmopts.nothrows = -1;
vmopts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
m::vm::eval eval
{
pdus, vmopts
@ -12130,7 +12126,6 @@ console_cmd__fed__backfill(opt &out, const string_view &line)
}
m::vm::opts vmopts;
vmopts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
vmopts.nothrows = -1;
vmopts.room_head = false;
vmopts.room_head_resolve = true;
@ -12309,7 +12304,6 @@ console_cmd__fed__event(opt &out, const string_view &line)
return true;
m::vm::opts vmopts;
vmopts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
vmopts.fetch_prev = false;
m::vm::eval eval
{

View file

@ -223,7 +223,6 @@ check_event(const resource::request &request,
};
m::event::conforms non_conforms;
non_conforms |= non_conforms.MISSING_PREV_STATE;
const m::event::conforms report
{
event, non_conforms.report

View file

@ -174,7 +174,6 @@ put__invite(client &client,
};
m::event::conforms non_conforms;
non_conforms |= non_conforms.MISSING_PREV_STATE;
const m::event::conforms report
{
event, non_conforms.report

View file

@ -57,7 +57,6 @@ handle_edu(client &client,
vmopts.non_conform.set(m::event::conforms::MISSING_SIGNATURES);
vmopts.non_conform.set(m::event::conforms::MISSING_PREV_EVENTS);
vmopts.non_conform.set(m::event::conforms::MISSING_AUTH_EVENTS);
vmopts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
vmopts.non_conform.set(m::event::conforms::DEPTH_ZERO);
m::vm::eval eval
{
@ -73,7 +72,6 @@ handle_pdus(client &client,
{
m::vm::opts vmopts;
vmopts.node_id = request.origin;
vmopts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
vmopts.nothrows = -1U;
vmopts.infolog_accept = true;
m::vm::eval eval

View file

@ -108,7 +108,6 @@ put__send_join(client &client,
};
m::vm::opts vmopts;
vmopts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
m::vm::eval eval
{
event, vmopts

View file

@ -108,7 +108,6 @@ put__send_leave(client &client,
};
m::vm::opts vmopts;
vmopts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
m::vm::eval eval
{
event, vmopts