2018-10-01 22:27:46 +02:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
2019-10-06 02:02:50 +02:00
|
|
|
// Copyright (C) 2016-2019 Jason Volk <jason@zemos.net>
|
2018-10-01 22:27:46 +02:00
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
2020-03-07 21:37:55 +01:00
|
|
|
/// (internal) DNS cache
|
|
|
|
namespace ircd::net::dns::cache
|
|
|
|
{
|
2020-04-25 08:35:18 +02:00
|
|
|
struct waiter;
|
2020-03-07 21:37:55 +01:00
|
|
|
using closure = std::function<bool (const string_view &, const json::object &)>;
|
|
|
|
|
|
|
|
extern conf::item<seconds> min_ttl;
|
|
|
|
extern conf::item<seconds> error_ttl;
|
|
|
|
extern conf::item<seconds> nxdomain_ttl;
|
|
|
|
|
2020-04-25 08:35:18 +02:00
|
|
|
extern ctx::dock dock;
|
|
|
|
extern ctx::mutex mutex;
|
|
|
|
extern std::list<waiter> waiting;
|
|
|
|
|
|
|
|
bool operator==(const waiter &, const waiter &) noexcept;
|
|
|
|
bool operator!=(const waiter &, const waiter &) noexcept;
|
|
|
|
|
2020-03-07 21:37:55 +01:00
|
|
|
string_view make_type(const mutable_buffer &out, const string_view &);
|
|
|
|
string_view make_type(const mutable_buffer &out, const uint16_t &);
|
|
|
|
|
|
|
|
bool for_each(const string_view &type, const closure &); // do not make_type() here
|
|
|
|
bool for_each(const hostport &, const opts &, const closure &);
|
|
|
|
bool get(const hostport &, const opts &, const callback &);
|
|
|
|
bool put(const hostport &, const opts &, const records &);
|
|
|
|
bool put(const hostport &, const opts &, const uint &code, const string_view &msg = {});
|
|
|
|
}
|
2019-10-06 02:02:50 +02:00
|
|
|
|
2020-03-07 21:37:55 +01:00
|
|
|
/// DNS cache result waiter
|
2019-03-23 08:59:25 +01:00
|
|
|
struct ircd::net::dns::cache::waiter
|
|
|
|
{
|
|
|
|
dns::callback callback;
|
|
|
|
dns::opts opts;
|
2019-09-12 19:26:02 +02:00
|
|
|
uint16_t port;
|
2019-03-23 08:59:25 +01:00
|
|
|
string_view key;
|
2019-05-27 01:53:08 +02:00
|
|
|
char keybuf[rfc1035::NAME_BUFSIZE*2];
|
2019-03-23 08:59:25 +01:00
|
|
|
|
2019-09-12 19:26:02 +02:00
|
|
|
waiter(const hostport &hp, const dns::opts &opts, dns::callback &&callback);
|
2019-09-10 21:36:51 +02:00
|
|
|
waiter(waiter &&) = delete;
|
|
|
|
waiter(const waiter &) = delete;
|
|
|
|
waiter &operator=(waiter &&) = delete;
|
|
|
|
waiter &operator=(const waiter &) = delete;
|
2020-04-25 08:35:18 +02:00
|
|
|
|
|
|
|
static bool call(waiter &, const uint16_t &type, const string_view &tgt, const json::array &rrs);
|
|
|
|
static size_t call(const uint16_t &type, const string_view &tgt, const json::array &rrs);
|
2019-03-23 08:59:25 +01:00
|
|
|
};
|