ClickHouse/src/Common/CaresPTRResolver.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
1.5 KiB
C++
Raw Normal View History

#pragma once
2022-10-12 16:56:00 +00:00
#include <span>
#include <poll.h>
#include <mutex>
#include "DNSPTRResolver.h"
using ares_channel = struct ares_channeldata *;
2022-07-13 12:40:56 +00:00
namespace DB
{
/*
* Implements reverse DNS resolution using c-ares lib. System reverse DNS resolution via
2022-07-12 22:27:44 +00:00
* gethostbyaddr or getnameinfo does not work reliably because in some systems
* it returns all PTR records for a given IP and in others it returns only one.
* */
2022-07-13 12:40:56 +00:00
class CaresPTRResolver : public DNSPTRResolver
{
friend class DNSPTRResolverProvider;
/*
* Allow only DNSPTRProvider to instantiate this class
* */
struct provider_token {};
2023-01-26 16:54:12 +00:00
static constexpr auto C_ARES_POLL_EVENTS = POLLRDNORM | POLLIN;
public:
2022-07-13 12:40:56 +00:00
explicit CaresPTRResolver(provider_token);
~CaresPTRResolver() override;
std::unordered_set<std::string> resolve(const std::string & ip) override;
std::unordered_set<std::string> resolve_v6(const std::string & ip) override;
private:
2023-01-26 16:54:12 +00:00
bool wait_and_process();
void cancel_requests();
void resolve(const std::string & ip, std::unordered_set<std::string> & response);
void resolve_v6(const std::string & ip, std::unordered_set<std::string> & response);
2022-10-12 16:56:00 +00:00
std::span<pollfd> get_readable_sockets(int * sockets, pollfd * pollfd);
int64_t calculate_timeout();
void process_possible_timeout();
2022-10-10 21:54:35 +00:00
2022-10-12 16:56:00 +00:00
void process_readable_sockets(std::span<pollfd> readable_sockets);
ares_channel channel;
2023-01-25 22:09:35 +00:00
static std::mutex mutex;
};
}