0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-26 00:32:35 +01:00

ircd:Ⓜ️:fed: Simplify and rename well known fetch function.

This commit is contained in:
Jason Volk 2020-03-07 12:53:33 -08:00
parent 4935015b18
commit a068981452
3 changed files with 25 additions and 16 deletions

View file

@ -14,7 +14,7 @@
namespace ircd::m::fed
{
net::hostport matrix_service(net::hostport);
net::hostport well_known(const mutable_buffer &out, const net::hostport &remote);
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);
}

View file

@ -1737,11 +1737,22 @@ ircd::m::fed::fetch_head(const id::room &room_id,
return prev_event_id;
}
ircd::net::hostport
ircd::m::fed::well_known(const mutable_buffer &buf,
const net::hostport &remote)
ircd::string_view
ircd::m::fed::fetch_well_known(const mutable_buffer &buf,
const string_view &origin)
try
{
const net::hostport remote
{
origin
};
// Hard target https service; do not inherit matrix service from remote.
const net::hostport target
{
host(remote), "https", port(remote)
};
const unique_buffer<mutable_buffer> head_buf
{
16_KiB
@ -1753,12 +1764,6 @@ try
wb, host(remote), "GET", "/.well-known/matrix/server",
};
// Hard target https service; do not inherit matrix service from remote.
const net::hostport target
{
host(remote), "https", port(remote)
};
const const_buffer out_head
{
wb.completed()
@ -1809,7 +1814,12 @@ try
string_view{response},
};
return matrix_service(ret);
// Move the returned string to the front of the buffer; this overwrites
// any other incoming content to focus on just the unquoted string.
return string_view
{
data(buf), move(buf, m_server)
};
}
catch(const ctx::interrupted &)
{
@ -1817,13 +1827,12 @@ catch(const ctx::interrupted &)
}
catch(const std::exception &e)
{
thread_local char rembuf[rfc3986::DOMAIN_BUFSIZE * 2];
log::derror
{
log, "Matrix server well-known query for %s :%s",
string(rembuf, remote),
origin,
e.what(),
};
return remote;
return origin;
}

View file

@ -14693,7 +14693,7 @@ console_cmd__well_known__matrix__server(opt &out, const string_view &line)
"remote"
}};
const net::hostport &remote
const string_view &remote
{
param.at("remote")
};
@ -14705,7 +14705,7 @@ console_cmd__well_known__matrix__server(opt &out, const string_view &line)
const net::hostport result
{
m::fed::well_known(buf, remote)
m::fed::fetch_well_known(buf, remote)
};
out << result << std::endl;