0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 18:22:50 +01:00

ircd:Ⓜ️:fed: Simplify cache record composition; use json::members iov.

This commit is contained in:
Jason Volk 2020-03-09 09:09:36 -07:00
parent 3cf10f853f
commit c4ef486ebd

View file

@ -1579,51 +1579,26 @@ try
return delegated;
}
// We hijack the user's buffer to construct the event content for the
// cache record. Since we might have already used this buffer for the
// actual well-known network query we window it down to not overwrite
// our payload string.
const mutable_buffer out_buf
{
buf + size(delegated)
};
// Print our cache record to the buffer; note that this doesn't really
// match the format of other DNS records in this room since it's a bit
// simpler, but we don't share the ircd.dns.rr type prefix anyway.
json::stack out{out_buf};
{
json::stack::object content
{
out
};
json::stack::member
{
content, "ttl", json::value
{
// Any time the well-known result is the same as the origin (that
// includes legitimate errors where fetch_well_known() returns the
// origin to default) we consider that an error and use the error
// TTL value. Sorry, no exponential backoff implemented yet.
const auto cache_ttl
{
origin == delegated?
seconds(well_known_cache_error).count():
seconds(well_known_cache_default).count()
}
};
json::stack::member
{
content, "m.server", delegated
};
}
// Write to the !dns room
// Write our record to the cache room; note that this doesn't really
// match the format of other DNS records in this room since it's a bit
// 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::object
m::send(room, m::me(), type, origin, json::members
{
out.completed()
{ "ttl", cache_ttl },
{ "m.server", delegated },
})
};