2021-03-09 22:24:35 +00:00
|
|
|
#pragma once
|
2018-12-12 02:52:51 +00:00
|
|
|
|
2021-03-09 22:24:35 +00:00
|
|
|
#include "serialize.hpp"
|
|
|
|
#include "name.hpp"
|
|
|
|
#include <llarp/net/net_int.hpp>
|
2018-12-03 22:22:59 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace dns
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
using QType_t = uint16_t;
|
2018-12-04 16:16:43 +00:00
|
|
|
using QClass_t = uint16_t;
|
2018-12-03 22:22:59 +00:00
|
|
|
|
|
|
|
struct Question : public Serialize
|
|
|
|
{
|
2018-12-04 16:16:43 +00:00
|
|
|
Question() = default;
|
2021-07-29 20:40:25 +00:00
|
|
|
|
|
|
|
explicit Question(std::string name, QType_t type);
|
|
|
|
|
2018-12-04 16:16:43 +00:00
|
|
|
Question(Question&& other);
|
|
|
|
Question(const Question& other);
|
2018-12-03 22:22:59 +00:00
|
|
|
bool
|
|
|
|
Encode(llarp_buffer_t* buf) const override;
|
|
|
|
|
|
|
|
bool
|
|
|
|
Decode(llarp_buffer_t* buf) override;
|
|
|
|
|
2022-07-16 00:41:14 +00:00
|
|
|
std::string
|
|
|
|
ToString() const;
|
2019-02-24 23:46:37 +00:00
|
|
|
|
2018-12-04 16:16:43 +00:00
|
|
|
bool
|
|
|
|
operator==(const Question& other) const
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
return qname == other.qname && qtype == other.qtype && qclass == other.qclass;
|
2018-12-04 16:16:43 +00:00
|
|
|
}
|
|
|
|
|
2022-07-18 20:05:39 +00:00
|
|
|
std::string qname;
|
2018-12-03 22:22:59 +00:00
|
|
|
QType_t qtype;
|
|
|
|
QClass_t qclass;
|
2019-04-26 12:11:34 +00:00
|
|
|
|
|
|
|
/// determine if we match a name
|
|
|
|
bool
|
|
|
|
IsName(const std::string& other) const;
|
|
|
|
|
2020-08-31 23:25:58 +00:00
|
|
|
/// is the name [something.]localhost.loki. ?
|
|
|
|
bool
|
|
|
|
IsLocalhost() const;
|
|
|
|
|
2020-10-12 16:18:46 +00:00
|
|
|
/// return true if we have subdomains in ths question
|
|
|
|
bool
|
|
|
|
HasSubdomains() const;
|
|
|
|
|
2020-08-31 23:25:58 +00:00
|
|
|
/// get subdomain(s), if any, from qname
|
|
|
|
std::string
|
|
|
|
Subdomains() const;
|
|
|
|
|
2019-04-26 12:11:34 +00:00
|
|
|
/// return qname with no trailing .
|
|
|
|
std::string
|
|
|
|
Name() const;
|
2019-05-01 13:40:10 +00:00
|
|
|
|
|
|
|
/// determine if we are using this TLD
|
|
|
|
bool
|
|
|
|
HasTLD(const std::string& tld) const;
|
2021-07-29 20:40:25 +00:00
|
|
|
|
|
|
|
util::StatusObject
|
|
|
|
ToJSON() const override;
|
2018-12-03 22:22:59 +00:00
|
|
|
};
|
|
|
|
} // namespace dns
|
|
|
|
} // namespace llarp
|
2022-07-16 00:41:14 +00:00
|
|
|
|
|
|
|
template <>
|
|
|
|
constexpr inline bool llarp::IsToStringFormattable<llarp::dns::Question> = true;
|