From 719a965d9f5b52b917da53838e9733e2d9daf006 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 8 Jul 2019 23:23:39 -0700 Subject: [PATCH] ircd::m::event: Remove prev_state from top level. --- include/ircd/m/event/conforms.h | 3 - include/ircd/m/event/prev.h | 6 -- ircd/m_event.cc | 123 +------------------------------ ircd/m_room.cc | 3 - modules/client/rooms/invite.cc | 1 - modules/console.cc | 6 -- modules/federation/invite.cc | 1 - modules/federation/invite2.cc | 1 - modules/federation/send.cc | 2 - modules/federation/send_join.cc | 1 - modules/federation/send_leave.cc | 1 - 11 files changed, 1 insertion(+), 147 deletions(-) diff --git a/include/ircd/m/event/conforms.h b/include/ircd/m/event/conforms.h index dc473d4f6..9f3697e4e 100644 --- a/include/ircd/m/event/conforms.h +++ b/include/ircd/m/event/conforms.h @@ -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_ diff --git a/include/ircd/m/event/prev.h b/include/ircd/m/event/prev.h index d7cc85f7c..33238a3a8 100644 --- a/include/ircd/m/event/prev.h +++ b/include/ircd/m/event/prev.h @@ -38,28 +38,22 @@ struct ircd::m::event::prev :json::tuple < json::property, - json::property, json::property > { std::tuple auth_events(const size_t &idx) const; - std::tuple prev_states(const size_t &idx) const; std::tuple 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; diff --git a/ircd/m_event.cc b/ircd/m_event.cc index a6ee47c8b..d83a7c79b 100644 --- a/ircd/m_event.cc +++ b/ircd/m_event.cc @@ -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::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::prev::prev_events(const size_t &idx) const diff --git a/ircd/m_room.cc b/ircd/m_room.cc index fcf7358c7..6c19e1e4c 100644 --- a/ircd/m_room.cc +++ b/ircd/m_room.cc @@ -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; diff --git a/modules/client/rooms/invite.cc b/modules/client/rooms/invite.cc index e1b2cdd56..12b677075 100644 --- a/modules/client/rooms/invite.cc +++ b/modules/client/rooms/invite.cc @@ -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); diff --git a/modules/console.cc b/modules/console.cc index 65ab44052..43ecfa028 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -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 { diff --git a/modules/federation/invite.cc b/modules/federation/invite.cc index b2c040c79..cbaa5c630 100644 --- a/modules/federation/invite.cc +++ b/modules/federation/invite.cc @@ -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 diff --git a/modules/federation/invite2.cc b/modules/federation/invite2.cc index 2e9574e90..5262e68a3 100644 --- a/modules/federation/invite2.cc +++ b/modules/federation/invite2.cc @@ -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 diff --git a/modules/federation/send.cc b/modules/federation/send.cc index 82615a100..97ac85e2a 100644 --- a/modules/federation/send.cc +++ b/modules/federation/send.cc @@ -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 diff --git a/modules/federation/send_join.cc b/modules/federation/send_join.cc index 4ca8dc6c7..28cdd4347 100644 --- a/modules/federation/send_join.cc +++ b/modules/federation/send_join.cc @@ -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 diff --git a/modules/federation/send_leave.cc b/modules/federation/send_leave.cc index 9b02bd1ac..a37601e50 100644 --- a/modules/federation/send_leave.cc +++ b/modules/federation/send_leave.cc @@ -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