0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-07-04 17:48:35 +02:00

ircd::net: Add additional conf items; update resolver timeout to use ms.

This commit is contained in:
Jason Volk 2018-03-09 12:22:10 -08:00
parent 4145a94fc8
commit e4a4526b0c
4 changed files with 32 additions and 13 deletions

View file

@ -22,6 +22,7 @@ struct ircd::net::listener::acceptor
using error_code = boost::system::error_code;
static log::log log;
static conf::item<milliseconds> timeout;
std::string name;
size_t backlog;

View file

@ -85,6 +85,8 @@ struct ircd::net::dns::opts
/// (internal) DNS cache
struct ircd::net::dns::cache
{
static conf::item<seconds> clear_nxdomain;
std::multimap<std::string, rfc1035::record::A, std::less<>> A;
std::multimap<std::string, rfc1035::record::SRV, std::less<>> SRV;
};

View file

@ -23,6 +23,7 @@ struct ircd::net::dns::resolver
using header = rfc1035::header;
static constexpr const size_t &MAX_COUNT{64};
static conf::item<milliseconds> timeout;
std::vector<ip::udp::endpoint> server; // The list of active servers
size_t server_next{0}; // Round-robin state to hit servers
@ -50,7 +51,7 @@ struct ircd::net::dns::resolver
void operator()(const hostport &, const opts &, callback);
bool check_timeout(const uint16_t &id, tag &, const steady_point &expired);
void check_timeouts(const seconds &timeout);
void check_timeouts(const milliseconds &timeout);
void worker();
ctx::context context;

View file

@ -800,6 +800,13 @@ ircd::net::listener::acceptor::log
"listener"
};
decltype(ircd::net::listener::acceptor::timeout)
ircd::net::listener::acceptor::timeout
{
{ "name", "ircd.net.acceptor.timeout" },
{ "default", 5000L },
};
ircd::net::listener::acceptor::acceptor(const json::object &opts)
try
:name
@ -965,7 +972,7 @@ noexcept try
};
++handshaking;
sock->set_timeout(5000ms); //TODO: config
sock->set_timeout(milliseconds(timeout));
sock->ssl.async_handshake(handshake_type, std::move(handshake));
}
catch(const ctx::interrupted &e)
@ -2149,6 +2156,13 @@ decltype(ircd::net::dns::opts_default)
ircd::net::dns::opts_default
{};
decltype(ircd::net::dns::cache::clear_nxdomain)
ircd::net::dns::cache::clear_nxdomain
{
{ "name", "net.dns.cache.clear_nxdomain" },
{ "default", 43200L },
};
/// Convenience composition with a single ipport callback. This is the result of
/// an automatic chain of queries such as SRV and A/AAAA based on the input and
/// intermediate results.
@ -2400,6 +2414,13 @@ ircd::net::dns::make_SRV_key(const mutable_buffer &out,
// net/resolver.h
//
decltype(ircd::net::dns::resolver::timeout)
ircd::net::dns::resolver::timeout
{
{ "name", "net.dns.resolver.timeout" },
{ "default", 10000L },
};
ircd::net::dns::resolver::resolver()
:ns{*ircd::ios}
,context
@ -2425,12 +2446,6 @@ void
ircd::net::dns::resolver::worker()
try
{
static conf::item<seconds> timeout
{
{ "name", "net.dns.resolver.timeout" },
{ "default", 5L },
};
while(1)
{
dock.wait([this]
@ -2438,8 +2453,8 @@ try
return !tags.empty();
});
ctx::sleep(seconds(timeout));
check_timeouts(seconds(timeout));
ctx::sleep(milliseconds(timeout));
check_timeouts(milliseconds(timeout));
}
}
catch(const ctx::interrupted &)
@ -2448,7 +2463,7 @@ catch(const ctx::interrupted &)
}
void
ircd::net::dns::resolver::check_timeouts(const seconds &timeout)
ircd::net::dns::resolver::check_timeouts(const milliseconds &timeout)
{
const auto cutoff
{
@ -2821,7 +2836,7 @@ ircd::net::dns::resolver::handle_error(const header &header,
{
const auto &host{rstrip(q.name, '.')};
rfc1035::record::A record;
record.ttl = ircd::time() + hours(24).count(); //TODO: conf
record.ttl = ircd::time() + seconds(cache::clear_nxdomain).count();
cache.A.emplace(host, record);
break;
}
@ -2830,7 +2845,7 @@ ircd::net::dns::resolver::handle_error(const header &header,
{
const auto &host{rstrip(q.name, '.')};
rfc1035::record::SRV record;
record.ttl = ircd::time() + hours(24).count(); //TODO: conf
record.ttl = ircd::time() + seconds(cache::clear_nxdomain).count();
cache.SRV.emplace(host, record);
break;
}