From da8beda0c33681256fca1aed9e0b1fdfa4d7354d Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 30 Sep 2018 17:47:41 -0700 Subject: [PATCH] ircd::m::id: Support intuitive constructions of m::node::id. --- include/ircd/m/id.h | 41 ++++++++++++++++++++------------- ircd/m/event.cc | 2 +- ircd/m/m.cc | 4 ++-- ircd/m/request.cc | 2 +- ircd/resource.cc | 2 +- modules/console.cc | 14 +++++++++-- modules/federation/sender.int.h | 2 +- modules/s_keys.cc | 4 ++-- 8 files changed, 45 insertions(+), 26 deletions(-) diff --git a/include/ircd/m/id.h b/include/ircd/m/id.h index f9c449668..693cedcad 100644 --- a/include/ircd/m/id.h +++ b/include/ircd/m/id.h @@ -92,8 +92,8 @@ enum ircd::m::id::sigil ROOM = '!', ///< Room ID (4.2.2) ROOM_ALIAS = '#', ///< Room alias (4.2.3) GROUP = '+', ///< Group ID (experimental) - NODE = ':', ///< Node ID (experimental) DEVICE = '%', ///< Device ID (experimental) + NODE = ':', ///< Node ID (experimental) }; /// (Appendix 4.2.1) User Identifiers @@ -205,21 +205,6 @@ struct ircd::m::id::group group() = default; }; -/// Node ID (EXPERIMENTAL) -/// -struct ircd::m::id::node -:ircd::m::id -{ - using buf = m::id::buf; - - template - node(args&&... a) - :m::id{NODE, std::forward(a)...} - {} - - node() = default; -}; - /// Device ID (EXPERIMENTAL) /// struct ircd::m::id::device @@ -235,6 +220,30 @@ 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; +}; + // Utilities namespace ircd::m { diff --git a/ircd/m/event.cc b/ircd/m/event.cc index 89f936c0f..2052ef4f5 100644 --- a/ircd/m/event.cc +++ b/ircd/m/event.cc @@ -735,7 +735,7 @@ try { const m::node::id::buf node_id { - "", origin + m::node::id::origin, origin }; const m::node node diff --git a/ircd/m/m.cc b/ircd/m/m.cc index 2457d8cbc..ccbaca9eb 100644 --- a/ircd/m/m.cc +++ b/ircd/m/m.cc @@ -330,7 +330,7 @@ ircd::m::my_room ircd::m::node::id::buf ircd_node_id { - "", "localhost" // replaced after conf init + ircd::m::node::id::origin, "localhost" // replaced after conf init }; ircd::m::node @@ -370,7 +370,7 @@ ircd::m::self::init::init(const string_view &origin) ircd_room_id = {"ircd", origin}; m::my_room = {ircd_room_id}; - ircd_node_id = {"", origin}; + ircd_node_id = {node::id::origin, origin}; m::my_node = {ircd_node_id}; users_room_id = {"users", origin}; diff --git a/ircd/m/request.cc b/ircd/m/request.cc index c265e1af0..712df309f 100644 --- a/ircd/m/request.cc +++ b/ircd/m/request.cc @@ -181,7 +181,7 @@ const const m::node::id::buf node_id { - "", unquote(at<"origin"_>(*this)) + m::node::id::origin, unquote(at<"origin"_>(*this)) }; const m::node node diff --git a/ircd/resource.cc b/ircd/resource.cc index fee4c5dfa..2fe0910cb 100644 --- a/ircd/resource.cc +++ b/ircd/resource.cc @@ -267,7 +267,7 @@ try "The X-Matrix Authorization is invalid." }; - request.node_id = {"", x_matrix.origin}; + request.node_id = {m::node::id::origin, x_matrix.origin}; request.origin = x_matrix.origin; // If we have an error cached from previously not being able to diff --git a/modules/console.cc b/modules/console.cc index 13a3c8b2b..28f00c1a5 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -6948,9 +6948,14 @@ 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 { - param.at(0) + node_id }; auto limit @@ -6983,9 +6988,14 @@ 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 { - param.at(0) + node_id }; const auto &key_id diff --git a/modules/federation/sender.int.h b/modules/federation/sender.int.h index fc9205e9b..50ad2602c 100644 --- a/modules/federation/sender.int.h +++ b/modules/federation/sender.int.h @@ -89,7 +89,7 @@ struct node void push(std::shared_ptr); node(const string_view &origin) - :id{"", origin} + :id{m::node::id::origin, origin} ,room{id} {} }; diff --git a/modules/s_keys.cc b/modules/s_keys.cc index 3a056abc5..d1c668c1b 100644 --- a/modules/s_keys.cc +++ b/modules/s_keys.cc @@ -597,7 +597,7 @@ cache_set(const json::object &keys) const m::node::id::buf node_id { - "", server_name + m::node::id::origin, server_name }; const m::node::room node_room @@ -634,7 +634,7 @@ cache_get(const string_view &server_name, { const m::node::id::buf node_id { - "", server_name + m::node::id::origin, server_name }; const m::node::room node_room