From c0a5a7a89ef8dc6a96f9d021129ad4e8d2007437 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 7 Mar 2020 17:09:09 -0800 Subject: [PATCH] ircd::m: Simplify various interfaces using string rather than net::hostport remotes. --- include/ircd/m/fed/fed.h | 4 ++-- include/ircd/m/room/aliases.h | 4 ++-- include/ircd/m/user/profile.h | 2 +- matrix/fed.cc | 4 ++-- matrix/keys.cc | 2 +- matrix/room_aliases.cc | 22 ++++++++-------------- matrix/user_profile.cc | 2 +- modules/console.cc | 9 ++++----- 8 files changed, 21 insertions(+), 28 deletions(-) diff --git a/include/ircd/m/fed/fed.h b/include/ircd/m/fed/fed.h index 0f282bf6e..7a2eb97f2 100644 --- a/include/ircd/m/fed/fed.h +++ b/include/ircd/m/fed/fed.h @@ -15,8 +15,8 @@ namespace ircd::m::fed { net::hostport matrix_service(net::hostport); string_view fetch_well_known(const mutable_buffer &out, const string_view &origin); - id::event::buf fetch_head(const id::room &room_id, const net::hostport &remote, const id::user &); - id::event::buf fetch_head(const id::room &room_id, const net::hostport &remote); + id::event::buf fetch_head(const id::room &room_id, const string_view &remote, const id::user &); + id::event::buf fetch_head(const id::room &room_id, const string_view &remote); } #include "version.h" diff --git a/include/ircd/m/room/aliases.h b/include/ircd/m/room/aliases.h index 3ef723e39..a0dd15e36 100644 --- a/include/ircd/m/room/aliases.h +++ b/include/ircd/m/room/aliases.h @@ -56,8 +56,8 @@ struct ircd::m::room::aliases::cache static bool for_each(const string_view &server, const closure_bool &); static bool for_each(const closure_bool &); - static void fetch(const alias &, const net::hostport &remote); - static bool fetch(std::nothrow_t, const alias &, const net::hostport &remote); + static void fetch(const alias &, const string_view &remote); + static bool fetch(std::nothrow_t, const alias &, const string_view &remote); static bool get(std::nothrow_t, const alias &, const id::closure &); static void get(const alias &, const id::closure &); diff --git a/include/ircd/m/user/profile.h b/include/ircd/m/user/profile.h index 0ecd4981e..cef3c66e7 100644 --- a/include/ircd/m/user/profile.h +++ b/include/ircd/m/user/profile.h @@ -19,7 +19,7 @@ struct ircd::m::user::profile m::user user; - static void fetch(const m::user &, const net::hostport &, const string_view &key = {}); + static void fetch(const m::user &, const string_view &, const string_view &key = {}); public: bool for_each(const closure_bool &) const; diff --git a/matrix/fed.cc b/matrix/fed.cc index c3b9969b3..ad2c744ee 100644 --- a/matrix/fed.cc +++ b/matrix/fed.cc @@ -1675,7 +1675,7 @@ fetch_head_timeout ircd::m::event::id::buf ircd::m::fed::fetch_head(const id::room &room_id, - const net::hostport &remote) + const string_view &remote) { const m::room room { @@ -1702,7 +1702,7 @@ ircd::m::fed::fetch_head(const id::room &room_id, ircd::m::event::id::buf ircd::m::fed::fetch_head(const id::room &room_id, - const net::hostport &remote, + const string_view &remote, const id::user &user_id) { const unique_buffer buf diff --git a/matrix/keys.cc b/matrix/keys.cc index c55046e93..efb59eeee 100644 --- a/matrix/keys.cc +++ b/matrix/keys.cc @@ -219,7 +219,7 @@ try assert(!query_server.empty()); m::fed::key::opts opts; - opts.remote = net::hostport{query_server}; + opts.remote = query_server; opts.dynamic = true; const unique_buffer buf { diff --git a/matrix/room_aliases.cc b/matrix/room_aliases.cc index fde08d50c..aad6325b2 100644 --- a/matrix/room_aliases.cc +++ b/matrix/room_aliases.cc @@ -283,29 +283,23 @@ ircd::m::room::aliases::cache::get(std::nothrow_t, return ret; } -namespace ircd::m -{ - thread_local char room_aliases_cache_fetch_hpbuf[384]; -} - bool IRCD_MODULE_EXPORT ircd::m::room::aliases::cache::fetch(std::nothrow_t, const alias &a, - const net::hostport &hp) + const string_view &remote) try { - fetch(a, hp); + fetch(a, remote); return true; } catch(const std::exception &e) { - thread_local char buf[384]; log::error { log, "Failed to fetch room_id for %s from %s :%s", string_view{a}, - string(buf, hp), + remote, e.what(), }; @@ -364,7 +358,7 @@ ircd::m::room::aliases::cache::for_each(const closure_bool &c) void IRCD_MODULE_EXPORT ircd::m::room::aliases::cache::fetch(const alias &alias, - const net::hostport &hp) + const string_view &remote) try { const unique_buffer buf @@ -373,7 +367,7 @@ try }; m::fed::query::opts opts; - opts.remote = hp; + opts.remote = remote; opts.dynamic = true; m::fed::query::directory request @@ -401,7 +395,7 @@ try throw m::NOT_FOUND { "Server '%s' does not know room_id for %s", - string(room_aliases_cache_fetch_hpbuf, hp), + remote, string_view{alias}, }; @@ -413,7 +407,7 @@ catch(const ctx::timeout &e) { http::GATEWAY_TIMEOUT, "M_ROOM_ALIAS_TIMEOUT", "Server '%s' did not respond with a room_id for %s in time", - string(room_aliases_cache_fetch_hpbuf, hp), + remote, string_view{alias}, }; } @@ -423,7 +417,7 @@ catch(const server::unavailable &e) { http::BAD_GATEWAY, "M_ROOM_ALIAS_UNAVAILABLE", "Server '%s' is not available to query a room_id for %s", - string(room_aliases_cache_fetch_hpbuf, hp), + remote, string_view{alias}, }; } diff --git a/matrix/user_profile.cc b/matrix/user_profile.cc index 42a1183f5..353d605b9 100644 --- a/matrix/user_profile.cc +++ b/matrix/user_profile.cc @@ -123,7 +123,7 @@ const void IRCD_MODULE_EXPORT ircd::m::user::profile::fetch(const m::user &user, - const net::hostport &remote, + const string_view &remote, const string_view &key) { const unique_buffer buf diff --git a/modules/console.cc b/modules/console.cc index ee0ee4955..d0352b88c 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -14087,14 +14087,13 @@ console_cmd__fed__key__query(opt &out, const string_view &line) bool console_cmd__fed__version(opt &out, const string_view &line) { - const net::hostport remote + const params param{line, " ", { - token(line, ' ', 0) - }; + "remote" + }}; m::fed::version::opts opts; - opts.remote = remote; - + opts.remote = param.at("remote"); const unique_mutable_buffer buf { 16_KiB