mirror of
https://github.com/matrix-construct/construct
synced 2024-12-27 07:54:05 +01:00
ircd::net::dns: Expose more cache utils to public interface.
This commit is contained in:
parent
59b0b633cb
commit
a1ac9cb356
4 changed files with 64 additions and 29 deletions
|
@ -83,6 +83,10 @@ namespace ircd::net::dns::cache
|
|||
{
|
||||
using closure = std::function<bool (const string_view &, const json::object &)>;
|
||||
|
||||
bool is_error(const json::object &rr);
|
||||
time_t get_ttl(const json::object &rr);
|
||||
bool expired(const json::object &rr, const time_t &rr_ts, const time_t &min_ttl);
|
||||
bool expired(const json::object &rr, const time_t &rr_ts);
|
||||
string_view make_type(const mutable_buffer &out, const string_view &);
|
||||
string_view make_type(const mutable_buffer &out, const uint16_t &);
|
||||
|
||||
|
|
57
ircd/net.cc
57
ircd/net.cc
|
@ -3507,6 +3507,63 @@ ircd::net::dns::cache::make_type(const mutable_buffer &out,
|
|||
};
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::net::dns::cache::expired(const json::object &rr,
|
||||
const time_t &rr_ts)
|
||||
{
|
||||
static mods::import<conf::item<seconds>> min_ttl
|
||||
{
|
||||
"s_dns", "ircd::net::dns::cache::min_ttl"
|
||||
};
|
||||
|
||||
static mods::import<conf::item<seconds>> error_ttl
|
||||
{
|
||||
"s_dns", "ircd::net::dns::cache::error_ttl"
|
||||
};
|
||||
|
||||
const conf::item<seconds> &min_ttl_item
|
||||
{
|
||||
static_cast<conf::item<seconds> &>(min_ttl)
|
||||
};
|
||||
|
||||
const conf::item<seconds> &error_ttl_item
|
||||
{
|
||||
static_cast<conf::item<seconds> &>(error_ttl)
|
||||
};
|
||||
|
||||
const seconds &min_seconds(min_ttl_item);
|
||||
const seconds &err_seconds(error_ttl_item);
|
||||
const time_t &min
|
||||
{
|
||||
is_error(rr)?
|
||||
err_seconds.count():
|
||||
min_seconds.count()
|
||||
};
|
||||
|
||||
return expired(rr, rr_ts, min);
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::net::dns::cache::expired(const json::object &rr,
|
||||
const time_t &rr_ts,
|
||||
const time_t &min_ttl)
|
||||
{
|
||||
const auto ttl(get_ttl(rr));
|
||||
return rr_ts + std::max(ttl, min_ttl) < ircd::time();
|
||||
}
|
||||
|
||||
time_t
|
||||
ircd::net::dns::cache::get_ttl(const json::object &rr)
|
||||
{
|
||||
return rr.get<time_t>("ttl", 0L);
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::net::dns::cache::is_error(const json::object &rr)
|
||||
{
|
||||
return rr.has("error");
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// net/ipport.h
|
||||
|
|
|
@ -760,29 +760,6 @@ ircd::net::dns::cache::call_waiter(const string_view &type,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::net::dns::cache::expired(const json::object &rr,
|
||||
const time_t &ts)
|
||||
{
|
||||
const auto ttl(get_ttl(rr));
|
||||
return ts + ttl < ircd::time();
|
||||
}
|
||||
|
||||
time_t
|
||||
ircd::net::dns::cache::get_ttl(const json::object &rr)
|
||||
{
|
||||
const seconds &min_ttl_s(min_ttl);
|
||||
const seconds &err_ttl_s(error_ttl);
|
||||
const time_t min_ttl_t(min_ttl_s.count());
|
||||
const time_t err_ttl_t(err_ttl_s.count());
|
||||
const time_t rr_ttl
|
||||
{
|
||||
rr.get<time_t>("ttl", err_ttl_t)
|
||||
};
|
||||
|
||||
return std::max(rr_ttl, min_ttl_t);
|
||||
}
|
||||
|
||||
//
|
||||
// cache room creation
|
||||
//
|
||||
|
|
|
@ -34,15 +34,12 @@ namespace ircd::net::dns::cache
|
|||
{
|
||||
struct waiter;
|
||||
|
||||
static time_t get_ttl(const json::object &rr);
|
||||
static bool expired(const json::object &rr, const time_t &ts);
|
||||
|
||||
static bool call_waiter(const string_view &, const string_view &, const json::array &, waiter &);
|
||||
static void handle(const m::event &, m::vm::eval &);
|
||||
|
||||
extern conf::item<seconds> min_ttl;
|
||||
extern conf::item<seconds> error_ttl;
|
||||
extern conf::item<seconds> nxdomain_ttl;
|
||||
extern conf::item<seconds> min_ttl IRCD_MODULE_EXPORT_DATA;
|
||||
extern conf::item<seconds> error_ttl IRCD_MODULE_EXPORT_DATA;
|
||||
extern conf::item<seconds> nxdomain_ttl IRCD_MODULE_EXPORT_DATA;
|
||||
|
||||
extern const m::room::id::buf room_id;
|
||||
extern m::hookfn<m::vm::eval &> hook;
|
||||
|
|
Loading…
Reference in a new issue