mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 08:12:37 +01:00
ircd::server: Add DNS expiration TTL state to peer.
This commit is contained in:
parent
ba24dd1018
commit
d6200a7ac3
3 changed files with 64 additions and 3 deletions
|
@ -27,11 +27,14 @@ struct ircd::server::peer
|
|||
static conf::item<size_t> link_min_default;
|
||||
static conf::item<size_t> link_max_default;
|
||||
static conf::item<seconds> error_clear_default;
|
||||
static conf::item<seconds> remote_ttl_min;
|
||||
static conf::item<seconds> remote_ttl_max;
|
||||
static uint64_t ids;
|
||||
|
||||
uint64_t id {++ids};
|
||||
net::ipport remote;
|
||||
std::string hostcanon; // hostname:service[:port]
|
||||
net::ipport remote;
|
||||
system_point remote_expires;
|
||||
net::open_opts open_opts;
|
||||
std::list<link> links;
|
||||
std::unique_ptr<err> e;
|
||||
|
@ -70,6 +73,7 @@ struct ircd::server::peer
|
|||
public:
|
||||
// indicator lights
|
||||
bool finished() const;
|
||||
bool expired() const;
|
||||
|
||||
// config related
|
||||
size_t link_min() const;
|
||||
|
|
|
@ -708,6 +708,20 @@ ircd::server::peer::link_max_default
|
|||
{ "default", 4L }
|
||||
};
|
||||
|
||||
decltype(ircd::server::peer::remote_ttl_min)
|
||||
ircd::server::peer::remote_ttl_min
|
||||
{
|
||||
{ "name", "ircd.server.peer.remote.ttl.min" },
|
||||
{ "default", 21600L },
|
||||
};
|
||||
|
||||
decltype(ircd::server::peer::remote_ttl_max)
|
||||
ircd::server::peer::remote_ttl_max
|
||||
{
|
||||
{ "name", "ircd.server.peer.remote.ttl.max" },
|
||||
{ "default", 259200L },
|
||||
};
|
||||
|
||||
decltype(ircd::server::peer::ids)
|
||||
ircd::server::peer::ids;
|
||||
|
||||
|
@ -1365,6 +1379,7 @@ try
|
|||
if(rfc3986::valid(std::nothrow, rfc3986::parser::ip_address, host(hostport)))
|
||||
{
|
||||
this->remote = {host(hostport), port(hostport)};
|
||||
this->remote_expires = system_point::max();
|
||||
open_opts.ipport = this->remote;
|
||||
open_links();
|
||||
return;
|
||||
|
@ -1525,9 +1540,26 @@ try
|
|||
};
|
||||
|
||||
assert(!net::dns::is_error(rr));
|
||||
const json::string &ip
|
||||
{
|
||||
rr.at("ip")
|
||||
};
|
||||
|
||||
// Save the results of the query to this object instance.
|
||||
this->remote = net::ipport
|
||||
{
|
||||
unquote(rr.at("ip")), port(this->remote)?: port(target)
|
||||
ip, port(this->remote)?: port(target)
|
||||
};
|
||||
|
||||
// Mark the absolute time-point this remote will need to be refreshed
|
||||
this->remote_expires =
|
||||
{
|
||||
now<system_point>() + std::clamp
|
||||
(
|
||||
seconds(rr.get("ttl", 43200L)),
|
||||
seconds(remote_ttl_min),
|
||||
seconds(remote_ttl_max)
|
||||
)
|
||||
};
|
||||
|
||||
open_opts.ipport = this->remote;
|
||||
|
@ -1588,10 +1620,26 @@ try
|
|||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
const json::string &ip
|
||||
{
|
||||
rr.at("ip")
|
||||
};
|
||||
|
||||
// Save the results of the query to this object instance.
|
||||
this->remote = net::ipport
|
||||
{
|
||||
unquote(rr.at("ip")), port(this->remote)?: port(target)
|
||||
ip, port(this->remote)?: port(target)
|
||||
};
|
||||
|
||||
// Mark the absolute time-point this remote will need to be refreshed
|
||||
this->remote_expires =
|
||||
{
|
||||
now<system_point>() + std::clamp
|
||||
(
|
||||
seconds(rr.get("ttl", 21600L)),
|
||||
seconds(remote_ttl_min),
|
||||
seconds(remote_ttl_max)
|
||||
)
|
||||
};
|
||||
|
||||
open_opts.ipport = this->remote;
|
||||
|
@ -1803,6 +1851,13 @@ const
|
|||
return link_max_default;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::server::peer::expired()
|
||||
const
|
||||
{
|
||||
return remote_expires < ircd::now<system_point>();
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::server::peer::finished()
|
||||
const
|
||||
|
|
|
@ -5600,6 +5600,7 @@ try
|
|||
out
|
||||
<< std::setw(4) << std::left << "ID" << ' '
|
||||
<< std::setw(40) << std::right << "ADDRESS" << ' '
|
||||
<< std::setw(7) << std::right << "TTL" << ' '
|
||||
<< std::setw(50) << std::left << "NAME" << ' '
|
||||
<< std::setw(23) << std::left << "READ-TOTAL" << ' '
|
||||
<< std::setw(23) << std::left << "WRITE-TOTAL" << ' '
|
||||
|
@ -5633,6 +5634,7 @@ try
|
|||
out
|
||||
<< std::setw(4) << std::left << peer.id << ' '
|
||||
<< std::setw(40) << std::right << net::ipport{peer.remote} << ' '
|
||||
<< std::setw(7) << std::right << duration_cast<seconds>(peer.remote_expires - now<system_point>()).count() << ' '
|
||||
<< std::setw(50) << std::left << trunc(host, 50) << ' '
|
||||
<< std::setw(23) << std::left << pretty(pbuf, iec(peer.read_total())) << ' '
|
||||
<< std::setw(23) << std::left << pretty(pbuf, iec(peer.write_total())) << ' '
|
||||
|
|
Loading…
Reference in a new issue