From 142179e4a582ddfba786d1e9ffaba2e61d561b76 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 15 Oct 2020 01:33:14 -0700 Subject: [PATCH] ircd::m::fed::well_known: Convert to future interface w/ dummy impl. --- include/ircd/m/fed/well_known.h | 3 ++- matrix/fed.cc | 10 ++++++--- matrix/fed_well_known.cc | 40 ++++++++++++++++++++++----------- modules/console.cc | 3 +-- 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/include/ircd/m/fed/well_known.h b/include/ircd/m/fed/well_known.h index ba181d878..64620dd06 100644 --- a/include/ircd/m/fed/well_known.h +++ b/include/ircd/m/fed/well_known.h @@ -15,7 +15,8 @@ namespace ircd::m::fed::well_known { struct opts; - string_view get(const mutable_buffer &, const string_view &, const opts &); + ctx::future + get(const mutable_buffer &out, const string_view &name, const opts &); extern conf::item fetch_redirects; extern conf::item fetch_timeout; diff --git a/matrix/fed.cc b/matrix/fed.cc index 383f24c80..e24e21813 100644 --- a/matrix/fed.cc +++ b/matrix/fed.cc @@ -1654,11 +1654,15 @@ ircd::m::fed::server(const mutable_buffer &buf, string_view target { - !port(remote)? - well_known::get(buf, host(remote), opts): - name + name }; + if(!port(remote)) + target = string_view + { + well_known::get(buf, host(remote), opts) + }; + remote = target; if(!port(remote) && !service(remote)) { diff --git a/matrix/fed_well_known.cc b/matrix/fed_well_known.cc index b325eca8a..08ea5b39d 100644 --- a/matrix/fed_well_known.cc +++ b/matrix/fed_well_known.cc @@ -23,6 +23,7 @@ namespace ircd::m::fed::well_known struct ircd::m::fed::well_known::request { static const string_view path; + static const string_view type; static const server::request::opts sopts; unique_mutable_buffer buf; @@ -49,6 +50,12 @@ ircd::m::fed::well_known::request::path "/.well-known/matrix/server" }; +decltype(ircd::m::fed::well_known::request::type) +ircd::m::fed::well_known::request::type +{ + "well-known.matrix.server" +}; + decltype(ircd::m::fed::well_known::request::sopts) ircd::m::fed::well_known::request::sopts { @@ -91,17 +98,12 @@ ircd::m::fed::well_known::fetch_redirects { "default", 2L }, }; -ircd::string_view +ircd::ctx::future ircd::m::fed::well_known::get(const mutable_buffer &buf, const string_view &origin, const opts &opts) try { - static const string_view type - { - "well-known.matrix.server" - }; - const m::room::id::buf room_id { "dns", m::my_host() @@ -115,7 +117,7 @@ try const m::event::idx event_idx { likely(opts.cache_check)? - room.get(std::nothrow, type, origin): + room.get(std::nothrow, request::type, origin): 0UL }; @@ -169,7 +171,10 @@ try timef(tmbuf, expires, localtime), }; - return cached; + return ctx::future + { + ctx::already, cached + }; } const string_view fetched @@ -207,7 +212,10 @@ try }; assert(opts.cache_check); - return cached; + return ctx::future + { + ctx::already, cached + }; } if(likely(opts.request && opts.cache_result)) @@ -228,7 +236,7 @@ try // simpler, but we don't share the ircd.dns.rr type prefix anyway. const auto cache_id { - m::send(room, m::me(), type, origin, json::members + m::send(room, m::me(), request::type, origin, json::members { { "ttl", cache_ttl }, { "m.server", delegated }, @@ -244,7 +252,10 @@ try }; } - return delegated; + return ctx::future + { + ctx::already, delegated + }; } catch(const ctx::interrupted &) { @@ -259,9 +270,12 @@ catch(const std::exception &e) e.what(), }; - return string_view + return ctx::future { - data(buf), move(buf, origin) + ctx::already, string_view + { + data(buf), move(buf, origin) + } }; } diff --git a/modules/console.cc b/modules/console.cc index 502908d44..96f05e448 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -15999,8 +15999,7 @@ console_cmd__well_known__matrix__server(opt &out, const string_view &line) m::fed::well_known::opts opts; opts.cache_check = false; opts.cache_result = false; - - const net::hostport result + const string_view result { m::fed::well_known::get(buf, remote, opts) };