diff --git a/include/ircd/m/id.h b/include/ircd/m/id.h index 5e6ade1da..104b8a3c2 100644 --- a/include/ircd/m/id.h +++ b/include/ircd/m/id.h @@ -45,7 +45,6 @@ struct ircd::m::id struct room; struct room_alias; struct group; - struct node; struct device; enum sigil :char; @@ -119,7 +118,6 @@ enum ircd::m::id::sigil ROOM_ALIAS = '#', ///< Room alias (4.2.3) GROUP = '+', ///< Group ID (experimental) DEVICE = '%', ///< Device ID (experimental) - NODE = ':', ///< Node ID (experimental) }; /// (Appendix 4.2.1) User Identifiers @@ -246,30 +244,6 @@ struct ircd::m::id::device device() = default; }; -/// Node ID (EXPERIMENTAL) -/// -struct ircd::m::id::node -:ircd::m::id -{ - using buf = m::id::buf; - - IRCD_OVERLOAD(domain) - node(const mutable_buffer &mb, domain_t, const string_view &domain_, const string_view &origin_) - :m::id{NODE, mb, domain_, origin_} - {} - - IRCD_OVERLOAD(origin) - node(const mutable_buffer &mb, origin_t, const string_view &origin_) - :m::id{NODE, mb, string_view{}, origin_} - {} - - node(const string_view &id) - :m::id{NODE, id} - {} - - node() = default; -}; - /// ID object backed by an internal buffer of default worst-case size. /// template diff --git a/include/ircd/m/node.h b/include/ircd/m/node.h index 7ba9b4be6..97a4c19db 100644 --- a/include/ircd/m/node.h +++ b/include/ircd/m/node.h @@ -18,8 +18,8 @@ namespace ircd::m extern room nodes; bool my(const node &); - bool exists(const id::node &); - node create(const id::node &, const json::members &args = {}); + bool exists(const node &); + node create(const node &, const json::members &args = {}); } /// A node is an entity (lay: a server) participating in the matrix system. The @@ -37,13 +37,10 @@ namespace ircd::m struct ircd::m::node { struct room; - using id = m::id::node; using key_closure = std::function; // remember to unquote()!!! using ed25519_closure = std::function; - id node_id; - - operator const id &() const; + string_view node_id; id::room room_id(const mutable_buffer &) const; id::room::buf room_id() const; @@ -51,9 +48,11 @@ struct ircd::m::node void key(const string_view &key_id, const ed25519_closure &) const; void key(const string_view &key_id, const key_closure &) const; - node(const id &node_id) + node(const string_view &node_id) :node_id{node_id} - {} + { + rfc3986::valid_remote(node_id); + } node() = default; }; @@ -68,15 +67,8 @@ struct ircd::m::node::room id::room::buf room_id; room(const m::node &node); - room(const m::node::id &node_id); + room(const string_view &node_id); room() = default; room(const room &) = delete; room &operator=(const room &) = delete; }; - -inline ircd::m::node::operator -const ircd::m::node::id &() -const -{ - return node_id; -} diff --git a/include/ircd/m/v1/groups.h b/include/ircd/m/v1/groups.h index db46d2f3d..fc6cb03d5 100644 --- a/include/ircd/m/v1/groups.h +++ b/include/ircd/m/v1/groups.h @@ -26,7 +26,7 @@ struct ircd::m::v1::groups::publicised return json::object{in.content}; } - publicised(const id::node &, const vector_view &, const mutable_buffer &, opts); + publicised(const string_view &, const vector_view &, const mutable_buffer &, opts); publicised() = default; }; diff --git a/ircd/m.cc b/ircd/m.cc index e102c5cf2..a66ba0eb0 100644 --- a/ircd/m.cc +++ b/ircd/m.cc @@ -335,10 +335,10 @@ ircd::m::my_room // my node // -ircd::m::node::id::buf +std::array ircd_node_id { - ircd::m::node::id::origin, "localhost" // replaced after conf init + "localhost" // replaced after conf init }; ircd::m::node @@ -402,15 +402,17 @@ ircd::m::self::init::init(const string_view &origin, self::origin = origin; self::servername = servername; + m::my_node = string_view{strlcpy + { + ircd_node_id, origin + }}; + ircd_user_id = {"ircd", origin}; m::me = {ircd_user_id}; ircd_room_id = {"ircd", origin}; m::my_room = {ircd_room_id}; - ircd_node_id = {node::id::origin, origin}; - m::my_node = {ircd_node_id}; - users_room_id = {"users", origin}; m::user::users = {users_room_id}; @@ -2270,37 +2272,36 @@ ircd::m::nodes }; ircd::m::node -ircd::m::create(const id::node &node_id, +ircd::m::create(const node &node, const json::members &args) { - using prototype = node (const id::node &, const json::members &); + using prototype = m::node (const m::node &, const json::members &); static mods::import function { "s_node", "create_node" }; - assert(node_id); - return function(node_id, args); + return function(node, args); } bool -ircd::m::exists(const node::id &node_id) +ircd::m::exists(const node &node) { - using prototype = bool (const node::id &); + using prototype = bool (const string_view &); static mods::import function { "s_node", "exists__nodeid" }; - return function(node_id); + return function(node.node_id); } bool ircd::m::my(const node &node) { - return my(node.node_id); + return my_host(node.node_id); } // @@ -2332,12 +2333,7 @@ ircd::m::node::key(const string_view &key_id, const key_closure &closure) const { - const auto &server_name - { - node_id.hostname() - }; - - m::keys::get(server_name, key_id, [&closure, &key_id] + m::keys::get(node_id, key_id, [&closure, &key_id] (const json::object &keys) { const json::object &vks @@ -2376,16 +2372,32 @@ ircd::m::id::room ircd::m::node::room_id(const mutable_buffer &buf) const { - assert(!empty(node_id)); + assert(!empty(this->node_id)); + + // for compatibility with hashing legacy node_id's + thread_local char node_id_buf[m::id::MAX_SIZE]; + mutable_buffer mb{node_id_buf}; + consume(mb, copy(mb, "::"_sv)); + consume(mb, copy(mb, this->node_id)); + const string_view &node_id + { + node_id_buf, data(mb) + }; + const sha256::buf hash { sha256{node_id} }; - char b58[size(hash) * 2]; - return + thread_local char b58_buf[b58encode_size(size(hash))]; + const string_view b58 { - buf, b58encode(b58, hash), my_host() + b58encode(b58_buf, hash) + }; + + return id::room + { + buf, b58, my_host() }; } @@ -2393,7 +2405,7 @@ const // node::room // -ircd::m::node::room::room(const m::node::id &node_id) +ircd::m::node::room::room(const string_view &node_id) :room{m::node{node_id}} {} @@ -4690,14 +4702,14 @@ const } }; - const m::node::id::buf node_id + const json::string &origin { - m::node::id::origin, unquote(at<"origin"_>(*this)) + at<"origin"_>(*this) }; const m::node node { - node_id + origin }; bool verified{false}; diff --git a/ircd/m_event.cc b/ircd/m_event.cc index cf3d299ff..0c0e76c7b 100644 --- a/ircd/m_event.cc +++ b/ircd/m_event.cc @@ -3389,14 +3389,9 @@ ircd::m::verify(const event &event, const string_view &keyid) try { - const m::node::id::buf node_id - { - m::node::id::origin, origin - }; - const m::node node { - node_id + origin }; bool ret{false}; diff --git a/ircd/m_id.cc b/ircd/m_id.cc index 33ba4f733..829ce2f9a 100644 --- a/ircd/m_id.cc +++ b/ircd/m_id.cc @@ -28,7 +28,6 @@ struct ircd::m::id::input const rule room_id_sigil { lit(char(id::ROOM)) ,"room_id sigil" }; const rule room_alias_sigil { lit(char(id::ROOM_ALIAS)) ,"room_alias sigil" }; const rule group_id_sigil { lit(char(id::GROUP)) ,"group_id sigil" }; - const rule node_sigil { lit(char(id::NODE)) ,"node sigil" }; const rule device_sigil { lit(char(id::DEVICE)) ,"device sigil" }; const rule sigil { @@ -37,7 +36,6 @@ struct ircd::m::id::input room_id_sigil | room_alias_sigil | group_id_sigil | - node_sigil | device_sigil ,"sigil" }; @@ -756,7 +754,6 @@ ircd::m::reflect(const id::sigil &c) case id::ROOM: return "ROOM"_sv; case id::ROOM_ALIAS: return "ROOM_ALIAS"_sv; case id::GROUP: return "GROUP"_sv; - case id::NODE: return "NODE"_sv; case id::DEVICE: return "DEVICE"_sv; } diff --git a/ircd/m_v1.cc b/ircd/m_v1.cc index 129eaffaf..9e6dafceb 100644 --- a/ircd/m_v1.cc +++ b/ircd/m_v1.cc @@ -13,20 +13,20 @@ // v1/groups.h // -ircd::m::v1::groups::publicised::publicised(const id::node &node, +ircd::m::v1::groups::publicised::publicised(const string_view &node, const vector_view &user_ids, const mutable_buffer &buf_, opts opts) :server::request{[&] { if(!opts.remote) - opts.remote = node.host(); + opts.remote = node; if(!defined(json::get<"origin"_>(opts.request))) json::get<"origin"_>(opts.request) = my_host(); if(!defined(json::get<"destination"_>(opts.request))) - json::get<"destination"_>(opts.request) = node.host(); + json::get<"destination"_>(opts.request) = node; if(!defined(json::get<"uri"_>(opts.request))) json::get<"uri"_>(opts.request) = "/_matrix/federation/v1/get_groups_publicised"; diff --git a/modules/console.cc b/modules/console.cc index 1bdd92dba..a0d44a5ee 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -351,7 +351,6 @@ console_cmd__time(opt &out, const string_view &line) int console_command_numeric(opt &, const string_view &line); bool console_id__user(opt &, const m::user::id &id, const string_view &line); -bool console_id__node(opt &, const m::node::id &id, const string_view &line); bool console_id__room(opt &, const m::room::id &id, const string_view &line); bool console_id__event(opt &, const m::event::id &id, const string_view &line); bool console_json(const json::object &); @@ -378,9 +377,6 @@ console_command_derived(opt &out, const string_view &line) case m::id::ROOM: return console_id__room(out, id, line); - case m::id::NODE: - return console_id__node(out, id, line); - case m::id::USER: return console_id__user(out, id, line); @@ -9481,18 +9477,19 @@ console_cmd__room__id(opt &out, const string_view &id) { case m::id::USER: out << m::user{id}.room_id() << std::endl; - break; - - case m::id::NODE: - out << m::node{id}.room_id() << std::endl; - break; + return true; case m::id::ROOM_ALIAS: out << m::room_id(m::room::alias(id)) << std::endl; - break; + return true; default: - break; + return true; + } + else if(rfc3986::valid_remote(std::nothrow, id)) + { + out << m::node{id}.room_id() << std::endl; + return true; } return true; @@ -10651,15 +10648,6 @@ console_cmd__typing(opt &out, const string_view &line) // node // -//TODO: XXX -bool -console_id__node(opt &out, - const m::node::id &id, - const string_view &args) -{ - return true; -} - bool console_cmd__node__keys(opt &out, const string_view &line) { @@ -10668,14 +10656,9 @@ console_cmd__node__keys(opt &out, const string_view &line) "node_id", "[limit]" }}; - const m::node::id::buf node_id - { - m::node::id::origin, param.at(0) - }; - const m::node &node { - node_id + param.at("node_id") }; auto limit @@ -10708,14 +10691,9 @@ console_cmd__node__key(opt &out, const string_view &line) "node_id", "key_id" }}; - const m::node::id::buf node_id - { - m::node::id::origin, param.at(0) - }; - const m::node &node { - node_id + param.at("node_id") }; const auto &key_id @@ -11279,7 +11257,7 @@ console_cmd__feds__resend(opt &out, const string_view &line) bool console_cmd__fed__groups(opt &out, const string_view &line) { - const m::id::node &node + const string_view node { token(line, ' ', 0) }; diff --git a/modules/federation/sender.cc b/modules/federation/sender.cc index 43d07ac32..c2bee9178 100644 --- a/modules/federation/sender.cc +++ b/modules/federation/sender.cc @@ -245,7 +245,7 @@ try } m::v1::send::opts opts; - opts.remote = origin(); + opts.remote = remote; opts.sopts = &sopts; const vector_view pduv @@ -274,7 +274,7 @@ catch(const std::exception &e) { log::error { - "flush error to %s :%s", string_view{id}, e.what() + "flush error to %s :%s", remote, e.what() }; err = true; @@ -372,7 +372,7 @@ try "%u %s from %s for %s", ushort(code), http::status(code), - string_view{node.id}, + node.remote, txn.txnid }; @@ -385,7 +385,7 @@ try log::derror { "Error from %s in %s for %s :%s", - string_view{node.id}, + node.remote, txn.txnid, string_view{event_id}, string_view{error} @@ -401,7 +401,7 @@ catch(const http::error &e) "%u %s from %s for %s :%s", ushort(e.code), http::status(e.code), - string_view{node.id}, + node.remote, txn.txnid, e.what() }; @@ -414,7 +414,7 @@ catch(const std::exception &e) log::derror { "Error from %s for %s :%s", - string_view{node.id}, + node.remote, txn.txnid, e.what() }; @@ -451,7 +451,7 @@ recv_timeout(txn &txn, log::dwarning { "Timeout to %s for txn %s", - string_view{node.id}, + node.remote, txn.txnid }; @@ -464,7 +464,7 @@ remove_node(const node &node) { const auto it { - nodes.find(node.origin()) + nodes.find(node.remote) }; assert(it != end(nodes)); diff --git a/modules/federation/sender.int.h b/modules/federation/sender.int.h index 50ad2602c..e720a9f62 100644 --- a/modules/federation/sender.int.h +++ b/modules/federation/sender.int.h @@ -74,23 +74,19 @@ struct txndata struct node { std::deque> q; - m::node::id::buf id; + std::array rembuf; + string_view remote; m::node::room room; server::request::opts sopts; txn *curtxn {nullptr}; bool err {false}; - string_view origin() const - { - return id.host(); - }; - bool flush(); void push(std::shared_ptr); - node(const string_view &origin) - :id{m::node::id::origin, origin} - ,room{id} + node(const string_view &remote) + :remote{strlcpy{rembuf, remote}} + ,room{this->remote} {} }; diff --git a/modules/m_room_history_visibility.cc b/modules/m_room_history_visibility.cc index 9fe709897..92eb10da7 100644 --- a/modules/m_room_history_visibility.cc +++ b/modules/m_room_history_visibility.cc @@ -17,10 +17,10 @@ IRCD_MODULE }; static bool -_visible_(const m::event &event, - const m::user::id &user_id, - const m::room &room, - const string_view &history_visibility) +_visible_to_user(const m::event &event, + const m::user::id &user_id, + const m::room &room, + const string_view &history_visibility) { char membership_buf[m::MEMBERSHIP_MAX_SIZE]; string_view membership @@ -54,10 +54,10 @@ _visible_(const m::event &event, } static bool -_visible_(const m::event &event, - const m::node::id &node_id, - const m::room &room, - const string_view &history_visibility) +_visible_to_node(const m::event &event, + const string_view &node_id, + const m::room &room, + const string_view &history_visibility) { const m::room::origins origins { @@ -65,7 +65,7 @@ _visible_(const m::event &event, }; // Allow joined servers - if(origins.has(node_id.host())) + if(origins.has(node_id)) return true; // Allow auth chain events XXX: this is too broad @@ -75,7 +75,7 @@ _visible_(const m::event &event, // Allow any event where the state_key string is a user mxid and the server // is the host of that user. Note that applies to any type of event. if(m::valid(m::id::USER, json::get<"state_key"_>(event))) - if(m::user::id(at<"state_key"_>(event)).host() == node_id.host()) + if(m::user::id(at<"state_key"_>(event)).host() == node_id) return true; return false; @@ -93,20 +93,16 @@ _visible(const m::event &event, if(empty(mxid)) return false; - switch(m::sigil(mxid)) + if(m::valid(m::id::USER, mxid)) + return _visible_to_user(event, mxid, room, history_visibility); + + if(rfc3986::valid_remote(std::nothrow, mxid)) + return _visible_to_node(event, mxid, room, history_visibility); + + throw m::UNSUPPORTED { - case m::id::USER: - return _visible_(event, m::user::id{mxid}, room, history_visibility); - - case m::id::NODE: - return _visible_(event, m::node::id{mxid}, room, history_visibility); - - default: throw m::UNSUPPORTED - { - "Cannot determine visibility for '%s' mxids", - reflect(m::sigil(mxid)) - }; - } + "Cannot determine visibility for '%s'", mxid + }; } bool diff --git a/modules/s_keys.cc b/modules/s_keys.cc index f3720119c..9758d8b8b 100644 --- a/modules/s_keys.cc +++ b/modules/s_keys.cc @@ -639,19 +639,14 @@ ircd::m::create_my_key() size_t ircd::m::keys_cache_set(const json::object &keys) { - const auto &server_name + const json::string &server_name { - unquote(keys.at("server_name")) - }; - - const m::node::id::buf node_id - { - m::node::id::origin, server_name + keys.at("server_name") }; const m::node::room node_room { - node_id + server_name }; if(!exists(node_room.room_id)) @@ -681,14 +676,9 @@ ircd::m::keys_cache_get(const string_view &server_name, const string_view &key_id, const keys::closure &closure) { - const m::node::id::buf node_id - { - m::node::id::origin, server_name - }; - const m::node::room node_room { - node_id + server_name }; const auto reclosure{[&closure] diff --git a/modules/s_node.cc b/modules/s_node.cc index 58119de8e..774f66b71 100644 --- a/modules/s_node.cc +++ b/modules/s_node.cc @@ -23,14 +23,10 @@ nodes_room }; extern "C" m::node -create_node(const m::node::id &node_id, +create_node(const m::node &node, const json::members &args) { - const m::node node - { - node_id - }; - + assert(node.node_id); const m::room::id::buf room_id { node.room_id() @@ -38,12 +34,12 @@ create_node(const m::node::id &node_id, //TODO: ABA create(room_id, m::me.user_id); - send(nodes_room, m::me.user_id, "ircd.node", node_id, args); + send(nodes_room, m::me.user_id, "ircd.node", node.node_id, args); return node; } extern "C" bool -exists__nodeid(const m::node::id &node_id) +exists__nodeid(const string_view &node_id) { return nodes_room.has("ircd.node", node_id); }