mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-03 23:15:52 +00:00
7caa87862e
All #ifndef guards on headers have been removed, I think, in favor of #pragma once Headers are now included as `#include "filename"` if the included file resides in the same directory as the file including it, or any subdirectory therein. Otherwise they are included as `#include <project/top/dir/relative/path/filename>` The above does not include system/os headers.
71 lines
1.5 KiB
C++
71 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include "serialize.hpp"
|
|
#include "name.hpp"
|
|
#include <llarp/net/net_int.hpp>
|
|
|
|
namespace llarp
|
|
{
|
|
namespace dns
|
|
{
|
|
using QType_t = uint16_t;
|
|
using QClass_t = uint16_t;
|
|
|
|
struct Question : public Serialize
|
|
{
|
|
Question() = default;
|
|
Question(Question&& other);
|
|
Question(const Question& other);
|
|
bool
|
|
Encode(llarp_buffer_t* buf) const override;
|
|
|
|
bool
|
|
Decode(llarp_buffer_t* buf) override;
|
|
|
|
std::ostream&
|
|
print(std::ostream& stream, int level, int spaces) const;
|
|
|
|
bool
|
|
operator==(const Question& other) const
|
|
{
|
|
return qname == other.qname && qtype == other.qtype && qclass == other.qclass;
|
|
}
|
|
|
|
Name_t qname;
|
|
QType_t qtype;
|
|
QClass_t qclass;
|
|
|
|
/// determine if we match a name
|
|
bool
|
|
IsName(const std::string& other) const;
|
|
|
|
/// is the name [something.]localhost.loki. ?
|
|
bool
|
|
IsLocalhost() const;
|
|
|
|
/// return true if we have subdomains in ths question
|
|
bool
|
|
HasSubdomains() const;
|
|
|
|
/// get subdomain(s), if any, from qname
|
|
std::string
|
|
Subdomains() const;
|
|
|
|
/// return qname with no trailing .
|
|
std::string
|
|
Name() const;
|
|
|
|
/// determine if we are using this TLD
|
|
bool
|
|
HasTLD(const std::string& tld) const;
|
|
};
|
|
|
|
inline std::ostream&
|
|
operator<<(std::ostream& out, const Question& q)
|
|
{
|
|
q.print(out, -1, -1);
|
|
return out;
|
|
}
|
|
} // namespace dns
|
|
} // namespace llarp
|